Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 22 Coding SQL Access Statements : Coding SQL Access Statements

Coding SQL Access Statements
Code the SQL access statements within the Working Storage Section and Procedure Division of your COBOL program. All SQL statements must be preceded by:
Exec Sql
and followed by:
End-Exec
Initial Statement
The first SQL statement in the Working Storage Section must be one of:
Exec Sql
Include Sqlca
End-Exec
or
Exec Sql Begin Declare Section End-Exec
Exec Sql
   01 Sqlstate Pic x(5).
   01 Sqlcode Pic 59 Comp.End-Exec
Exec Sql End Declare Section End-Exec.
The Sqlcode declaration can be used in addition to, or in place of, the Sqlstate declaration. This is the method of error handling and error reporting through the SQL Communications Area (SQLCA), and the status variables Sqlstate and Sqlcode.
Defining Valid Names
If table, parameter, or field names are invalid for COBOL, define valid names. This example defines the TDS table #ED_EMPLOYEES and assigns a valid COBOL name (MGRNO) to a TIBCO Object Service Broker field (MGR#):
Exec Sql
Define Employee Table = #ED_EMPLOYEES
Field mgrno = MGR#,
Refer to Coding Considerations for information about assigning COBOL names to TIBCO Object Service Broker objects.
Specifying Selection
Declare cursors to make selections from tables. Use standard SQL syntax and TIBCO Object Service Broker names:
Exec Sql
Declare Cursa Cursor For
Select EMPNO, LNAME, MGR#
From #ED_EMPLOYEES('EDUC',LOCATION77) where
MGR#= 84021
End-Exec
Specifying Data Areas
Specify data areas to receive data from TIBCO Object Service Broker:
01 COB-EMPNO PIC 9(7).
01 LAST-NAME PIC X(22).
01 MANAGER PIC 9(7).
Refer to Syntax Mapping for conversions from TIBCO Object Service Broker syntax to COBOL declarations.
Coding the Remaining SQL Statements
Code the remaining SQL statements as usual, such as FETCH CURSOR:
Exec Sql
Fetch Cursa into :cob-EMPNO, :last-name, :manager
End-Exec
 
Close each cursor before using another cursor on the same table. You can use CLOSE CURSOR to close specific cursors. All cursors are closed by COMMIT and ROLLBACK statements.

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved