There have been times when I am debugging a multi-thousand line program when I find a line of code that can look something like:
1414.00 dou (X = Const1) ; |
I can see what value is in variable X. But my attempts to see what is in Const1 is met with:
EVAL Const1 Identifier does not exist. |
The first thought that passes through my mind is that I wish the person who had written the program had used meaningful names when defining their variables and constants.
The second is why doesn't debug allow me to view the value of the constant.
IBM cannot do anything to resolve my first thought. But it has with the second.
As part of the latest round of Technology Refreshes, IBM i 7.4 TR5 and 7.3 TR11, I can now debug constants. All I need to do is to add a RPG control option.
This example program shows how it can be done:
01 **free 02 ctl-opt debug(*constants) ; 03 dcl-c Constant1 const('This is a constant') ; 04 dcl-c Constant2 'Another constant' ; 05 *inlr = *on ; |
Line 1: In 2021 there is no reason why I would not write my RPG in totally free format.
Line 2: The DEBUG control option has been around for some time, it is only with these TRs that I can use the *CONSTANTS.
Lines 3 and 4: I have defined two constants here.
I start debug, and place a breakpoint at line 5. Now when I check the values on the constants I get:
EVAL Constant1 CONSTANT1 = 'This is a constant' EVAL Constant2 CONSTANT2 = 'Another constant' |
While I love this new functionality, it does not make an excuse for not giving your variables and constants meaningful names.
|
You can learn more about the debug RPG control option from the IBM website here.
This article was written for IBM i 7.4 TR5 and 7.3 TR11.
Nice to see these TRs come out with good and useful tools. I remember when IBM didn't even want to talk about RPG and acted as if everything would be done in Java.
ReplyDeleteExcelent! Thanks for sharing
ReplyDelete"dou (Counter = MaxArraySize) ;"
ReplyDeleteOr even better:
dou (Counter = %Elem(array) ;
or with dynamic arrays while you are adding elements:
dou (Counter = %Elem(array: *Max) ;
That way it is soft coded - no need for a constant.
But I agree that the new constant debug is great - if only it would work on my system!
"Jai ustaad khaleest" - Old Farsi saying
DeleteTranslation "Master's seat is vacant".
Meaning "Nobody can take occupy the seat of master except master, even when he is not around".
As I looked at the response, I wondered who wrote it. Saw the name wnd said to myself, "Ah! Should have guessed".
I was just rewriting an old fixed format program written 25 years ago and patched badly, making debug a nightmare. One of the beauty to use was %elem in DOW and FOR. So I was naturally fascinated by the response.
Nice
ReplyDeleteThis will be nice for all our clients using old code.
ReplyDeleteSimon, thanks for sharing, it will be useful. I hate bad descriptor’s meaningless. Great examples.
ReplyDeleteThanks Simon, that and the ability to change UDF return value thru the same debug() keyword are cool enhancements in #rpg
ReplyDelete