As discussed in Chapter 3, “Communicating with Adaptive Server,” the precompiler automatically sets the system variables when you include SQLCA, SQLCODE, or SQLSTATE in the application program. However, you must explicitly declare host and indicator variables in a declare section before using them in Embedded SQL statements.
WARNING! The precompiler generates some variables, all of which begin with “SQL--”. Do not begin your variables with “SQL,” or you may receive an error message or unreliable data.
You cannot use COPY statements in a declare section. The syntax for a declare section is:
exec sql begin declare section end-exec
declarations ...
exec sql end declare section end-exec.
Host variable declarations must conform to the COBOL rules for data declarations. You need not declare all variables in one declare section, since you can have an unlimited number of declare sections in a program.
Version 11.1 and later does not support updates to the
PIC clause.
When declaring variables, you must also specify the picture and usage clauses. For valid picture and usage clauses, see the section “Comparing COBOL and Adaptive Server datatypes”
The following example shows a sample declare section:
exec sql begin declare section end-exec
01 E-NAME PIC X(30).
01 E-TYPE PIC X(3).
01 TINY-INT PIC S9(2) COMP.
01 SHORT-INT PIC S9(4) COMP.
01 MONEY-DATA CS-MONEY.
exec sql end declare section end-exec.