using variables

Document ID : KB000044065
Last Modified Date : 14/02/2018
Show Technical Document Details

Question:

I use a variable as a counter that starts from zero each day, and use this variable as an input to a COBOL program.

Is there a way of defining that the variable will always be sent to the COBOL program as three characters in length, padded to the left with leading zeroes ?

As it is, when the counter contains 1 - 9 the input size is one character, when 10 - 99 it is two characters and only when over 100 is it three characters. 

 

Answer:

There is no way of automatically padding the field to always be 3 characters with leading zeroes, or forcing right-adjustment, but these PCL coding suggestions are a way of doing this:

|SET &J=L'&SIDURI - set the var to the length. 
then it will test the length using IF - and pad zeros as needed 

|SET &SIDURI=&SIDURI+1 
|SET &J=L'&SIDURI 
|IF &J EQ 3 SET &SIDURI=&SIDURI 
|IF &J EQ 2 SET &SIDURI=0&SIDURI 
|IF &J EQ 1 SET &SIDURI=00&SIDURI 

 

|CALL $GVAR I2P2643 
|SET &SIDURI(1,3)=&RESULT 
|TYPE &SIDURI START VALUE 
|IF &SIDURI > 99 
|SET &SIDURI(1,3)=&SIDURI+1 
|TYPE &SIDURI OVER 100 
|ENDIF 
|IF &SIDURI < 9 
|SET &SIDURI(3,3)=&SIDURI+1 
|TYPE &SIDURI LESS 10 
|ENDIF 
|IF &SIDURI > 9 IF &SIDURI < 100 
|SET &SIDURI(2,2)=&SIDURI+1 
|TYPE &SIDURI BETWEEN 10/99 
|ENDIF