Once upon a time, it was a rather tedious task to left-adjust decimal values and right-adjust character values with RPG. Nowadays, some of the more recent operation codes make the adjustments easy. 1 contains the source code for RPG subroutine ADJUST, which will left- or right-adjust the contents of a 30-byte variable. All you need to do is load the receiver variable field (RCVVAR) with the value you want to adjust and load the adjustment type field (ADJTYP) with an 'L' to left adjust or 'R' to right-adjust.
Once upon a time, it was a rather tedious task to left-adjust decimal values and right-adjust character values with RPG. Nowadays, some of the more recent operation codes make the adjustments easy. Figure 1 contains the source code for RPG subroutine ADJUST, which will left- or right-adjust the contents of a 30-byte variable. All you need to do is load the receiver variable field (RCVVAR) with the value you want to adjust and load the adjustment type field (ADJTYP) with an 'L' to left adjust or 'R' to right-adjust.
Right-adjust or Left-adjust Subroutine
Figure 1 RPG Subroutine to Left- or Right-adjust a Value
*=============================================================== C Z-ADD1234567 FLDDEC 120 C MOVEL'ABCDEFGH'FLDALF 12 C MOVE FLDDEC RCVVAR 30 P C MOVEL'L' ADJTYP 1 C EXSR LRADJ C RCVVAR DSPLY C MOVE FLDALF RCVVAR P C MOVEL'R' ADJTYP C EXSR LRADJ C RCVVAR DSPLY C MOVEL*ON *INLR *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 C LRADJ BEGSR * Load RCVVAR with value to be left or right adjusted * Load ADJTYP with 'L' to left adjust; 'R' to right adjust C MOVE ' 0' BLKZRO 2 C MOVE *BLANK BLANK 1 C *LIKE DEFN RCVVAR STRING+ 1 * Left adjust C ADJTYP IFEQ 'L' C 31 ADD 1 FACTOR 30 C MOVE RCVVAR STRING P C BLKZRO CHECKSTRING POS 30 C FACTOR SUB POS STRLGT 30 C STRLGT SUBSTSTRING:POSSTRING P C MOVELSTRING RCVVAR C ELSE * Right adjust C Z-ADD31 FACTOR C MOVELRCVVAR STRING P C BLANK CHEKRSTRING POS C FACTOR SUB POS BLK 30 C BLANK CAT STRING:BLKSTRING P C MOVE STRING RCVVAR C ENDIF C ENDSR *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 *===============================================================
LATEST COMMENTS
MC Press Online