Character string handling has become a powerful tool in the RPG programmer's toolbox. The following three techniques offer you a few shortcuts for jobs that used to be very tedious.
To find out how many characters exist in an alphanumeric field, use the code shown in the first example in 3. The Check Reverse (CHEKR) operation will look for the last nonblank character in the input field (INPFLD) and return its position in the variable X. The result of this operation is that the value in field X will be the length of the data in the field INPFLD.
To find out how many characters exist in an alphanumeric field, use the code shown in the first example in Figure 3. The Check Reverse (CHEKR) operation will look for the last nonblank character in the input field (INPFLD) and return its position in the variable X. The result of this operation is that the value in field X will be the length of the data in the field INPFLD.
To left justify data in an alphanumeric field, remove leading blanks using the code in the second example in 3. The CHECK operation will locate the first nonblank character in INPFLD and put its position into variable X. The subsequent Substring (SUBST) operation will move the INPFLD data back into itself beginning at the first nonblank character address. The P extender is specified so all characters beyond those that were moved will be replaced with blanks.
To left justify data in an alphanumeric field, remove leading blanks using the code in the second example in Figure 3. The CHECK operation will locate the first nonblank character in INPFLD and put its position into variable X. The subsequent Substring (SUBST) operation will move the INPFLD data back into itself beginning at the first nonblank character address. The P extender is specified so all characters beyond those that were moved will be replaced with blanks.
To right adjust data in an alphanumeric field, remove trailing blanks using the code in the third example in 3. Use the CHEKR operation to find the last nonblank character. The result in variable X represents the length of the field. The contents of INPFLD are then saved in a work field (WRKFLD).
To right adjust data in an alphanumeric field, remove trailing blanks using the code in the third example in Figure 3. Use the CHEKR operation to find the last nonblank character. The result in variable X represents the length of the field. The contents of INPFLD are then saved in a work field (WRKFLD).
Subtract the length of the data (currently stored in variable X) from the field length (stored in FLDLEN) and return the results back to variable X. The result in variable X is now the number of trailing blanks that exist in the input field.
Clear the original input field (INP-FLD) and then perform a concatenation (CAT) operation from WRKFLD back into INPFLD using the number of trailing blanks as the new number of leading blanks.
Swapping the number of trailing blanks for the number of leading blanks right adjusts INPFLD.
? Doug Pence
TechTalk: RPG String Calculations
Figure 3: RPG String Calculations
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 * * Example 1 - Calculate data length C ' ' CHEKRINPFLD X 20 * * Example 2 - Left justify data C ' ' CHECKINPFLD X 20 C SUBSTINPFLD:X INPFLD P * * Example 3 - Right justify data C ' ' CHEKRINPFLD X 20 C MOVELINPFLD WRKFLD 20 P C FLDLEN SUB X X C MOVE *BLANKS INPFLD 20 C CAT WRKFLD:X INPFLD *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7
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.
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:
LATEST COMMENTS
MC Press Online