DESCRIBE OUTPUT

The DESCRIBE OUTPUT statement obtains information about a prepared statement.

Invocation

This statement can be embedded only in a COBOL application program. It is an executable statement that can be dynamically prepared.

Syntax

Read syntax diagramSkip visual syntax diagramDESCRIBEOUTPUTstatement-name INTOdescriptor-name

Description

The following keyword parameters are defined for the DESCRIBE OUTPUT statement:
OUTPUT
When a statement-name is specified, optional keyword to indicate that the describe will return information about the select list columns in the prepared SELECT statement.
statement-name
Identifies the prepared statement. When the DESCRIBE statement is executed, the name must identify a statement that has been prepared.
INTO descriptor-name
Identifies an SQL descriptor area (SQLIMSDA), which is described in SQL descriptor area (SQLIMSDA). Use the INCLUDE SQLIMSDA statement to declare the SQLIMSDA in the application.

After the DESCRIBE statement is executed, all the fields in the SQLIMSDA except SQLN are either set by IMS or ignored.

Example

Execute a DESCRIBE statement with the included SQLIMSDA. After DESCRIBE, SQLIMSD specifies the number of result fields returned. IF SQLIMSD equals 0, the statement is a non-SELECT statement such as INSERT, UPDATE, or DELTEE. If SQLIMSD is greater than zero, the statement is a SELECT statement and allocates storage for each result field and specify its address to the SQLIMSDATA field in the SQLIMSDA. Finally, FETCH the result dataset into the SQLIMSDA.

EXEC SQLIMS                               
   INCLUDE SQLIMSDA
END-EXEC

EXEC SQLIMS                         
  DECLARE C1 CURSOR FOR DYSQL 
END-EXEC.                        

EXEC SQLIMS                               
   PREPARE DYSQL FROM :SELECT-STATEMENT   
END-EXEC           

EXEC SQLIMS                               
   DESCRIBE DYSQL INTO :SQLIMSDA
END-EXEC 

IF SQLIMSD > 0 
   EXEC SQLIMS OPEN C1 END-EXEC.
   .... /* Code to allocate the storage for each result field */
   .... /* Set the storage address to each SQLIMSDATA variable */
   EXEC SQLIMS FETCH C1 INTO :SQLIMSDA END-EXEC.
 
   IF SQLIMSCODE = 100
      PERFORM DATA-NOT-FOUND
   ELSE
      PERFORM GET-REST-OF-HOSP
      UNTIL SQLIMSCODE IS NOT EQUAL TO ZERO.
 
   EXEC SQLIMS CLOSE C1 END-EXEC.