星期二, 11月 07, 2023

2006-08-24 如何擷取 PF 檔案格式的長度 ? (RTVRECLEN command with API QUSLRCD)


如何擷取 PF 檔案格式的長度 ? (RTVRECLEN command with API QUSLRCD)

File  : QCLSRC
Member: RTVRECLENC
Type  : CLP
Usage : CRTCLPGM RTVRECLENC


  /*  Program : RTVRCDLENC                                      */
  /*  System  : iSeries                                         */
  /*  AUTHOR :  Vengoal Chang                 August 24,  2006  */
  /*                                                            */
  /*  Retrieve record length                                    */

  /* TO COMPILE :                                               */
  /*                                                            */
  /*        CRTCLPGM    PGM(XXX/RTVRECLENC) +                   */
  /*                      SRCFILE(XXX/QLSRC) +                  */


 RTVRCDLEN:  PGM        PARM(&FILEQUAL &RCDLEN)

             DCL        VAR(&FILEQUAL) TYPE(*CHAR) LEN(20) /* +
                          qualified file name */
             DCL        VAR(&RCDLEN) TYPE(*DEC) LEN(5 0) /* record +
                          length in decimal */

             DCL        VAR(&RCDLENCHR) TYPE(*CHAR) LEN(5) /* record +
                          length in character format */
             DCL        VAR(&FILENAME) TYPE(*CHAR) LEN(10) /* file +
                          name */
             DCL        VAR(&LIBNAME) TYPE(*CHAR) LEN(10) /* library +
                          name */


  /*   API DATA    */

             DCL        VAR(&RCDLENBIN) TYPE(*CHAR) LEN(4)
             DCL        VAR(&RCDFMT) TYPE(*CHAR) LEN(10)
             DCL        VAR(&RCDTXT) TYPE(*CHAR) LEN(50)

  /*  PARAMETERS FOR THE QUSLRCD   API    */

             DCL        VAR(&FILQUAL) TYPE(*CHAR) LEN(20)

  /*  PARAMETERS FOR THE QUSCRTUS  API    */

             DCL        VAR(&USP_NAME) TYPE(*CHAR) LEN(10) /* user +
                          space name */
             DCL        VAR(&USP_LIB) TYPE(*CHAR) LEN(10) /* user +
                          space library */
             DCL        VAR(&USP_QUAL) TYPE(*CHAR) LEN(20) /* user +
                          space qualified name */
             DCL        VAR(&USP_TYPE) TYPE(*CHAR) LEN(10) /* user +
                          space type */
             DCL        VAR(&USP_SIZE) TYPE(*CHAR) LEN(4) /* user +
                          space size */
             DCL        VAR(&USP_FILL) TYPE(*CHAR) LEN(1) /* user +
                          space fill character */
             DCL        VAR(&USP_AUT) TYPE(*CHAR) LEN(10) /* user +
                          space authority */
             DCL        VAR(&USP_TEXT) TYPE(*CHAR) LEN(50) /* user +
                          space text */
             DCL        VAR(&USP_REPL) TYPE(*CHAR) LEN(10) /* user +
                          space replace */
             DCL        VAR(&USP_ERROR) TYPE(*CHAR) LEN(256) /* user +
                          space error */

  /*  PARAMETERS FOR THE QUSRTVUS  API    */

             DCL        VAR(&STARTPOS) TYPE(*CHAR) LEN(4)
             DCL        VAR(&DATALEN ) TYPE(*CHAR) LEN(4)
             DCL        VAR(&RECEIVER) TYPE(*CHAR) LEN(16)

             DCL        VAR(&LISTOFFSET) TYPE(*DEC) LEN(5 0) /* +
                          offset of first data */
             DCL        VAR(&LISTSIZE) TYPE(*DEC) LEN(5 0) /* size +
                          of data */
             DCL        VAR(&ENTNBR) TYPE(*DEC) LEN(5 0) /* number +
                          of entries */
             DCL        VAR(&ENTLEN) TYPE(*DEC) LEN(5 0) /* entry +
                          length in dec */
             DCL        VAR(&ENTLENBIN) TYPE(*CHAR) LEN(4) /* entry +
                          length in binary */
             DCL        VAR(&LISTPOSBIN) TYPE(*CHAR) LEN(4) /* +
                          position of first entry in binary */
             DCL        VAR(&COUNT) TYPE(*DEC) LEN(5) VALUE(0) /* +
                          counter */
             DCL        VAR(&DATA) TYPE(*CHAR) LEN(4096)

             CHGVAR     VAR(&FILENAME) VALUE(%SST(&FILEQUAL 1 10))
             CHGVAR     VAR(&LIBNAME) VALUE(%SST(&FILEQUAL 11 10))

             CHKOBJ     OBJ(&LIBNAME/&FILENAME) OBJTYPE(*FILE)
             MONMSG     MSGID(CPF0000) EXEC(DO)
             SNDPGMMSG  MSG('** ERROR ** File ' *CAT &LIBNAME *TCAT +
                          '/' *CAT &FILENAME *BCAT 'does not exist +
                          or you are not authorised') MSGTYPE(*DIAG)
             SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('** +
                          Error **') MSGTYPE(*ESCAPE)
             GOTO       CMDLBL(END)
             ENDDO

 /*  CREATE USER SPACE */

             CHGVAR     VAR(&USP_NAME) VALUE('MYUSRSPACE') /* set +
                          user space name */
             CHGVAR     VAR(&USP_LIB) VALUE('QTEMP') /* set user +
                          space library */
             CHGVAR     VAR(&USP_QUAL) VALUE(&USP_NAME *CAT +
                          &USP_LIB) /* set user space qualified name */
             CHGVAR     VAR(&USP_TYPE) VALUE('MYTYPE') /* set user +
                          space type */
             CHGVAR     VAR(%BIN(&USP_SIZE)) VALUE(64000) /* set user +
                          space size */
             CHGVAR     VAR(&USP_FILL) VALUE(' ') /* set user space +
                          fill character */
             CHGVAR     VAR(&USP_AUT) VALUE('*USE') /* set user +
                          space authority */
             CHGVAR     VAR(&USP_TEXT) VALUE('HVDS : my user space') +
                          /* set user space text */
             CHGVAR     VAR(%BIN(&USP_ERROR 1 4)) VALUE(0)


             CALL       PGM(QUSCRTUS) PARM(&USP_QUAL &USP_TYPE +
                          &USP_SIZE &USP_FILL &USP_AUT &USP_TEXT)


 /*  EXECUTE  API  */


             CALL       PGM(QUSLRCD) PARM(&USP_QUAL 'RCDL0200' +
                          &FILEQUAL '0' &USP_ERROR)


 /*  RETRIEVE DATA IN USER SPACE */

             CHGVAR     VAR(%BIN(&STARTPOS)) VALUE(125) /* set start +
                          position */
             CHGVAR     VAR(%BIN(&DATALEN)) VALUE(16) /* set data +
                          length    */

             CALL       PGM(QUSRTVUS) PARM(&USP_QUAL &STARTPOS +
                          &DATALEN &RECEIVER)

             CHGVAR     VAR(&LISTOFFSET) VALUE(%BIN(&RECEIVER 1 4))
             CHGVAR     VAR(&LISTSIZE)   VALUE(%BIN(&RECEIVER 5 4))
             CHGVAR     VAR(&ENTNBR)     VALUE(%BIN(&RECEIVER 9 4))
             CHGVAR     VAR(&ENTLEN)     VALUE(%BIN(&RECEIVER 13 4))

             CHGVAR     VAR(%BIN(&LISTPOSBIN)) VALUE(&LISTOFFSET + 1)
             CHGVAR     VAR(&ENTLENBIN) VALUE(%SST(&RECEIVER 13 4))


  /*  ENTRY RETRIEVAL  */

             CHGVAR     VAR(&COUNT) VALUE(0)

             IF         COND(&COUNT *EQ &ENTNBR) THEN(GOTO +
                          CMDLBL(DONE))

             CALL       PGM(QUSRTVUS) PARM(&USP_QUAL &LISTPOSBIN +
                          &ENTLENBIN &DATA)

  /* EXTRACT DATA */

             CHGVAR     VAR(&RCDFMT) VALUE(%SST(&DATA 1 10))
             CHGVAR     VAR(&RCDLENBIN) VALUE(%SST(&DATA 25 4))
             CHGVAR     VAR(&RCDTXT) VALUE(%SST(&DATA 33 50))

             CHGVAR     VAR(&RCDLEN) VALUE(%BIN(&RCDLENBIN))
             CHGVAR     VAR(&RCDLENCHR) VALUE(&RCDLEN)

  /* send completion message */
             SNDPGMMSG  MSG(&LIBNAME *TCAT '/' *CAT &FILENAME *BCAT +
                            'Record length = ' *CAT &RCDLENCHR) +
                          MSGTYPE(*COMP)

 DONE:       DLTUSRSPC  USRSPC(&USP_LIB/&USP_NAME)

 END:        ENDPGM




File  : QCMDSRC
Member: RTVRECLEN
Type  : CMD
Usage : CRTCMD CMD(RTVRECLEN) PGM(yourlib/RTVRECLENC) ALLOW(*IPGM *BPGM)

  /*  Command : RTVRCDLEN                                       */
  /*  System  : iSeries                                         */
  /*  AUTHOR :  Vengoal Chang                 August 24,  2006  */
  /*  Retrieve record length                                    */
  
 /* TO COMPILE :                                                */
 /*                                                             */
 /*        CRTCMD     CMD(XXX/RTVRECLEN) PGM(XXX/RTVRECLENC) +  */
 /*                      SRCFILE(XXX/QCMDSRC) +                 */
 /*     ALLOW(*IPGM  *BPGM)                          */

 RTVRECLEN:  CMD        PROMPT('Retrieve record length')

             PARM       KWD(FILE) TYPE(FILENAME) PROMPT('File name')

             PARM       KWD(RECLEN) TYPE(*DEC) LEN(5 0) RTNVAL(*YES) +
                          PROMPT('Record length')

 FILENAME:   QUAL       TYPE(*NAME) LEN(10) MIN(1)
             QUAL       TYPE(*NAME) LEN(10) DFT(*LIBL) +
                          SPCVAL((*CURLIB) (*LIBL)) PROMPT('Library')



File  : QCLSRC
Member: RTVRECLENT
Type  : CLP
Usage : CRTCLPGM RTVRECLENT
        CALL RTVRECLENT
        
        DSPJOBLOG -> Enter -> F10 -> pageup        
        會看到
        QGPL/QDDSSRC Record length = 00092 訊息


PGM                                                  
                                                     
             DCL  &RECLENC *CHAR 5                   
             DCL  &RECLEN  *DEC  5 0                 
             RTVRECLEN  FILE(QGPL/QDDSSRC) RECLEN(&RECLEN) 
             CHGVAR &RECLENC &RECLEN                 
                  
ENDPGM


                       



沒有留言: