If you are on OS/400 V2R1, you may already have started to use the new RPG/400 operation codes ENDIF, ENDDO, ENDCS and ENDSL in your programs. You'll find that it doesn't take long to become accustomed to seeing these operation codes in your programs. The first time you go back to do maintenance on a pre-V2R1 program, you'll not be satisfied with the plain old END statement.
So, do you avoid using the new ENDxx statements in the old program to maintain consistency, or do you take the time to manually replace all the END statements in the program? Here's a command that automatically replaces all old END statements in an RPG/400 source member with the appropriate ENDxx statement. It's the Change RPG END Operations (CHGRPGEND) command.
To run the command, key in CHGRPGEND and press F4 to prompt. Key in the source member name and the qualified name of the source file where it resides; then press Enter. The RPG program reads through the C-specs in the selected source member and replaces all END statements with the appropriate ENDIF, ENDDO, ENDCS or ENDSL statement. Up to 99 levels of nesting are supported.
To install CHGRPGEND in your system, simply enter the source code listed in Figures 2 to 4 and compile as indicated at the bottom of each figure.
TechTalk: Utility to Change all END operations to
Figure 2 Command CHGRPGEND
CHGRPGEND: CMD PROMPT('Change RPG END Operations') PARM KWD(SRCMBR) TYPE(*NAME) LEN(10) MIN(1) + PROMPT('Source member') PARM KWD(SRCFILE) TYPE(Q1) PROMPT('Source file') Q1: QUAL TYPE(*NAME) LEN(10) DFT(QRPGSRC) QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) + SPCVAL((*LIBL)) PROMPT('Library')
TechTalk: Utility to Change all END operations to
Figure 3 CL program RPG003CL
RPG003CL: + PGM PARM(&SRCMBR &QSRCF) DCL VAR(&SRCMBR) TYPE(*CHAR) LEN(10) DCL VAR(&QSRCF) TYPE(*CHAR) LEN(20) DCL VAR(&SRCF) TYPE(*CHAR) LEN(10) DCL VAR(&SRCFLIB) TYPE(*CHAR) LEN(10) DCL VAR(&MSGID) TYPE(*CHAR) LEN(7) DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(100) DCL VAR(&MSGF) TYPE(*CHAR) LEN(10) DCL VAR(&MSGFLIB) TYPE(*CHAR) LEN(10) MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR)) CHGVAR VAR(&SRCF) VALUE(%SST(&QSRCF 1 10)) CHGVAR VAR(&SRCFLIB) VALUE(%SST(&QSRCF 11 10)) ALCOBJ OBJ((&SRCFLIB/&SRCF *FILE *SHRUPD &SRCMBR)) WAIT(0) OVRDBF FILE(QRPGSRC) TOFILE(&SRCFLIB/&SRCF) MBR(&SRCMBR) + WAITFILE(1) LVLCHK(*NO) SECURE(*YES) CALL PGM(RPG003RG) DLCOBJ OBJ((&SRCFLIB/&SRCF *FILE *SHRUPD &SRCMBR)) RETURN ERROR: + RCVMSG MSGTYPE(*EXCP) MSGDTA(&MSGDTA) MSGID(&MSGID) MSGF(&MSGF) + MSGFLIB(&MSGFLIB) SNDPGMMSG MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) MSGDTA(&MSGDTA) + MSGTYPE(*ESCAPE) DLCOBJ OBJ((&SRCFLIB/&SRCF *FILE *SHRUPD &SRCMBR)) MONMSG MSGID(CPF0000) ENDPGM
TechTalk: Utility to Change all END operations to
Figure 4 RPG program RPG003RG
FQRPGSRC UP F 92 DISK * E ARY 99 2 * IQRPGSRC NS I 18 19 SPCTYP I 40 41 OPCDE2 I 40 42 OPCDE3 I 40 44 OPCODE * C SPCTYP IFEQ 'C ' C SELEC C OPCDE2 WHEQ 'IF' C ADD 1 X 20 C MOVEL'IF' ARY,X C OPCDE2 WHEQ 'DO' C ADD 1 X C MOVEL'DO' ARY,X C OPCDE3 WHEQ 'CAS' C CASE ANDEQ'N' C ADD 1 X C MOVEL'CS' ARY,X C MOVE 'Y' CASE C OPCODE WHEQ 'SELEC' C ADD 1 X C MOVEL'SL' ARY,X C OPCODE WHEQ 'END ' C OPCODE OREQ 'ENDIF' C OPCODE OREQ 'ENDDO' C OPCODE OREQ 'ENDCS' C OPCODE OREQ 'ENDSL' C OPCODE IFEQ 'END ' C EXCPTCHANGE C ENDIF C ARY,X IFEQ 'CS' C MOVE 'N' CASE C ENDIF C MOVE *BLANK ARY,X C SUB 1 X C ENDSL C ENDIF * C *INZSR BEGSR C MOVE 'N' CASE 1 C ENDSR * OQRPGSRC E CHANGE O ARY,X 44
LATEST COMMENTS
MC Press Online