Home > AS/400 Tips > iSeries programmer tips > Use APIs to produce all SPLF from a specific OUTQ
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Use APIs to produce all SPLF from a specific OUTQ


Jean-Marie SAUVAGEOT
04.12.2004
Rating: -4.20- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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



Code

    
/*'=================================================================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.


Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
iSeries CL programming
Taking advantage of CL advancements, starting with V5R3
Checking in on your IBM i authorization lists
Running PHP open source applications: NOBODY needs authority
Simplify the process of converting a spool file from iSeries into an Excel spreadsheet
CL program for daily backups
An automated CL method of moving a query from AS/400 to Excel
Changing user password expiration
Eight steps for creating program documentation using AS/400 utilities
DAYSPAST CLLE program for AS/400: Compares object creation date with today's date
Advanced Job Scheduler help

RPG iSeries programming
Enhancing RPG with external SQL stored procedures
Introduction to SQLRPGLE on IBM i: Making a report
Making the most of RPG data handling on IBM i
IBM i shop boosts online sales with RPG-based Web platform
Migrating from RPG to EGL on IBM i
Allow access to data from a stored procedure result set using COBOL or RPG
EGL Rich UI on IBM i: Do you Dojo?
Programming for the Web on the IBM i, what is possible
A taste of COMMON: ILE, IBM releases, Web applications and new products
Documenting nested program structures on the AS/400

Application Development
iSeries calling an .exe
Top 10 programmer tips
Formatted work job scheduler
Convert system date and time
Mixing free format code with embedded SQL
SQL update a field in one file from a field in another file
Webcasts for iSeries programmers
Programming advice from the pros
Easy code copying via the drag and drop method
Setting FTP time-outs

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Report Program Generator  (Search400.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts