The CRTKLIST command will create an RPG or RPGLE source member containing a key list for a keyed physical or logical file. The source code for the utility is shown in Figures 1, 2, and 3. The CRTKLIST command prompts you for a database file, a source file, a source member, and the member type.
After you run the command, the newly created source member contains the code for a key list that you can copy into your program and modify if necessary. The key list code contains one KLIST statement followed by one or more KFLD statements. The KLIST statement requires a key list name in factor 1, so the utility uses the first six characters of the record format name. For the KFLD statements, it uses the database field names in the result column.
The next time you need to create an RPG key list, try using the CRTKLIST utility. It may save you some time.
- T.V.S. Murthy
TechTalk: Create RPG key lists with the CRTKLIST utility.
Figure 1: The CRTKLIST Command
/*==================================================================*/ /* To compile: */ /* */ /* CRTCMD CMD(XXX/CRTKLIST) PGM(XXX/KLS001CL) + */ /* SRCFILE(XXX/QCMDSRC) */ /* */ /*==================================================================*/ CMD PROMPT('Create RPG Key List') PARM KWD(FILE) TYPE(FILLIB) MIN(1) PROMPT('Keyed + file') PARM KWD(SRCFILE) TYPE(FILLIB) MIN(1) + PROMPT('Source file') PARM KWD(SRCMBR) TYPE(*NAME) LEN(10) MIN(1) + PROMPT('Member') PARM KWD(MBRTYP) TYPE(*CHAR) LEN(10) RSTD(*YES) + DFT(RPG) VALUES(RPG RPGLE RPG38) + PROMPT('Member type') FILLIB: QUAL TYPE(*NAME) LEN(10) QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) + SPCVAL((*LIBL) (*CURLIB)) PROMPT('Library')
TechTalk: Create RPG key lists with the CRTKLIST utility.
Figure 2: The KLS001CL Program
/*==================================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/KLS001CL) SRCFILE(XXX/QCLSRC) */ /* */ /*==================================================================*/ PGM PARM(&FILE &SRCF &SRCMBR &MBRTYPE) DCL VAR(&FILE) TYPE(*CHAR) LEN(20) DCL VAR(&SRCF) TYPE(*CHAR) LEN(20) DCL VAR(&SRCMBR) TYPE(*CHAR) LEN(10) DCL VAR(&MBRTYPE) TYPE(*CHAR) LEN(10) DCL VAR(&MSGID) TYPE(*CHAR) LEN(7) DCL VAR(&MSGF) TYPE(*CHAR) LEN(10) DCL VAR(&MSGFLIB) TYPE(*CHAR) LEN(10) DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(80) MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(RCVERRORS)) DSPFD FILE(%SST(&FILE 11 10)/%SST(&FILE 1 10)) + TYPE(*ACCPTH) OUTPUT(*OUTFILE) + OUTFILE(QTEMP/KLS001PF) OUTMBR(*FIRST + *REPLACE) ADDPFM FILE(%SST(&SRCF 11 10)/%SST(&SRCF 1 10)) + MBR(&SRCMBR) SRCTYPE(&MBRTYPE) OVRDBF FILE(SRCMBR) TOFILE(%SST(&SRCF 11 + 10)/%SST(&SRCF 1 10)) MBR(&SRCMBR) OVRDBF FILE(QAFDACCP) TOFILE(QTEMP/KLS001PF) CALL PGM(KLS001RG) PARM(&MBRTYPE) IF COND(&MBRTYPE *EQ 'ARRIVAL') THEN(DO) RMVM FILE(%SST(&SRCF 11 10)/%SST(&SRCF 1 10)) + MBR(&SRCMBR) MONMSG MSGID(CPF0000) SNDPGMMSG MSG('File' *BCAT %SST(&FILE 1 10) *BCAT + 'is not a keyed physical or logical + file.') MSGTYPE(*INFO) ENDDO ELSE CMD(SNDPGMMSG MSG('Key list for file' *BCAT + %SST(&FILE 1 10) *BCAT 'created in file ' + *CAT %SST(&SRCF 11 10) *TCAT '/' *TCAT + %SST(&SRCF 1 10) *BCAT 'member ' *CAT + &SRCMBR *TCAT '.') MSGTYPE(*COMP)) GOTO CMDLBL(ENDPGM) RCVERRORS: RCVMSG MSGTYPE(*EXCP) MSGDTA(&MSGDTA) MSGID(&MSGID) SNDPGMMSG MSGID(&MSGID) MSGF(QCPFMSG) MSGDTA(&MSGDTA) + MSGTYPE(*ESCAPE) ENDPGM: ENDPGM
TechTalk: Create RPG key lists with the CRTKLIST utility.
Figure 3: The KLS001RG Program
*=============================================================== * To compile: * * CRTRPGPGM PGM(XXX/KLS001RG) SRCFILE(XXX/QRPGSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 FSRCMBR O F 112 DISK * FQAFDACCPIF E DISK * ISRCTXT DS I I 0 1 60SRCSEQ I I 0 7 120SRCDAT I 13 112 SRCDTA *=============================================================== C *ENTRY PLIST C PARM MBRTYP 10 * C READ QAFDACCP 99 C *IN99 IFEQ *OFF C APACCP ANDEQ'A' C MOVEL'ARRIVAL' MBRTYP P C ELSE C *IN99 DOWEQ*OFF C APBOLF IFNE SVBOLF C EXSR KLIST C MOVE APBOLF SVBOLF 10 C ENDIF C EXSR KFLD C READ QAFDACCP 99 C ENDDO C ENDIF * C MOVE *ON *INLR *=============================================================== C KLIST BEGSR * C ADD 100 SRCSEQ C CLEARSRCDTA C MBRTYP IFEQ 'RPGLE' C CAT 'C':5 SRCDTA C APBOLF CAT '00001':0 FILE6 6 C CAT FILE6:5 SRCDTA C CAT 'KLIST':8 SRCDTA C EXCPTRPGLE C ELSE C CAT 'C':5 SRCDTA C APBOLF CAT '00001':0 FILE6 C CAT FILE6:11 SRCDTA C CAT 'KLIST':4 SRCDTA C EXCPTRPG C ENDIF * C ENDSR *=============================================================== C KFLD BEGSR * C ADD 100 SRCSEQ C CLEARSRCDTA C MBRTYP IFEQ 'RPGLE' C CAT 'C':5 SRCDTA C CAT 'KFLD':19 SRCDTA C CAT APKEYF:20 SRCDTA C EXCPTRPGLE C ELSE C CAT 'C':5 SRCDTA C CAT 'KFLD':21 SRCDTA C CAT APKEYF:11 SRCDTA C EXCPTRPG C ENDIF * C ENDSR *=============================================================== OSRCMBR E RPG O SRCSEQ O SRCDAT O SRCDTA O E RPGLE O SRCSEQ O SRCDAT O SRCDTA
LATEST COMMENTS
MC Press Online