Right-adjust or Left-adjust Subroutine

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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 *=============================================================== 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: