星期一, 11月 06, 2023

2005-01-24 如何直接取得 Current job 最後一個報表的相關資訊 ?(API QSPRILSP)


2005-01-24 如何直接取得 Current job 最後一個報表的相關資訊 ?(API QSPRILSP)

從 OS V5R2 起,系統提供一個新的 RETRIEVE IDENTITY OF LAST SPOOLED FILE CREATED (QSPRILSP) API,
以便於程式執行時可以直接取的最新的報表資訊。


File  : QCLSRC
Member: RTVLSPSPLC
Type  : CLP
Usage : CRTCLPGM RTVLSTSPLC
        CALL RTVLSTSPLC
        then see dump spooled file for last spooled file information, or sent error message to job log


/*    In V5R2 new API                                                */
/*    RETRIEVE IDENTITY OF LAST SPOOLED FILE CREATED (QSPRILSP) API  */
/*                                                                   */

PGM

    DCL VAR(&RCVVAR)     TYPE(*CHAR) LEN(70)
    DCL VAR(&RCVVARLEN)  TYPE(*CHAR) LEN(4)

 /* only contain front 8 bytes for bytes provide and byte available */
    DCL VAR(&ERRCODE)    TYPE(*CHAR) LEN(8)

    /* FIELDS FROM FORMAT SPRL0100 */

    DCL VAR(&BYTESRTN)   TYPE(*DEC)  LEN(10 0)
    DCL VAR(&BYTESAVL)   TYPE(*DEC)  LEN(10 0)
    DCL VAR(&SPLFNAME)   TYPE(*CHAR) LEN(10)
    DCL VAR(&JOBNAME)    TYPE(*CHAR) LEN(10)
    DCL VAR(&USERNAME)   TYPE(*CHAR) LEN(10)
    DCL VAR(&JOBNBR)     TYPE(*CHAR) LEN(6)
    DCL VAR(&SPLFNBR)    TYPE(*DEC)  LEN(6 0)
    DCL VAR(&SYSTEMNAME) TYPE(*CHAR) LEN(8)
    DCL VAR(&CREATEDATE) TYPE(*CHAR) LEN(7)
    DCL VAR(&CREATETIME) TYPE(*CHAR) LEN(6)

    DCL        VAR(&MSGDTA) TYPE(*CHAR) LEN(256)
    DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)

  /* only get error bytes prodvide and bytes available */
  /* when call API error,                              */
  /* this will issue error message to job log, cna use MONMSG to  */
  /* monitor API error                                            */
    CHGVAR VAR(%BIN(&ERRCODE 1 4))   VALUE(0)

    /* &RCVVARLEN NEEDS TO BE SET TO THE SIZE OF &RCVVAR.  +
       IF YOU CHANGE THE SIZE OF &RCVVAR, CHANGE IT ON THE +
       LINE BELOW AS WELL! (CL HAS NO %SIZE BIF!!)        */

    CHGVAR VAR(%BIN(&RCVVARLEN 1 4)) VALUE(70)

    CALL PGM(QSPRILSP) PARM( &RCVVAR    +
                             &RCVVARLEN +
                             'SPRL0100' +
                             &ERRCODE   )
    MONMSG CPF0000 EXEC(GOTO ERROR)

    /* SINCE CL HAS NO SUCH THING AS A DATA STRUCTURE, I'VE +
       PUT ALL OF THE FIELDS INTO ONE BIG &RCVVAR FIELD,    +
       AND WILL SPLIT IT INTO SUBFIELDS BELOW:             */

    CHGVAR VAR(&BYTESRTN)   VALUE(%BIN(&RCVVAR  1  4))
    CHGVAR VAR(&BYTESAVL)   VALUE(%BIN(&RCVVAR  5  4))
    CHGVAR VAR(&SPLFNAME)   VALUE(%SST(&RCVVAR  9 10))
    CHGVAR VAR(&JOBNAME)    VALUE(%SST(&RCVVAR 19 10))
    CHGVAR VAR(&USERNAME)   VALUE(%SST(&RCVVAR 29 10))
    CHGVAR VAR(&JOBNBR)     VALUE(%SST(&RCVVAR 39  6))
    CHGVAR VAR(&SPLFNBR)    VALUE(%BIN(&RCVVAR 45  4))
    CHGVAR VAR(&SYSTEMNAME) VALUE(%SST(&RCVVAR 49  8))
    CHGVAR VAR(&CREATEDATE) VALUE(%SST(&RCVVAR 57  7))
    CHGVAR VAR(&CREATETIME) VALUE(%SST(&RCVVAR 65  6))

    /* THE FIELDS ABOVE NOW CONTAIN INFO ABOUT THE LAST   +
       SPOOLED FILE CREATED IN THE JOB.                  */

   DMPCLPGM
   GOTO END

ERROR:
             DMPCLPGM
             RCVMSG     MSGTYPE(*EXCP) RMV(*NO) MSG(&MSGDTA) +
                          MSGID(&MSGID)
             SNDPGMMSG  MSG(&MSGID *BCAT &MSGDTA)
             SNDPGMMSG  MSG('Call API error with ERRCODE Bytes +
                          Provided value = 0, please see job log')

END:

ENDPGM

            





沒有留言: