Thursday, September 23, 2021

Debugging constants in RPG

view values in constants

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.

  dou (X = Const1) ;

  dou (Counter = MaxArraySize) ;

 

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.

4 comments:

  1. 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.

    ReplyDelete
  2. Excelent! Thanks for sharing

    ReplyDelete
  3. "dou (Counter = MaxArraySize) ;"

    Or 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!

    ReplyDelete

To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.