The following program prints out the name of the job description or prints an error if the API could not find the job description name specified.
The following is the RPG code used to access the HOLD attribute. This is the same type of program as the RPG program examples in Example in OPM RPG: Retrieving the HOLD parameter (exception message) and example in OPM RPG: Retrieving the HOLD parameter (error code structure). The program, named JOBDAPI, prints the value of HOLD if it is found, as shown at 1. If an error occurs, the program prints a line that contains the error message ID to a spooled file called QPRINT, as shown at 2.
F*****************************************************************
F*****************************************************************
F*
F*Program Name: JOBDAPI
F*
F*Language: OPM RPG
F*
F*Descriptive Name: Get Job Description
F*
F*Description: The following program prints out the name of
F* the job description or prints an error if the
F* API could not find the job description name
F* specified.
F*
F*
F*Header Files Included: QUSEC - Error Code Parameter
F* QWDRJOBD - Retrieve Job Description API
F*
F*****************************************************************
F*****************************************************************
F* JOBDAPIR - Print value of HOLD parameter using API
F* Uses error-code data structure
F*
FQPRINT O F 132 OF PRINTER
I*
I* Error Code Parameter Include for the APIs
I*
I/COPY QSYSINC/QRPGSRC,QUSEC
I*
I* Retrieve Job Description API Include
I*
I/COPY QSYSINC/QRPGSRC,QWDRJOBD
I*
I*
I* Dummy data structure used to declare binary field (3)
I*
I DS
I I 390 B 1 40RCVLEN
I I 'JOBD0100' 5 12FORMAT
C*
C* Beginning of Mainline
C*
C* Two parameters are being passed into this program.
C*
C *ENTRY PLIST Parm list
C PARM JOBD 10 Job descrp
C PARM JOBDL 10 Jobd library
C*
C* Move the two parameters passed into LFNAM.
C*
C JOBD CAT JOBDL LFNAM 20 Qlfd name
C*
C* Error code parameter is set to 16.
C*
C Z-ADD16 QUSBNB Bytes provid
C*
C* Instead of specifying 'QWCRJOBD', I could have used the
C* constant QWDBGB that was defined in the QWDRJOBD include.
C* Call the API
C*
C CALL 'QWDRJOBD' Parm list
C PARM QWDBH Receiver Var.
C PARM RCVLEN Length RCVVAR
C PARM FORMAT Format Name
C PARM LFNAM Qual. Job Desc
C PARM QUSBN Error Code
C* If no bytes available, API was successful; print HOLD value
C QUSBNC IFEQ 0
C EXCPTGOOD
C ENDIF
C* If some bytes available, API failed; print error message ID
C QUSBNC IFGT 0
C EXCPTBAD
C ENDIF
C* End of program
C SETON LR
C RETRN
C*
C* End of MAINLINE
C**********************************************************************
O*
OQPRINT E 106 GOOD
O 'HOLD value - '
O QWDBHN
OQPRINT E 106 BAD
O 'Failed. Error ID - '
O QUSBND
The following data structures are used:
This defines the two binary fields used and the message ID that is returned for error conditions.
This defines format JOBD0100, a 390-byte data structure with the hold field in positions 77-86.
This contains a field used for the length of the receiver variable. The field is defined as binary and is in the first 4 bytes. The dummy data structure, as shown at 3, also contains the format field.
This data structure is used because RPG only allows binary variables to be defined in the context of a data structure.
The program retrieves the parameter list that is passed and initializes the fields to be passed to the API. The API is called and places information into the receiver-variable data structure if information is found. The API places the information in the error-code data structure if an error occurred and if enough space was provided to receive the information.
The program prints one of two different lines depending on whether any errors were found:
HOLD value - *NO (1) Failed. Error ID - CPF9801 (2)
See the following for the same example in different languages: