Problem solve Get help with specific problems with your technologies, process and projects.

CHKPF -- Scan your iSeries for damaged files

User Andrew Farmer tells you how to use the CHKPF command to identify problem files -- and he provides sample code.

This tip was submitted to the search400 Tip Exchange by user Andrew Farmer. Rate it below to let other users know how useful it is.

The CHKPF command can be run in batch or interactively. Physical files that are found to have data integrity errors or damage are identified by a message sent to the user profile message queue of the user profile who ran or submitted the CHKPF command. Physical files that are identified with data integrity errors or damage should be reviewed individually prior to performing any damage recovery.

To create the CHKPF command, do the following:

  1. Create source member CHKPF in source file QTXTSRC of library QGPL. Update the source member with the following statements:
            CREATE  TABLE QGPL/CHKPF (DBXLIB CHAR (10) NOT NULL WITH DEFAULT,
    DBXFIL CHAR (10) NOT NULL WITH DEFAULT)
  2. Create table CHKPF in library QGPL by running the SQL statement entered into source member CHKPF:
            RUNSQLSTM  SRCFILE(QGPL/QTXTSRC)  SRCMBR(CHKPF)  +
    COMMIT(*NONE)
  3. Create source member CHKPF in source file QCLSRC of library QGPL. Update the source member with the CHKPF CL source listed below.
  4. Create program CHKPF in library QGPL. Library QGPL must be in your library list:
            CRTCLPGM  PGM(QGPL/CHKPF)  SRCFILE(QGPL/QCLSRC)  +
    SRCMBR(CHKPF)
  5. Create source member CHKPF in source file QCMDSRC of library QGPL. Update the source member with the following statements:
            CMD        PROMPT('Check Damage on Physical Files')
    PARM KWD(LIBRARY) TYPE(*CHAR) LEN(10) +
    DFT(*ALL) MIN(0) PROMPT('Library name')
  6. Create command CHKPF in library QGPL:
             CRTCMD  CMD(QGPL/CHKPF)  PGM(QGPL/CHKPF)  +
    SRCFILE(QGPL/QCMDSRC) SRCMBR(CHKPF)

The CHKPF command is now ready for use. Prior to running the CHKPF command for all libraries, it is advisable to verify that the command works by running it for a single library first, for example, QGPL.

Code:

                *****   CL  CODE  *****


/*********************************************************************/
/*                                                                   */
/*  The CHKPF command will use CPYF to read every record of every    */
/*  physical file or table of a library or all libraries on the      */
/*  system. Upon completion any PF's with data errors will be        */
/*  identified. These PF's should be reviewed for possible invalid   */
/*  data contents or damage.                                         */
/*                                                                   */
/*********************************************************************/


            PGM        PARM(&LIBRARY)
            DCL        VAR(&LIBRARY) TYPE(*CHAR) LEN(10)
            DCL        VAR(&MSGTXT) TYPE(*CHAR) LEN(512)
            DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)
            DCL        VAR(&MSGKEY) TYPE(*CHAR) LEN(4) VALUE('9999')
            DCL        VAR(&MSGTXT1) TYPE(*CHAR) LEN(256)
            DCL        VAR(&PFCNT) TYPE(*DEC) LEN(9 0)
            DCL        VAR(&PFCNTA) TYPE(*CHAR) LEN(9)
            DCL        VAR(&PFERR) TYPE(*DEC) LEN(9 0)
            DCL        VAR(&PFERRA) TYPE(*CHAR) LEN(9)
            DCL        VAR(&USER) TYPE(*CHAR) LEN(10)
	    DCLF       FILE(CHKPF)


	    RTVJOBA    USER(&USER)

/**********************************************************************/
	
	    IF         COND(&LIBRARY *NE '*ALL') THEN(DO)
	    CHKOBJ     OBJ(&LIBRARY) OBJTYPE(*LIB)
	    MONMSG     MSGID(CPF0000) EXEC(DO)
	    CHGVAR     VAR(&MSGTXT) VALUE('Library ' *CAT +
        	         &LIBRARY *BCAT 'not found or not +
             	         available.')
    	    SNDPGMMSG  MSG(&MSGTXT) TOPGMQ(*PRV) MSGTYPE(*COMP)
	    GOTO       CMDLBL(ENDOFPGM)
	    ENDDO
	    ENDDO


       	    OVRDBF     FILE(QADBXREF)
	    IF         COND(&LIBRARY *EQ '*ALL') THEN(DO)
	    OPNQRYF    FILE((QSYS/QADBXREF)) FORMAT(QGPL/CHKPF) +
        	         QRYSLT('DBXATR = %VALUES("PF" +
             	         "TB")') KEYFLD(*FILE)
	
	    ENDDO
	    ELSE       CMD(DO)
	    OPNQRYF    FILE((QSYS/QADBXREF)) FORMAT(QGPL/CHKPF) +
             		 QRYSLT('DBXLIB = ''' *CAT &LIBRARY *CAT +
             		 ''' *AND DBXATR = %VALUES("PF" "TB")') +
             		 KEYFLD(*FILE)
	    ENDDO

	    DLTF       FILE(QTEMP/CHKPF)
	    MONMSG     MSGID(CPF0000)

/**********************************************************************/

            CRTDUPOBJ  OBJ(CHKPF) FROMLIB(QGPL) OBJTYPE(*FILE) +
                         TOLIB(QTEMP)
            CPYFRMQRYF FROMOPNID(QADBXREF) TOFILE(QTEMP/CHKPF) +
                         MBROPT(*REPLACE)
            CLOF       OPNID(QADBXREF)
            DLTOVR     FILE(QADBXREF)


            OVRDBF     FILE(CHKPF) TOFILE(QTEMP/CHKPF)
READ:       RCVF
            MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(ENDREAD))
            CHGVAR     VAR(&PFCNT) VALUE(&PFCNT +1)
            IF         COND(&DBXFIL *EQ 'CHKPF') THEN(GOTO +
                         CMDLBL(READ))


            DLTF       FILE(QTEMP/&DBXFIL)
            MONMSG     MSGID(CPF2105)

            CPYF       FROMFILE(&DBXLIB/&DBXFIL) +
                         TOFILE(QTEMP/&DBXFIL) FROMMBR(*ALL) +
                         TOMBR(*FROMMBR) MBROPT(*REPLACE) +
                         CRTFILE(*YES) FROMRCD(1) INCCHAR(*RCD 1 +
                         *EQ '@#[%')

            MONMSG     MSGID(CPF2817) EXEC(DO)
            RCVMSG     MSGTYPE(*LAST) RMV(*NO) KEYVAR(&MSGKEY)

/**********************************************************************/

RECIEVE:    RCVMSG     MSGTYPE(*PRV) MSGKEY(&MSGKEY) +
                         KEYVAR(&MSGKEY) MSG(&MSGTXT1) MSGID(&MSGID)

            IF         COND(&MSGID *EQ 'CPF2868') THEN(GOTO +
                         CMDLBL(READ))


            IF         COND(&MSGID *EQ 'CPF2883') THEN(GOTO +
                         CMDLBL(RECIEVE))


            IF         COND(&MSGID *EQ 'CPF320B') THEN(GOTO +
                         CMDLBL(READ))


            IF         COND(&MSGID *EQ 'CPF2833') THEN(GOTO +
                         CMDLBL(TEST1))

            GOTO       CMDLBL(SNDERROR)
            ENDDO
            MONMSG     MSGID(CPF2952) EXEC(DO)
            RCVMSG     MSGTYPE(*LAST) RMV(*NO) KEYVAR(&MSGKEY)

	    RCVMSG     MSGTYPE(*PRV) MSGKEY(&MSGKEY) +
             	         KEYVAR(&MSGKEY) MSG(&MSGTXT1) MSGID(&MSGID)


	    IF         COND(&MSGID *EQ 'CPF4234') THEN(GOTO +
                         CMDLBL(READ))
	    GOTO       CMDLBL(SNDERROR)
	    ENDDO

	    MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR))
            GOTO       CMDLBL(READ)

/**********************************************************************/

TEST1:      CPYF       FROMFILE(&DBXLIB/&DBXFIL) +
                         TOFILE(QTEMP/&DBXFIL) FROMMBR(*ALL) +
                         TOMBR(*FROMMBR) MBROPT(*REPLACE) +
                         CRTFILE(*YES) FROMRCD(1) INCCHAR(*RCD 1 +
                         *EQ '@') ERRLVL(0)

            MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR))

            GOTO       CMDLBL(READ)


ERROR:      RCVMSG     MSGTYPE(*LAST) RMV(*NO) KEYVAR(&MSGKEY)
            RCVMSG     MSGTYPE(*PRV) MSGKEY(&MSGKEY) +
                         KEYVAR(&MSGKEY) MSG(&MSGTXT1) MSGID(&MSGID)


SNDERROR:   CHGVAR     VAR(&MSGTXT) VALUE('Error on file ' *CAT +
                         &DBXFIL *BCAT 'in library ' *CAT &DBXLIB +
                         *TCAT '. Failing message is ' *CAT &MSGID +
                         *BCAT ': ' *CAT &MSGTXT1)
            SNDMSG     MSG(&MSGTXT) TOUSR(&USER)
            MONMSG     MSGID(CPF0000)


            CHGVAR     VAR(&PFERR) VALUE(&PFERR +1)
            CHGVAR     VAR(&MSGTXT) VALUE('File ' *CAT &DBXFIL +
                         *BCAT 'in library ' *CAT &DBXLIB *BCAT +
                         'in error.')
            SNDPGMMSG  MSG(&MSGTXT) TOPGMQ(*PRV) TOMSGQ(*TOPGMQ) +
                         MSGTYPE(*DIAG)
            GOTO       CMDLBL(READ)

ENDREAD:    CHGVAR     VAR(&PFCNTA) VALUE(&PFCNT)
            CHGVAR     VAR(&MSGTXT) VALUE(&PFCNTA *BCAT 'Physical +
                         Files processed for library ' *CAT +
                         &LIBRARY *TCAT '.')
            SNDPGMMSG  MSG(&MSGTXT) TOPGMQ(*PRV) TOMSGQ(*TOPGMQ) +
                         MSGTYPE(*COMP)
            IF         COND(&PFERR *EQ 0) THEN(DO)
            CHGVAR     VAR(&MSGTXT) VALUE('No errors found.')
            SNDPGMMSG  MSG(&MSGTXT) TOPGMQ(*PRV) MSGTYPE(*COMP)
            ENDDO
            ELSE       CMD(DO)
            CHGVAR     VAR(&PFERRA) VALUE(&PFERR)
            CHGVAR     VAR(&MSGTXT) VALUE(&PFERRA *BCAT 'Physical +
                         files were in error for library ' *CAT +
                         &LIBRARY *TCAT '. Review the previous +
                         job log messages for addtional +
                         information.')
            SNDPGMMSG  MSG(&MSGTXT) MSGTYPE(*COMP)


            ENDDO

ENDOFPGM:   DLTOVR     FILE(CHKPF)

            ENDPGM

Dig Deeper on Implementation

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close