Handling SQL error codes in Cobol applications

Cobol applications can request more information about SQL error codes by using the DSNTIAR subroutine or issuing a GET DIAGNOSTICS statement.

Procedure

To request more information about SQL errors from Cobol programs, use the following approaches:

  • You can 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.
  • 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.
    DSNTIAR syntax
    DSNTIAR has the following syntax:
    CALL 'DSNTIAR' USING 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:
    01  ERROR-MESSAGE.
            02  ERROR-LEN   PIC S9(4)  COMP-5 VALUE +1320.
            02  ERROR-TEXT  PIC X(132) OCCURS 10 TIMES
                                       INDEXED BY ERROR-INDEX.
    77  ERROR-TEXT-LEN      PIC S9(9)  COMP-5 VALUE +132.
    ⋮
    CALL 'DSNTIAR' USING SQLCA ERROR-MESSAGE ERROR-TEXT-LEN.
    where ERROR-MESSAGE is the name of the message output area containing 10 lines of length 132 each, and ERROR-TEXT-LEN is the length of each line.
    lrecl
    A fullword containing the logical record length of output messages, in the range 72–240.

    An example of calling DSNTIAR from an application appears in the Db2 sample assembler program DSN8BC3, which is contained in the library DSN8C10.

  • If your CICS® application requires CICS storage handling, you must use the subroutine DSNTIAC instead of DSNTIAR.
    If you call DSNTIAR dynamically from a CICS COBOL application program, be sure you do the following:
    • Compile the COBOL application with the NODYNAM option.
    • Define DSNTIAR in the CSD.
    DSNTIAC syntax

    If your CICS application requires CICS storage handling, you must use the subroutine DSNTIAC instead of DSNTIAR. DSNTIAC has the following syntax:

    CALL 'DSNTIAC' USING 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.