Handling SQL error codes in PL/I applications
PL/I applications can request more information about SQL error codes by using the DSNTIAR subroutine or issuing a GET DIAGNOSTICS statement.
Procedure
To request information about SQL errors in PL/I programs, use the following approaches:
- You can use the subroutine DSNTIAR to convert an SQL return code into a text message. DSNTIAR takes data from the SQLCA, formats it into a message, and places the result in a message output area that you provide in your application program. For concepts and more information on the behavior of DSNTIAR, see Displaying SQLCA fields by calling DSNTIAR.
- DSNTIAR syntax
-
CALL DSNTIAR ( sqlca, message, lrecl );
- DSNTIAR parameters
- The DSNTIAR parameters have the following meanings:
- sqlca
- An SQL communication area.
- message
- An output area, in VARCHAR format, in which DSNTIAR places the message text. The first halfword contains the length of the remaining area; its minimum value is 240. The output lines of text, each line being the length specified in lrecl, are put into this area. For example, you could specify the format of the output area as:
where ERROR_MESSAGE is the name of the message output area, DATA_DIM is the number of lines in the message output area, and DATA_LEN is the length of each line.DCL DATA_LEN FIXED BIN(31) INIT(132); DCL DATA_DIM FIXED BIN(31) INIT(10); DCL 1 ERROR_MESSAGE AUTOMATIC, 3 ERROR_LEN FIXED BIN(15) UNAL INIT((DATA_LEN*DATA_DIM)), 3 ERROR_TEXT(DATA_DIM) CHAR(DATA_LEN); ⋮ CALL DSNTIAR ( SQLCA, ERROR_MESSAGE, DATA_LEN );
- lrecl
- A fullword containing the logical record length of output messages, in the range 72–240.
Because DSNTIAR is an assembler language program, you must include the following directives in your PL/I application:DCL DSNTIAR ENTRY OPTIONS (ASM,INTER,RETCODE);
An example of calling DSNTIAR from an application appears in the Db2 sample assembler program DSN8BP3, contained in the library DSN8D10.SDSNSAMP. See Sample applications supplied with Db2 for z/OS for instructions on how to access and print the source code for the sample program. - If your CICS application requires CICS storage handling, you must use the subroutine DSNTIAC instead of DSNTIAR.
- DSNTIAC syntax
- DSNTIAC has the following syntax:
CALL DSNTIAC (eib, commarea, sqlca, msg, lrecl);
- DSNTIAC parameters
-
DSNTIAC has extra parameters, which you must use for calls to routines that use CICS commands.
- eib
- EXEC interface block
- commarea
- communication area
For more information on these parameters, see the appropriate application programming guide for CICS. The remaining parameter descriptions are the same as those for DSNTIAR. Both DSNTIAC and DSNTIAR format the SQLCA in the same way.
You must define DSNTIA1 in the CSD. If you load DSNTIAR or DSNTIAC, you must also define them in the CSD. For an example of CSD entry generation statements for use with DSNTIAC, see job DSNTEJ5A.
The assembler source code for DSNTIAC and job DSNTEJ5A, which assembles and link-edits DSNTIAC, are in the data set prefix.SDSNSAMP.
- You can also use the MESSAGE_TEXT condition item field of the GET DIAGNOSTICS statement to convert an SQL return code into a text message. Programs that require long token message support should code the GET DIAGNOSTICS statement instead of DSNTIAR. For more information about GET DIAGNOSTICS, see Checking the execution of SQL statements by using the GET DIAGNOSTICS statement.