Defining Receiver Variables
When defining receiver variables, the most common error is to create them too
small for the amount of data that they are to receive. Both example programs are
coded in RPG and, when run, lists all active jobs on the system.
Defining Receiver Variables—Example of Incorrect Coding
The following example program will fail because the receiver variable has been
defined as 50 bytes (shown at .7/ on page 9-11), but 60 bytes are being requested
to be passed back from the API (shown at .8/ in the incorrect and correct pro-
grams on pages 9-11 and 9-13, respectively). The correct coding is shown at .9/
on page 9-13.
When this happens, other variables are overwritten with unintended data. This
causes the other variables to be incorrect. For example, the first 10 characters of
QUSBN may be written over with these extra characters. On the call to the next
API, the error code parameter may appear to contain meaningless characters that
would cause the next call to an API to fail.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\
\Program Name: PGM1
\
\Program Language: RPG
\
\Description: This sample program illustrates the incorrect
\ way of defining receiver variables.
\
\Header Files Included: QUSEC - Error Code Parameter
\ QUSLJOB - List Job API
\ QUSGEN - User Space Format for Generic Header
\
\APIs Used: QUSCRTUS - Create User Space
\ QUSLJOB - List Job
\ QUSRTVUS - Retrieve User Space
\ QUSDLTUS - Delete User Space
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ THIS PROGRAM WILL CREATE THE NECESSARY SPACE AND THEN CALL
\ THE QUSLJOB API TO GET A LIST OF ALL ACTIVE JOBS ON THE SYSTEM.
\ BRING IN THE GENERIC USER SPACE HEADER FROM QSYSINC
I/COPY QSYSINC/QRPGSRC,QUSGEN
\
\ BRING IN THE ERROR STRUCTURE FROM QSYSINC
I/COPY QSYSINC/QRPGSRC,QUSEC
\
\\ JOBLð1ðð FORMAT RETURNED FROM QUSLJOB API
I/COPY QSYSINC/QRPGSRC,QUSLJOB
\
\\ JOB NAME STRUCTURE FOR CALLING QUSLJOB
IJOBNAM DS
I I '\ALL ' 1 1ð JOB
I I '\ALL ' 11 2ð USER
I I '\ALL' 21 26 JOBNUM
ISPCNAM DS
I I 'SPCNAME ' 1 1ð SPC
I I 'QTEMP ' 11 2ð LIB
9-10 System API Programming V4R1