Using the Error Code Parameter
The error code parameter provides a way for you to determine if the API encoun-
tered any errors.
The examples in this topic present a program used for creating a user space.
Using the Error Code Parameter—Example of Incorrect Coding
The common error shown in the following example is the use of the error code
structure to indicate to the API not to send exception messages for errors found.
Additionally, the example does not examine the error code structure to determine if
the API call was successful or not. To demonstrate the improper use of the error
code structure, an incorrect value is used on the replace parameter of the
QUSCRTUS API. The replace parameter is a required parameter. The coded
error (*XXXXXXX) is shown at location 2 in the incorrect and correct coding
(pages 9-3 and 9-4, respectively).
Both the incorrect and correct coding (1 on page 9-3 and 1 on page 9-3) show
the program monitoring for any error from the call to the API. However, the
program does not examine the bytes available field after calling the QUSCRTUS
API.
Because of the error on the replace parameter, the requested user space is not
created. The calling program, however, is not aware of this (shown at 3 on page
9-3).
ᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍᑍ
ᑍ
ᑍProgram Name: PGM1
ᑍ
ᑍProgram Language: RPG
ᑍ
ᑍDescription: This sample program illustrates the incorrect
ᑍ 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 'PAM ' 11 2 LIB
ᑍᑍ OTHER ASSORTED VARIABLES
I DS
I I 2 B 1 4SIZ
I B 5 8START
I I X'' 9 9 INTVAL
ᑍ
ᑍ Initialize the bytes provided field (QUSBNDB) of the error code
ᑍ structure. Languages such as RPG and CL tend to initialize the bytes
ᑍ provided field to blanks, which when passed to an API is viewed as a
ᑍ very large (and incorrect) binary value. If you receive CPF3CF1 when
9-2 System API Programming V4R1