Here's my method for trimming leading zeros from a character field in RPG (V2R1 or later). Let's say a character field with a length of 10, named CHRNUM, contains the value '002300450'. The TRMZRO subroutine in 8 will remove all leading zeros and return a value of ' 2300450'.
Here's my method for trimming leading zeros from a character field in RPG (V2R1 or later). Let's say a character field with a length of 10, named CHRNUM, contains the value '002300450'. The TRMZRO subroutine in Figure 8 will remove all leading zeros and return a value of ' 2300450'.
This technique eliminates the need for array processing and therefore is very efficient.
If you want to remove leading zeros from a character field that was originally a negative number, you will have to append a negative sign. This can easily be done by using the CAT operation.
Trimming Leading Zeros
Figure 8 RPG Code for Removing Leading Zeros from a Charact
... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 C CLEARWRK30 C MOVE CHRNUM WRK30 30 C EXSR TRMZRO C MOVE WRK30 CHRNUM C MOVEL*ON *INLR *=============================================================== C TRMZRO BEGSR *=============================================================== C WRK30 IFNE *ALL'0' C WRK30 ANDNE*BLANKS C ' ':'0' XLATEWRK30 WRK30 C '0' CHECKWRK30 Y 30 C '0':' ' XLATEWRK30 WRK30 C ' ':'0' XLATEWRK30:Y WRK30 C ELSE C MOVE *BLANKS WRK30 C ENDIF C ENDSR *===============================================================
LATEST COMMENTS
MC Press Online