Example in ILE RPG: Accessing a field value (initial library list)

This program retrieves the library list from a job description. It expects errors to be returned via the error code parameter.

Note: Read the Code license and disclaimer information for important legal information.

Refer to Example in OPM RPG: Accessing a field value (initial library list) for the original example.

     D***************************************************************
     D***************************************************************
     D*
     D*  Program Name: JOBDAPI
     D*
     D*  Programming Language: ILE RPG
     D*
     D*  Description:  This program retrieves the library list from
     D*                a job description.  It expects errors to be
     D*                returned via the error code parameter.
     D*
     D*  Header Files Included: QUSEC - Error Code Parameter
     D*
     D*  Header Files Modified: QWDRJOBD - Retrieve Job Description API
     D*
     D***************************************************************
     D***************************************************************
     D*
     D* Error Code parameter include
     D*
     D/COPY QSYSINC/QRPGLESRC,QUSEC
     D*
     D* The following QWDRJOBD include from QSYSINC is copied into
     D* this program so that it can be declared as 1000 bytes in
     D* size.  This size should accommodate the variable length Library
     D* List array.
     D*
     D*** START HEADER FILE SPECIFICATIONS ****************************
     D*
     D*Header File Name: H/QWDRJOBD
     D*
     D*Descriptive Name: Retrieve Job Description Information API
     D*
     D*5763-SS1  (C) Copyright IBM Corp. 1994,1994
     D*All rights reserved.
     D*US Government Users Restricted Rights -
     D*Use, duplication or disclosure restricted
     D*by GSA ADP Schedule Contract with IBM Corp.
     D*
     D*Licensed Materials-Property of IBM
     D*
     D*
     D*Description: The Retrieve Job Description Information API
     D*          retrieves information from a job description
     D*          object and places it into a single variable in the
     D*          calling program.
     D*
     D*Header Files Included: None.
     D*
     D*Macros List: None.
     D*
     D*Structure List:  Qwd_JOBD0100_t
     D*
     D*Function Prototype List: QWDRJOBD
     D*
     D*Change Activity:
     D*
     D*CFD List:
     D*
     D*FLAG REASON       LEVEL DATE   PGMR      CHANGE DESCRIPTION
     D*---- ------------ ----- ------ --------- ----------------------
     D*$A0= D2862000     3D10  940424 ROCH:     New Include
     D*
     D*End CFD List.
     D*
     D*Additional notes about the Change Activity
     D*End Change Activity.
     D*** END HEADER FILE SPECIFICATIONS ******************************
     D*****************************************************************
     D*Prototype for QWDRJOBD API
     D*****************************************************************
     D QWDRJOBD        C                   'QWDRJOBD'
     D*****************************************************************
     D*Type Definition for the JOBD0100 format.
     D****                                                          ***
     D*NOTE: The following type definition defines only the fixed
     D*   portion of the format.  Any varying length field will
     D*   have to be defined by the user.
     D*****************************************************************
     DQWDD0100         DS          5000
     D*                                             Qwd JOBD0100
     D QWDBRTN                 1      4B 0
     D*                                             Bytes Returned
     D QWDBAVL                 5      8B 0
     D*                                             Bytes Available
     D QWDJDN                  9     18
     D*                                             Job Description Name
     D QWDJDLN                19     28
     D*                                             Job Description Lib Name
     D QWDUN                  29     38
     D*                                             User Name
     D QWDJD                  39     46
     D*                                             Job Date
     D QWDJS                  47     54
     D*                                             Job Switches
     D QWDJQN00               55     64
     D*                                             Job Queue Name
     D QWDJQLN00              65     74
     D*                                             Job Queue Lib Name
     D QWDJQP                 75     76
     D*                                             Job Queue Priority
     D QWDHJQ                 77     86
     D*                                             Hold Job Queue
     D QWDOQN                 87     96
     D*                                             Output Queue Name
     D QWDOQLN                97    106
     D*                                             Output Queue Lib Name
     D QWDOQP                107    108
     D*                                             Output Queue Priority
     D QWDPDN                109    118
     D*                                             Printer Device Name
     D QWDPT                 119    148
     D*                                             Print Text
     D QWDSCS                149    152B 0
     D*                                             Syntax Check Severity
     D QWDES                 153    156B 0
     D*                                             End Severity
     D QWDMLS                157    160B 0
     D*                                             Message Log Severity
     D QWDMLL                161    161
     D*                                             Message Log Level
     D QWDMLT                162    171
     D*                                             Message Log Text
     D QWDLCLP               172    181
     D*                                             Log CL Programs
     D QWDIMR                182    191
     D*                                             Inquiry Message Reply
     D QWDDRA                192    204
     D*                                             Device Recovery Action
     D QWDTSEP               205    214
     D*                                             Time Slice End Pool
     D QWDAC                 215    229
     D*                                             Accounting Code
     D QWDRD                 230    309
     D*                                             Routing Data
     D QWDTD                 310    359
     D*                                             Text Description
     D QWDERVED00            360    360
     D*                                             Reserved
     D QWDOILL               361    364B 0               (1)
     D*                                             Offset Initial Lib List
     D QWDNLILL              365    368B 0               (2)
     D*                                             Number Libs In Lib list
     D QWDORD                369    372B 0
     D*                                             Offset Request Data
     D QWDLRD                373    376B 0
     D*                                             Length Request Data
     D QWDJMQMS              377    380B 0
     D*                                             Job Message Queue Max Size
     D QWDJMQFA              381    390
     D*                                             Job Msg Queue Full Action
     D*QWDRSV2               391    391
     D*
     D*                             Varying length
     D*QWDILL                392    402    DIM(00001)
     D*
     D*                                 Varying length
     D*QWDRD00               403    403
     D*
     D*                             Varying length
     D*
     D* Command string data structure
     D*
     DCMD_STRING       DS
     D                               22    INZ('SNDMSG MSG(''LIBRARY - ')
     D LIBRARY                       10
     D                               15    INZ(''') TOUSR(QPGMR)')
     D*
     D* Miscellaneous data structure
     D*
     DRCVLEN           S              9B 0 INZ(%SIZE(QWDD0100))
     DFORMAT           S              8    INZ('JOBD0100')
     DLENSTR           S             15  5 INZ(%SIZE(CMD_STRING))
     C*
     C* Beginning of mainline
     C*
     C* Two parameters are being passed into this program
     C*
     C     *ENTRY        PLIST
     C                   PARM                    JOBD             10
     C                   PARM                    JOBD_LIB         10
     C*
     C* Move the two parameters passed into LFNAM
     C*
     C     JOBD          CAT       JOBD_LIB      LFNAM            20
     C*
     C* Error Code Bytes Provided is set to 16
     C*
     C                   EVAL      QUSBPRV = %SIZE(QUSEC)
     C*
     C* Call the API.
     C*
     C                   CALL      QWDRJOBD
     C                   PARM                    QWDD0100
     C                   PARM                    RCVLEN
     C                   PARM                    FORMAT
     C                   PARM                    LFNAM
     C                   PARM                    QUSEC
     C*
     C* Test for an error on the API call
     C*
     C                   IF        QUSBAVL > 0
     C*
     C* If there was an error, exit to ERROR subroutine
     C*
     C                   EXSR      ERROR
     C                   ELSE
     C*
     C* Else, add 1 to the Initial library list offset because RPG
     C* is a Base 1 language
     C*
     C     QWDOILL       ADD       1             X                 5 0
     C                   DO        QWDNLILL
     C                   EVAL      LIBRARY = %SUBST(QWDD0100:X:10)
     C*
     C* Let's tell everyone what the library value is
     C*
     C                   CALL      'QCMDEXC'
     C                   PARM                    CMD_STRING
     C                   PARM                    LENSTR
     C                   ADD       11            X
     C                   IF        (X + 10) > RCVLEN
     C                   LEAVE
     C                   ENDIF
     C                   ENDDO
     C                   ENDIF
     C*
     C                   EVAL      *INLR = '1'
     C                   RETURN
     C*
     C* End of MAINLINE
     C*
     C* Subroutine to handle errors returned in the error code parameter
     C*
     C     ERROR         BEGSR
     C*
     C* Process errors returned from the API.  As this sample program
     C* used /COPY to include the error code structure, only the first
     C* 16 bytes of the error code structure are available.  If the
     C* application program needed to access the variable length
     C* exception data for the error, the developer should physically
     C* copy the QSYSINC include and modify the copied include to
     C* define additional storage for the exception data.
     C*
     C                   ENDSR
Related reference
Example in OPM RPG: Accessing a field value (initial library list)