Differences in how the Db2 precompiler and coprocessor behave
The sections that follow enumerate the differences in behavior between the stand-alone COBOL Db2® precompiler and the integrated COBOL Db2 coprocessor.
For details about the CCSID determination under the Db2 precompiler and coprocessor, see COBOL and Db2 CCSID determination.
Period at the end of EXEC SQL INCLUDE statements
Precompiler: The Db2 precompiler does
not require that a period end each EXEC SQL INCLUDE
statement. If a period is
specified, the precompiler processes it as part of the statement. If a period is not specified, the
precompiler accepts the statement as if a period had been specified.
Coprocessor: The Db2 coprocessor
treats each EXEC SQL INCLUDE
statement like a COPY
statement, and
requires that a period end the statement. For example:
IF A = B THEN
EXEC SQL INCLUDE some_code_here END-EXEC.
ELSE
. . .
END-IF
Note that the period does not terminate the IF
statement.
EXEC SQL and REPLACE or COPY REPLACING
Precompiler: With the Db2
precompiler, COBOL REPLACE
statements and the REPLACING
phrase of
the COPY
statement act on the expanded source created from the EXEC
SQL
statement. COBOL rules for REPLACE
and REPLACING
are
used.
Coprocessor: With the Db2
coprocessor, REPLACE
and COPY . . . REPLACING
statements act on
the original source program, including EXEC SQL
statements.
Different behavior can result, as in the following example:
REPLACE == ABC == By == XYZ ==.
01 G.
02 ABC PIC X(10).
. . .
EXEC SQL SELECT * INTO :G.ABC FROM TABLE1 END-EXEC
With the precompiler, the reference to G.ABC
will appear as ABC of
G
in the expanded source and will be replaced with XYZ of G
. With the
coprocessor, replacement will not occur, because ABC
is not delimited by separators
in the original source string G.ABC
.
Source code after an END-EXEC statement
Precompiler: The Db2 precompiler
ignores any code that follows END-EXEC
statements on the same line.
Coprocessor: The Db2 coprocessor
processes code that follows END-EXEC
statements on the same line.
Multiple definitions of host variables
Precompiler: The Db2 precompiler does not require that host variable references be unique. The first definition that maps to a valid Db2 data type is used.
Coprocessor: The Db2 coprocessor requires that each host variable reference be unique. The coprocessor diagnoses nonunique references to host variables. You must fully qualify host variable references to make them unique or use the QUALIFY compiler option.
EXEC SQL statement continuation lines
Precompiler: The Db2 precompiler
requires that EXEC SQL
statements start in columns 12 through 72. Continuation
lines of the statements can start anywhere in columns 8 through 72.
Coprocessor: The Db2 coprocessor
requires that all lines of an EXEC SQL
statement, including continuation lines, be
coded in columns 12 through 72.
Bit-data host variables
Precompiler: With the Db2
precompiler, a COBOL alphanumeric data item can be used as a host variable to hold Db2 character data that has subtype FOR
BIT DATA
. An explicit EXEC SQL DECLARE VARIABLE
statement that declares
that host variable as FOR BIT DATA
is not required.
Coprocessor: With the Db2
coprocessor, a COBOL alphanumeric data item can be used as a host variable to hold Db2 character data that has subtype FOR
BIT DATA
if an explicit EXEC SQL DECLARE VARIABLE
statement for that host
variable is specified in the COBOL program. For example:
EXEC SQL DECLARE :HV1 VARIABLE FOR BIT DATA END-EXEC.
As an alternative to adding EXEC SQL DECLARE . . . FOR BIT DATA
statements, you can use the NOSQLCCSID
compiler option. For details, see the
related reference about code-page determination below.
SQL-INIT-FLAG
Precompiler: With the Db2
precompiler, if you pass host variables that might be located at different addresses when the
program is called more than once, the called program must reset SQL-INIT-FLAG
.
Resetting this flag indicates to Db2 that
storage must be initialized when the next SQL statement runs. To reset the flag, insert the
statement MOVE ZERO TO SQL-INIT-FLAG
in the PROCEDURE DIVISION
of
the called program ahead of any executable SQL statements that use those host variables.
Coprocessor: With the Db2
coprocessor, the called program does not need to reset SQL-INIT-FLAG
. An
SQL-INIT-FLAG
is automatically defined in the program to aid program portability.
However, statements that modify SQL-INIT-FLAG
, such as MOVE ZERO TO
SQL-INIT-FLAG
, have no effect on the SQL processing in the program.
SQL host variable containing FILLER data items
Precompiler: With the Db2 precompiler, an SQL host variable containing FILLER data items is not flagged with an error message.
IGYPS0294-S SQL host variable reference "data-item" was defined with a contained "FILLER"
data item, which is not valid for an SQL host variable. The statement was discarded.
For reference, see Host structures in COBOL in Programming for Db2 for z/OS.