When will I learn? Time after time, I've used the ILE debugger to debug RPG IV applications, yet when I receive the following message, I'm at a loss as to what to do next:
"Variable not found."
The variable is found! It is in the program, it is being referenced, and yet I cannot display its contents. So I spend a few minutes recompiling because I'm certain it's something I've done.
For example, I recently had two variables named QUAL and FIND in my RPG IV program. QUAL contained a qualified database file name, and FIND contained data that I wanted to use to search the database file.
Stepping into debug, I got the usual Display Module Source panel and started the program running. After a few statements, I put the cursor on the field named QUAL to check the format of the qualified name, but...
"Variable not found."
Since QUAL is a parameter, I thought, "Oh, the program hasn't accessed the parameters yet, and therefore the variable isn't accessible to the debugger." But I realized I was just making up scenarios in my mind to satisfy my own stupidity (parameters are one of the first things "moved" into the program, so this line of thinking was just B.S.). I remembered experiencing this problem a couple years ago, but I couldn't remember what I did about it or why I got the error. So I continued debugging.
Then, I needed to display the content of the SRCDTA field. I put the cursor on the field and pressed F11. Voila! The contents were displayed just fine. Later on, I needed to display the contents of the FIND field. So I put the cursor on the field and pressed F11.
"Variable not found."
I decided it was time to use the method of last resorts--no, not nuclear weapons, the online Help text. So I pressed F1 and was taken to the list of debugger commands. I rolled down to the EVAL command and pressed Enter. Nothing there of value, so I tabbed over to the SCALAR keyword and pressed Enter. Interesting, but again, not what I needed.
Since that was the end of the line of that chain of Help text, I returned to the main Help page. Then, I tabbed back over to EVAL and read the Help on that command again. I hoped something had changed in the 10 seconds since the last time I was there.
That time, instead of EVAL, I tabbed over to the EXPRESSION keyword and pressed Enter. Still nothing to report, but at least there were additional links. So I tabbed over to the RPG Language Examples link and pressed Enter. Sadly, still nothing.
But there were more links. So I tabbed over to the Display a Variable - RPG link and pressed Enter. Nothing to report there, either. So I went to press the Enter key to return to the previous display and inadvertently pressed the PgDn (page down) key on the numeric pad. The display rolled up and revealed what I already knew:
Comment: If a variable has the same name as a debug command, the %VAR keyword must be used."
If you use field names in your RPG IV program that have the same names as any of the debug commands, in order to display the contents of that variable, you must manually type in the EVAL command with %VAR surrounding the variable name.
So I entered the following:
This revealed the contents of the QUAL field, and I continued to debug the code.
So why doesn't F11 simply enclose all fields with %VAR so we can avoid this type of time-wasting situation?
For a complete list of debug command names that, if used as field names in your code, need to be enclosed in %VAR when referenced on any debugger command, press F1 from the Debug command line. Don't forget to page down (roll up) to see the entire list.
Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.
LATEST COMMENTS
MC Press Online