From: Marc Salvatori To: All
I know others have shared their approach for stripping leading zeros from character fields that had numeric values moved into them. I want to share mine for the benefit of others, and I'm interested in any comments others might have.
1 contains a subroutine called STRIPZ which strips the leading zeros from a character field. I could have avoided using the BLANKS field if the SUBST operation would allow me to use the *BLANKS constant. However, this routine works regardless of the size of the fields I work with.
Figure 1 contains a subroutine called STRIPZ which strips the leading zeros from a character field. I could have avoided using the BLANKS field if the SUBST operation would allow me to use the *BLANKS constant. However, this routine works regardless of the size of the fields I work with.
From: Matt Sargent To: Marc Salvatori
I guess my main problem with this is the BLANKS field. You're initializing it each time the subroutine is called, which serves no purpose except to provide a place to define the field. Since its value is never altered, it might be better if BLANKS were a constant field. Also, its length should be extended to 30 bytes since RPG can handle numeric fields with up to 30 digits.
The routine I like to use is shown in 2. It's very compact and requires only one work field (@ZS). CFIELD is the character field containing the numeric data to be processed. I translate all the zeros to blanks; then I translate all the blanks past the first nonblank character back to zeros. The XLATE operations make this very easy.
The routine I like to use is shown in Figure 2. It's very compact and requires only one work field (@ZS). CFIELD is the character field containing the numeric data to be processed. I translate all the zeros to blanks; then I translate all the blanks past the first nonblank character back to zeros. The XLATE operations make this very easy.
Strip Leading Zeros
Figure 1 Subroutine STRIPZ
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 C MOVE NUMFLD NUMBER C EXSR STRIPZ C MOVE NUMBER CHRFLD 7 *================================================================ * Strip leading zeros from alpha-numeric integer *================================================================ C STRIPZ BEGSR C MOVE *BLANKS BLANKS 15 C ' 0' CHECKNUMBER C 20 C SELEC C C WHEQ *ZERO C MOVE '0' NUMBER 15 P C C WHGT 1 C SUB 1 C C C SUBSTBLANKS NUMBER C ENDSL C ENDSR *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7
Strip Leading Zeros
Figure 2 Strip Leading Zeros
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 C '0':' ' XLATECFIELD CFIELD C ' ' CHECKCFIELD @ZS 30 C @ZS IFNE *ZERO C ' ':'0' XLATECFIELD:@ZSCFIELD C ENDIF
LATEST COMMENTS
MC Press Online