Defining List Entry Format Lengths
The example programs in this topic show how to code flexibility into your program
as it works its way through the formats used by an API.
Defining List Entry Format Lengths—Example of Incorrect Coding
A common error, or trap, when working with list entry format lengths is to hard code
the format length into your program. The format length is used by the program to
advance to the next list entry in the user space. From release to release, the
length of the format may change. Therefore, when the format length changes, your
program can be susceptible to being pointed to an incorrect position in the user
space and nonsense data placed in the receiver variable.
The program has the length of the list entry format hard coded. This is shown at
.1ð/ on page 9-16. If your program runs on a Version 2 Release 2 system, that
value would work. However, with Version 2 Release 3, the format size increased
from 52 to 56 bytes. The correct coding is shown at .11/ on page 9-17.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\
\Program Name: PGM1
\
\Program Language: RPG
\
\Description: This sample program illustrates the incorrect
\ way of using list entry length formats.
\
\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.
\ THE FIRST JOB NAME/USER WILL BE DISPLAYED TO THE USER.
I/COPY QSYSINC/QRPGSRC,QUSGEN
I/COPY QSYSINC/QRPGSRC,QUSLJOB
\
\ BRING IN THE ERROR STRUCTURE FROM QSYSINC
I/COPY QSYSINC/QRPGSRC,QUSEC
\
\\ 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
\ FORMAT JOBLð1ðð FOR QUSLJOB API
\
\\ DATA STRUCTURE CONTAINING SPACE NAME/LIB
ISPCNAM DS
9-14 System API Programming V4R1