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
ᑍ
ᑍᑍ JOBL1 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