Here's a utility that allows you to look at physical and single-format logical files in a new way. The command, shown in 1, is called Display Record Format (DSPRCDFMT). It's similar to the OS/400 command Display File Field Description (DSPFFD) because it shows you information about the fields in a file. But DSPRCDFMT also shows you the access path of the file, and the information is presented in a cleaner, easier-to-read format than DSPFFD. Information can either be displayed on the screen or spooled for printing.
Here's a utility that allows you to look at physical and single-format logical files in a new way. The command, shown in Figure 1, is called Display Record Format (DSPRCDFMT). It's similar to the OS/400 command Display File Field Description (DSPFFD) because it shows you information about the fields in a file. But DSPRCDFMT also shows you the access path of the file, and the information is presented in a cleaner, easier-to-read format than DSPFFD. Information can either be displayed on the screen or spooled for printing.
The command processing program for DSPRCDFMT is RCD002CL, shown in 2. The first thing that RCD002CL does is create a user space in QTEMP. Although there is no command in OS/400 to create a user space, it is easy enough to create one. The source code for the command CRTUSRSPC is shown in 3. Make sure that when creating this command, you use the Create User Space (QUSCRTUS) API as the command processing program.
The command processing program for DSPRCDFMT is RCD002CL, shown in Figure 2. The first thing that RCD002CL does is create a user space in QTEMP. Although there is no command in OS/400 to create a user space, it is easy enough to create one. The source code for the command CRTUSRSPC is shown in Figure 3. Make sure that when creating this command, you use the Create User Space (QUSCRTUS) API as the command processing program.
The utility then uses the List Fields (QUSLFLD) API to load the user space with all of the fields in a file, along with their definition. The Display File Description (DSPFD) command is then executed to an OUTFILE in order to retrieve the access path. Unfortunately, IBM's database APIs don't provide this information, so the DSPFD command will have to do. RCD002RG, a RPG program shown in 4, is then called to retrieve the list of fields from the user space. Depending on the user's request, this information -- along with the access path information -- is then written to either a display file, RCD002DF (shown in 5), or to a spool file.
The utility then uses the List Fields (QUSLFLD) API to load the user space with all of the fields in a file, along with their definition. The Display File Description (DSPFD) command is then executed to an OUTFILE in order to retrieve the access path. Unfortunately, IBM's database APIs don't provide this information, so the DSPFD command will have to do. RCD002RG, a RPG program shown in Figure 4, is then called to retrieve the list of fields from the user space. Depending on the user's request, this information -- along with the access path information -- is then written to either a display file, RCD002DF (shown in Figure 5), or to a spool file.
DSPRCDFMT is a utility that should prove to be a real productivity booster. Without it, you would have to page through the output of several OS/400 commands. DSPRCDFMT can be particularly useful from within SEU, since it is usually while coding that you realize you need the name or size of a field, or the record format name, or the names of the key fields. By pressing F21 to pop up a command window, you can use DSPRCDFMT to look at files on the fly. Once you start using this utility, you will wonder how you ever got along without it.
DSPRCDFMT -- An API Alternative to DSPFFD
Figure 1 Command DSPRCDFMT
DSPRCDFMT: CMD PROMPT('File Field Description') PARM KWD(FILE) TYPE(QUAL) MIN(1) PROMPT('File') PARM KWD(OUTPUT) TYPE(*CHAR) LEN(7) RSTD(*YES) + DFT(*) VALUES(* *PRINT *SRCMBR) + PROMPT('Output') PARM KWD(SRCF) TYPE(Q2) PMTCTL(PC1) + PROMPT('Source file') PARM KWD(MBR) TYPE(*NAME) LEN(10) DFT(*FILE) + SPCVAL((*FILE)) PMTCTL(PC1) PROMPT('Member') PARM KWD(MBROPT) TYPE(*CHAR) LEN(8) RSTD(*YES) + DFT(*REPLACE) VALUES(*ADD *REPLACE) + PMTCTL(PC1) PROMPT('Member options') QUAL: QUAL TYPE(*NAME) LEN(10) QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) + SPCVAL((*LIBL)) PROMPT('Library') Q2: QUAL TYPE(*NAME) LEN(10) DFT(QPGMSRC) QUAL TYPE(*NAME) LEN(10) DFT(QTEMP) + SPCVAL((*LIBL)) PROMPT('Library') PC1: PMTCTL CTL(OUTPUT) COND((*EQ '*SRCMBR'))
DSPRCDFMT -- An API Alternative to DSPFFD
Figure 2 CL program RCD002CL
RCD002CL: + PGM PARM(&FILE &OUTPUT &QUALSRCF &MBR &MBROPT) DCL VAR(&FILE) TYPE(*CHAR) LEN(20) DCL VAR(&FILNAM) TYPE(*CHAR) LEN(10) DCL VAR(&LIBNAM) TYPE(*CHAR) LEN(10) DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(80) DCL VAR(&MSGID) TYPE(*CHAR) LEN(7) DCL VAR(&OUTPUT) TYPE(*CHAR) LEN(7) DCL VAR(&QUALSRCF) TYPE(*CHAR) LEN(20) DCL VAR(&MBR) TYPE(*CHAR) LEN(10) DCL VAR(&SRCF) TYPE(*CHAR) LEN(10) DCL VAR(&SRCFLIB) TYPE(*CHAR) LEN(10) DCL VAR(&MBROPT) TYPE(*CHAR) LEN(8) MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR)) CHGVAR VAR(&FILNAM) VALUE(%SST(&FILE 1 10)) CHGVAR VAR(&LIBNAM) VALUE(%SST(&FILE 11 10)) /* Validate source file name if OUTPUT(*SRCMBR) requested */ CHGVAR VAR(&SRCF) VALUE(%SST(&QUALSRCF 1 10)) CHGVAR VAR(&SRCFLIB) VALUE(%SST(&QUALSRCF 11 10)) IF COND(&MBR *EQ '*FILE') THEN(CHGVAR VAR(&MBR) VALUE(&FILNAM)) IF COND(&OUTPUT *EQ '*SRCMBR') THEN(DO) IF COND(&SRCFLIB *EQ 'QTEMP') THEN(DO) CRTSRCPF FILE(QTEMP/&SRCF) RCDLEN(92) MONMSG MSGID(CPF0000) ENDDO CHKOBJ OBJ(&SRCFLIB/&SRCF) OBJTYPE(*FILE) MBR(&MBR) MONMSG MSGID(CPF9801) EXEC(DO) CHGVAR VAR(&MSGDTA) VALUE('Source file' *BCAT &SRCFLIB + *TCAT '/' *CAT &SRCF *BCAT 'not found.') GOTO CMDLBL(SNDERRMSG) ENDDO MONMSG MSGID(CPF9810) EXEC(DO) CHGVAR VAR(&MSGDTA) VALUE('Source library' *BCAT &SRCFLIB + *BCAT 'not found.') GOTO CMDLBL(SNDERRMSG) ENDDO MONMSG MSGID(CPF9815) EXEC(DO) ADDPFM FILE(&SRCFLIB/&SRCF) MBR(&MBR) ENDDO ENDDO /* Create user space to begin processing */ CRTUSRSPC USRSPC(QTEMP/RCD002US) TEXT('User space for DSPRCDFMT') MONMSG MSGID(CPF9870) CALL PGM(QUSLFLD) PARM('RCD002US QTEMP ' 'FLDL0100' &FILE + '*FIRST ' '0') DSPFD FILE(&LIBNAM/&FILNAM) TYPE(*ACCPTH) OUTPUT(*OUTFILE) + OUTFILE(QTEMP/RCD002PF) IF COND(&OUTPUT *EQ '*SRCMBR') THEN(DO) IF COND(&MBROPT *EQ '*REPLACE') THEN(CLRPFM + FILE(&SRCFLIB/&SRCF) MBR(&MBR)) OVRDBF FILE(SOURCE) TOFILE(&SRCFLIB/&SRCF) MBR(&MBR) ENDDO OVRDBF FILE(QAFDACCP) TOFILE(RCD002PF) CALL PGM(RCD002RG) PARM(&OUTPUT) DLTOVR FILE(*ALL) GOTO CMDLBL(ENDPGM) ERROR: + RCVMSG MSGTYPE(*EXCP) MSGDTA(&MSGDTA) MSGID(&MSGID) SNDERRMSG: + SNDPGMMSG MSGID(&MSGID) MSGF(QCPFMSG) MSGDTA(&MSGDTA) + MSGTYPE(*ESCAPE) ENDPGM: + ENDPGM
DSPRCDFMT -- An API Alternative to DSPFFD
Figure 3 Command CRTUSRSPC
/*********************************************************************/ /* WHEN CREATING THIS COMMAND USE "QSYS/QUSCRTUS" AS THE COMMAND */ /* PROCESSING PROGRAM. */ /*********************************************************************/ CMD PROMPT('Create User Space') PARM KWD(USRSPC) TYPE(QUAL) PROMPT('User space') PARM KWD(ATR) TYPE(*CHAR) LEN(10) + PROMPT('Attribute') PARM KWD(SIZE) TYPE(*INT4) DFT(100000) + PROMPT('Size') PARM KWD(INIT) TYPE(*CHAR) LEN(1) PROMPT('Initial + value') PARM KWD(AUT) TYPE(*CHAR) LEN(10) RSTD(*YES) + DFT(*ALL) VALUES(*ALL *CHANGE *USE + *EXCLUDE) PROMPT('Public authority') PARM KWD(TEXT) TYPE(*CHAR) LEN(50) PROMPT('Text') QUAL: QUAL TYPE(*NAME) LEN(10) MIN(1) QUAL TYPE(*NAME) LEN(10) MIN(1) PROMPT('Library')
DSPRCDFMT -- An API Alternative to DSPFFD
Figure 4 RPG program RCD002RG
H * FQAFDACCPIF E DISK FRCD002DFCF E WORKSTN UC F SFLRN KSFILE DSPSFL01 FQPRINT O F 80 OF PRINTER UC FSOURCE O F 92 DISK A UC * E LN 5 1 E KF 25 10 E KN 25 3 0 * I DS I 1 176 #HEADR I B 1 40#OFSET I B 9 120#COUNT I B 13 160#LNGTH I 133 142 FILNAM I 143 152 LIBNAM I 153 162 FILTYP I 163 172 RCDFMT I B 173 1760#RCDLN * * I#INFO DS 288 I 1 10 FIELD I B 17 200#START I B 21 240#CHRLN I B 25 280#NUMLN I B 29 320#DECPS I 33 74 TEXT * I DS I I 125 B 1 40#STPOS I I 176 B 5 80#STLEN I I 'RCD002US QTEMP ' 9 28 #SPC20 * I DS I 1 50LEN I 1 5 LN * C *ENTRY PLIST C PARM #OUTPT 7 * C 1 DO #COUNT C CALL 'QUSRTVUS' C PARM #SPC20 C PARM #STPOS C PARM #STLEN C PARM #INFO C ADD 1 SFLRN 30 C Z-ADD#START FROM C #START ADD #CHRLN TO C SUB 1 TO * C #NUMLN IFGT 0 C MOVE #DECPS DEC 2 C MOVEL',' DEC C Z-ADD#NUMLN LEN C ELSE C MOVE *BLANKS DEC C Z-ADD#CHRLN LEN C END * C Z-ADD1 L 30 C L DOWLE5 C LN,L ANDEQ'0' C MOVE ' ' LN,L C ADD 1 L C END * C MOVEALN SIZE C MOVE DEC SIZE * C Z-ADD0 KEY C #SAVEK IFLE 25 C Z-ADD#SAVEK K C FIELD LOKUPKF,K 99 C *IN99 IFEQ '1' C Z-ADDKN,K KEY C END C END * C #OUTPT IFEQ '* ' C WRITEDSPSFL01 C ELSE C #OUTPT IFEQ '*PRINT ' C EXCPTDETAIL C ELSE C EXCPTWRTSRC C END C END * C ADD #STLEN #STPOS C END * C #OUTPT IFEQ '* ' C WRITEDSPRCD01 C EXFMTDSPCTL01 C END * C SETON LR ***************************************************************** C *INZSR BEGSR ***************************************************************** * C CALL 'QUSRTVUS' C PARM #SPC20 C PARM #STPOS C PARM #STLEN C PARM #HEADR * C #OFSET ADD 1 #STPOS C Z-ADD#LNGTH #STLEN C Z-ADD#RCDLN RCDLEN C Z-ADD#COUNT FIELDS * C #OUTPT IFEQ '* ' C OPEN RCD002DF C ELSE C #OUTPT IFEQ '*PRINT ' C OPEN QPRINT C EXCPTHEADER C ELSE C OPEN SOURCE C EXCPTSRCHDR C END C END * C Z-ADD26 K 30 C READ QWHFDACP 99 C *IN99 DOWEQ'0' C K ANDGT1 C SUB 1 K C MOVE APKEYF KF,K C Z-ADDAPKEYN KN,K C READ QWHFDACP 99 C END C Z-ADDK #SAVEK 30 C CLOSEQAFDACCP C ENDSR * OQPRINT E 2 1 HEADER O OR OF O 51 'File Field Description' * O E 1 HEADER O OR OF O 12 'File . . :' O FILNAM 23 O 42 'Record format . :' O RCDFMT 53 O 74 'Record length . . :' O RCDLEN3 80 * O E 2 HEADER O OR OF O 12 'Library . :' O LIBNAM 23 O 42 'Type of file . . :' O FILTYP 53 O 74 'Number of fields . :' O FIELDS3 80 * O E 1 HEADER O OR OF O 5 'From' O 10 'To' O 18 'Size' O 24 'Key' O 32 'Field' O 42 'Text' * O EF 1 DETAIL O FROM 3 5 O TO 3 10 O SIZE 18 O KEY 4 23 O FIELD 37 O TEXT 80 * OSOURCE EADD SRCHDR O 63 'File Field Description' O EADD SRCHDR O 24 'File . . :' O FILNAM 35 O 54 'Record format . :' O RCDFMT 65 O 86 'Record length . . :' O RCDLEN3 92 O EADD SRCHDR O 24 'Library . :' O LIBNAM 35 O 54 'Type of file . . :' O FILTYP 65 O 86 'Number of fields . :' O FIELDS3 92 O EADD SRCHDR O 17 'From' O 22 'To' O 30 'Size' O 36 'Key' O 44 'Field' O 54 'Text' O EADD WRTSRC O FROM 3 17 O TO 3 22 O SIZE 30 O KEY 4 35 O FIELD 49 O TEXT 92
DSPRCDFMT -- An API Alternative to DSPFFD
Figure 5 Display file RCD002DF
A DSPSIZ(24 80 *DS3) A PRINT A CA03(03) A CA12(12) A R DSPSFL01 SFL A FROM 4Y 0O 7 2EDTCDE(3) A TO 4Y 0O 7 7EDTCDE(3) A SIZE 7A O 7 12 A KEY 3Y 0O 7 21EDTCDE(4) A FIELD 10A O 7 28 A TEXT 42A O 7 39 A R DSPCTL01 SFLCTL(DSPSFL01) A SFLSIZ(0016) A SFLPAG(0015) A OVERLAY A PUTOVR A SFLDSP A SFLDSPCTL A N90 SFLEND A 1 30'Display Record Format' A DSPATR(HI) A 3 2'File . . :' A FILNAM 10A O 3 14 A 3 25'Record format . :' A RCDFMT 10A O 3 44 A 3 55'Record length . . :' A RCDLEN 5Y 0O 3 76EDTCDE(3) A 4 2'Library . :' A LIBNAM 10A O 4 14 A 4 25'Type of file . . :' A FILTYP 10A O 4 44 A 4 55'Number of fields . :' A FIELDS 5Y 0O 4 76EDTCDE(3) A 6 2'From' A DSPATR(HI) A 6 9'To' A DSPATR(HI) A 6 15'Size' A DSPATR(HI) A 6 22'Key' A DSPATR(HI) A 6 28'Field' A DSPATR(HI) A 6 39'Text' A DSPATR(HI) A R DSPRCD01 A 23 2'F3=Exit' A COLOR(BLU) A 23 13'F12=Cancel' A COLOR(BLU)
LATEST COMMENTS
MC Press Online