Padding variables to 3 characters with leading zeroes or right adjusted
search cancel

Padding variables to 3 characters with leading zeroes or right adjusted

book

Article ID: 44065

calendar_today

Updated On:

Products

FAQS - Automated Systems Operation

Issue/Introduction

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

Is there a way of defining the variable 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 three characters when over 100. 

 

Environment

Release:  5.1
Component: FAQS-Automated Systems Operation

Resolution

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