ibm-midrangecontrol-language

Incrementing a text field in CL


I have to change a CL program on an iSeries computer. The original CL has a variable called &SEQ. It is a text field with a value of '001'. Is there a way possible in CL to add one to the value to make it '002'? I'm not familiar with CL programming, so I don't know if you can do mathematic functions on a character variable. Thanks for any help!


Solution

  • Do to that you have to use a *DEC CL variable and then move it into the text field. At the top of the program add the following line:

    DCL &SEQNBR *DEC 3 VALUE(1)
    

    Then in the program at the point where you want to increment the sequence number do this:

    CHGVAR &SEQNBR VALUE(&SEQNBR + 1)
    CHGVAR &SEQ VALUE(&SEQNBR)
    

    What is going on here? You declare the numeric variable &SEQNBR with an initial value of 1. Then increment it using the CHGVAR command. This makes its value 2. Then you move it to the text field &SEQ and it will receive the value as '002'.