ᑍ calling an API, the bytes provided field should be the first field
ᑍ you examine as part of problem determination.
C Z-ADD16 QUSBNB 1
ᑍ
ᑍ CREATE THE SPACE TO HOLD THE DATA
C CALL 'QUSCRTUS'
C PARM SPCNAM
C PARM 'EXT_ATTR'EXTATR 1
C PARM SIZ
C PARM INTVAL
C PARM 'ᑍALL 'PUBAUT 1
C PARM 'NO TEXT 'TXTDSC 5
C PARM 'ᑍXXXXXXX'REPLAC 1 2
C PARM QUSBN
ᑍᑍ Program does not check the error code parameter 3
ᑍᑍ
C SETON LR
Using the Error Code Parameter—Example of Correct Coding
You can add code to help you discover what errors may be in a program. In the
following example program, code has been added to monitor error information
passed back in the error code parameter (QUSBN). This code is shown at 4 on
page 9-4. The code at 4 has been added to check the error code parameter for
any messages and to display the exception identifier to the user if any errors are
found. The incorrectly coded program does no checking for the error code param-
eter (shown at 3 on page 9-3).
ᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍ
ᑍ
ᑍProgram Name: PGM2
ᑍ
ᑍProgram Language: RPG
ᑍ
ᑍDescription: This sample program illustrates the correct
ᑍ way of using the error code parameter.
ᑍ
ᑍHeader Files Included: QUSEC - Error Code Parameter
ᑍ
ᑍAPIs Used: QUSCRTUS - Create User Space
ᑍ
ᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍ
ᑍ BRING IN THE ERROR STRUCTURE FROM QSYSINC
I/COPY QSYSINC/QRPGSRC,QUSEC
ᑍᑍ
ISPCNAM DS
I I 'SPCNAME ' 1 1 SPC
I I 'QTEMP ' 11 2 LIB
ᑍᑍ OTHER ASSORTED VARIABLES
I DS
I I 2 B 1 4SIZ
I B 5 8START
I I X'' 9 9 INTVAL
ᑍ
C Z-ADD16 QUSBNB 1
ᑍ
Chapter 9. Common API Programming Errors 9-3