Use APIs to produce all SPLF from a specific OUTQ

Use Application Programming Interfaces (APIs) to change specific attributes from all Spooled Files in a specific output queue.

Use Application Programming Interfaces (APIs) to change specific attributes from all Spooled Files in a specific

output queue.

In my example, the PGM is changing the USRDTA field and moving the Spooled Files from OUTQ_FROM to OUTQ_TO.

The input parameters and the SPLF attributes you're going to update can be changed.

My intention is only to write a example of a PGM using APIs to process all SPLF from a specific OUTQ.

APIs have some advantages against traditional programming techniques.

Faster execution:
If additional input or output parameters are provided for any of the APIs (i.e. by OS/400 release upgrade), the new parameters will be placed after the current parameters and will be optional parameters. The existing APIs will continue to work without any changes


    
/*'=================================================================EUR*/
/*'                                                                 EUR*/
/*'CHANGE USERDATA ON ALL SPLF IN A SPECIFIC OUTQ AND MOVE TO       EUR*/
/*'ANOTHER OUTPUT QUEUE                                             EUR*/
/*'-----------------------------------------------------------------EUR*/
/*'Date       | Author       | Description                          EUR*/
/*'-----------+--------------+--------------------------------------EUR*/
/*'02.04.2004 | J. SAUVAGEOT | Creation                             EUR*/
/*'===========+==============+======================================EUR*/
             PGM        PARM(&OUTQ_FROM &OUTQL_FROM &USRDTA &OUTQ_TO +
                          &OUTQL_TO)

             DCL        VAR(&OUTQ_FROM) TYPE(*CHAR) LEN(10)
             DCL        VAR(&OUTQL_FROM) TYPE(*CHAR) LEN(10)
             DCL        VAR(&USRDTA) TYPE(*CHAR) LEN(10)
             DCL        VAR(&OUTQ_TO) TYPE(*CHAR) LEN(10)
             DCL        VAR(&OUTQL_TO) TYPE(*CHAR) LEN(10)

             DCL        VAR(&FILE)      TYPE(*CHAR) LEN(10)
             DCL        VAR(&JOBNAME)   TYPE(*CHAR) LEN(10)
             DCL        VAR(&USER)      TYPE(*CHAR) LEN(10)
             DCL        VAR(&JOBNUMBER) TYPE(*CHAR) LEN(6)
             DCL        VAR(&FILENR)    TYPE(*DEC) LEN(4)

             DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)
             DCL        VAR(&MSGDTALN) TYPE(*DEC) LEN(9 0)
             DCL        VAR(&MSGDTA) TYPE(*CHAR) LEN(80)
             DCL        VAR(&NO_ERROR) TYPE(*CHAR) LEN(4) +
                          VALUE(X'00000000')

/* Declares for QUSCRTUS - Create User Space */

             DCL        VAR(&QCUS_NAME) TYPE(*CHAR) LEN(20) +
                          VALUE('UPD_UDTA  QTEMP     ')
             DCL        VAR(&QCUS_EXATR) TYPE(*CHAR) LEN(10) +
                          VALUE('USRSPC    ')
/* Maximum number of SPLF the User Space will contain */
             DCL        VAR(&QCUS_SIZE) TYPE(*CHAR) LEN(4) +
                          VALUE(X'00010000')
             DCL        VAR(&QCUS_INIT) TYPE(*CHAR) LEN(1) VALUE(X'00')
             DCL        VAR(&QCUS_PUBA) TYPE(*CHAR) LEN(10) +
                          VALUE('*ALL      ')
             DCL        VAR(&QCUS_TEXT) TYPE(*CHAR) LEN(50)
             DCL        VAR(&QCUS_REPL) TYPE(*CHAR) LEN(10) +
                          VALUE('*YES      ')
             DCL        VAR(&QCUS_DOMN) TYPE(*CHAR) LEN(10) +
                          VALUE('*DEFAULT  ')

/* Declares for QUSLSPL - List Spooled Files */

             DCL        VAR(&QLSF_NAME) TYPE(*CHAR) LEN(20) +
                          VALUE('UPD_UDTA  QTEMP     ')
             DCL        VAR(&QLSF_FOMT) TYPE(*CHAR) LEN(8) +
                          VALUE('SPLF0100')
             DCL        VAR(&QLSF_USER) TYPE(*CHAR) LEN(10)
             DCL        VAR(&QLSF_OUTQ) TYPE(*CHAR) LEN(20)
             DCL        VAR(&QLSF_FORM) TYPE(*CHAR) LEN(10)
             DCL        VAR(&QLSF_USRD) TYPE(*CHAR) LEN(10)

/* Declares for QUSRTVUS - Retrieve User Space */

             DCL        VAR(&QRUS_NAME) TYPE(*CHAR) LEN(20) +
                          VALUE('UPD_UDTA  QTEMP     ')
             DCL        VAR(&QRUS_STRT) TYPE(*CHAR) LEN(4)
             DCL        VAR(&QRUS_LENG) TYPE(*CHAR) LEN(4)
             DCL        VAR(&QRUS_HEAD) TYPE(*CHAR) LEN(16)
             DCL        VAR(&QRUS_LINE) TYPE(*CHAR) LEN(82)
             DCL        VAR(&INT_OFFSET) TYPE(*DEC) LEN(9 0)
             DCL        VAR(&INT_NUMBER) TYPE(*DEC) LEN(9 0)
             DCL        VAR(&INT_SIZE) TYPE(*DEC) LEN(9 0)
             DCL        VAR(&INT_POSIT) TYPE(*DEC) LEN(9 0)

/* Variables QUSRSPLA - Get Spooled File Attributes */

             DCL        VAR(&QGSA_RCV) TYPE(*CHAR) LEN(3772)
             DCL        VAR(&QGSA_RCVLN) TYPE(*CHAR) LEN(4) +
                          VALUE(X'00000EBC')
             DCL        VAR(&QGSA_FOMT) TYPE(*CHAR) LEN(8) +
                          VALUE('SPLA0200')
             DCL        VAR(&QGSA_JOB) TYPE(*CHAR) LEN(26) +
                          VALUE('*INT                      ')
             DCL        VAR(&QGSA_IJOB) TYPE(*CHAR) LEN(16)
             DCL        VAR(&QGSA_ISPL) TYPE(*CHAR) LEN(16)
             DCL        VAR(&QGSA_SPLF) TYPE(*CHAR) LEN(10) +
                          VALUE('*INT      ')
             DCL        VAR(&QGSA_SPLNB) TYPE(*CHAR) LEN(4) +
                          VALUE(X'00000000')

/* Declares for QUSDLTUS - Delete User Space */

             DCL        VAR(&QDUS_NAME) TYPE(*CHAR) LEN(20) +
                          VALUE('UPD_UDTA  QTEMP     ')

/* Declares for QERRCD - Error Code */

             DCL        VAR(&QERRCD) TYPE(*CHAR) LEN(96)


/* Create Userspace */

             CHGVAR     VAR(%SST(&QERRCD 1 8)) +
                          VALUE(X'0000006000000000')
             CALL       PGM(QUSCRTUS) PARM(&QCUS_NAME &QCUS_EXATR +
                          &QCUS_SIZE &QCUS_INIT &QCUS_PUBA +
                          &QCUS_TEXT &QCUS_REPL &QERRCD &QCUS_DOMN)
             IF         COND(%SST(&QERRCD 5 4) *NE &NO_ERROR) +
                          THEN(GOTO CMDLBL(ERROR_API))

/* List all Spooled Files from a given Output Queue */

             CHGVAR     VAR(&QLSF_USER) VALUE('*ALL')
             CHGVAR     VAR(&QLSF_OUTQ) VALUE(&OUTQ_FROM *CAT +
                          &OUTQL_FROM)
             CHGVAR     VAR(&QLSF_FORM) VALUE('*ALL')
             CHGVAR     VAR(&QLSF_USRD) VALUE('*ALL')
             CHGVAR     VAR(%SST(&QERRCD 1 8)) +
                          VALUE(X'0000006000000000')
             CALL       PGM(QUSLSPL) PARM(&QLSF_NAME &QLSF_FOMT +
                          &QLSF_USER &QLSF_OUTQ &QLSF_FORM +
                          &QLSF_USRD &QERRCD)
             IF         COND(%SST(&QERRCD 5 4) *NE &NO_ERROR) +
                          THEN(GOTO CMDLBL(ERROR_API))

/* Read Headerdata from Userspace */

             CHGVAR     VAR(%BIN(&QRUS_STRT)) VALUE(125)
             CHGVAR     VAR(%BIN(&QRUS_LENG)) VALUE(16)
             CHGVAR     VAR(%SST(&QERRCD 1 8)) +
                          VALUE(X'0000006000000000')
             CALL       PGM(QUSRTVUS) PARM(&QRUS_NAME &QRUS_STRT +
                          &QRUS_LENG &QRUS_HEAD &QERRCD)
             IF         COND(%SST(&QERRCD 5 4) *NE &NO_ERROR) +
                          THEN(GOTO CMDLBL(ERROR_API))

             CHGVAR     VAR(&INT_OFFSET) VALUE(%BIN(&QRUS_HEAD 1 4))
             CHGVAR     VAR(&INT_NUMBER) VALUE(%BIN(&QRUS_HEAD 9 4))
             CHGVAR     VAR(&INT_SIZE) VALUE(%BIN(&QRUS_HEAD 13 4))

/* Loop through the Userspace */

             CHGVAR     VAR(&INT_POSIT) VALUE(0)
 LOOP_SPACE: CHGVAR     VAR(&INT_POSIT) VALUE(&INT_POSIT + 1)
             IF         COND(&INT_POSIT *GT &INT_NUMBER) THEN(GOTO +
                          CMDLBL(END_SPACE))

/* Read next Userspace detail line */

             CHGVAR     VAR(%BIN(&QRUS_STRT)) VALUE(&INT_OFFSET + +
                          ((&INT_POSIT - 1) * &INT_SIZE) + 1)
             CHGVAR     VAR(%BIN(&QRUS_LENG)) VALUE(82)
             CHGVAR     VAR(%SST(&QERRCD 1 8)) +
                          VALUE(X'0000006000000000')
             CALL       PGM(QUSRTVUS) PARM(&QRUS_NAME &QRUS_STRT +
                          &QRUS_LENG &QRUS_LINE &QERRCD)
             IF         COND(%SST(&QERRCD 5 4) *NE &NO_ERROR) +
                          THEN(GOTO CMDLBL(ERROR_API))

/* Get Spooled File Attributes */

             CHGVAR     VAR(&QGSA_IJOB) VALUE(%SST(&QRUS_LINE 51 16))
             CHGVAR     VAR(&QGSA_ISPL) VALUE(%SST(&QRUS_LINE 67 16))
             CHGVAR     VAR(%SST(&QERRCD 1 8)) +
                          VALUE(X'0000006000000000')
             CALL       PGM(QUSRSPLA) PARM(&QGSA_RCV &QGSA_RCVLN +
                          &QGSA_FOMT &QGSA_JOB &QGSA_IJOB +
                          &QGSA_ISPL &QGSA_SPLF &QGSA_SPLNB &QERRCD)
             IF         COND(%SST(&QERRCD 5 4) *NE &NO_ERROR) +
                          THEN(GOTO CMDLBL(ERROR_API))

             CHGVAR     VAR(&JOBNAME)   VALUE(%SST(&QGSA_RCV 49 10))
             CHGVAR     VAR(&FILE)      VALUE(%SST(&QGSA_RCV 75 10))
             CHGVAR     VAR(&USER)      VALUE(%SST(&QGSA_RCV 59 10))
             CHGVAR     VAR(&JOBNUMBER) VALUE(%SST(&QGSA_RCV 69 10))
             CHGVAR     VAR(&FILENR)     VALUE(%BIN(&QGSA_RCV 85 4))

/* Change Spooled Files attibutes */
/* Here we'll change the SAVE value to *NO */
/* and        move the SPLF to another output queue */
             CHGSPLFA   FILE(&FILE) JOB(&JOBNUMBER/&USER/&JOBNAME) +
                          SPLNBR(&FILENR) OUTQ(&OUTQL_TO/&OUTQ_TO) +
                          SAVE(*NO) USRDTA(&USRDTA)

/* Release Spooled Files which may be in HOLD status  */
             RLSSPLF    FILE(&FILE) JOB(&JOBNUMBER/&USER/&JOBNAME) +
                          SPLNBR(&FILENR)

/* File xxxx number yyy not released because not HELD */
             MONMSG     MSGID(CPF3322)

/* Read next Spooled File from User Space */

             GOTO       CMDLBL(LOOP_SPACE)


/* Delete Userspace  */

 END_SPACE:  CHGVAR     VAR(%SST(&QERRCD 1 8)) +
                          VALUE(X'0000006000000000')
             CALL       PGM(QUSDLTUS) PARM(&QDUS_NAME &QERRCD)
             IF         COND(%SST(&QERRCD 5 4) *NE &NO_ERROR) +
                          THEN(GOTO CMDLBL(ERROR_API))
/* JUMP */

             GOTO       CMDLBL(END)

/* API-Error */

 ERROR_API:  CHGVAR     VAR(&MSGID) VALUE(%SST(&QERRCD 9 7))
             CHGVAR     VAR(&MSGDTALN) VALUE(%BIN(&QERRCD 5 4))
             CHGVAR     VAR(&MSGDTALN) VALUE(&MSGDTALN - 16)
             CHGVAR     VAR(&MSGDTA) VALUE(%SST(&QERRCD 17 &MSGDTALN))
             SNDPGMMSG  MSGID(&MSGID) MSGF(QCPFMSG) MSGDTA(&MSGDTA) +
                          MSGTYPE(*DIAG)

/* Error */

 ERROR:      SNDPGMMSG  MSGID(CPF9899) MSGF(QCPFMSG) MSGTYPE(*ESCAPE)

/* Bye, bye */

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Ask your programming questions--or help out your peers by answering them--in our live discussion forums.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.

This was first published in April 2004

Dig deeper on iSeries CL programming

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchEnterpriseLinux

SearchDataCenter

Close