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.

8 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
    Replies
    1. "Jai ustaad khaleest" - Old Farsi saying
      Translation "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.

      Delete
  4. This will be nice for all our clients using old code.

    ReplyDelete
  5. Simon, thanks for sharing, it will be useful. I hate bad descriptor’s meaningless. Great examples.

    ReplyDelete
  6. Reynaldo Dandreb MedillaJanuary 22, 2022 at 5:54 AM

    Thanks Simon, that and the ability to change UDF return value thru the same debug() keyword are cool enhancements in #rpg

    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.