IBM Support

COBOL/SQL CoProcessor does not detect a missing END-EXEC statement in the DATA DIVISION causing confusing compiler errors.

Troubleshooting


Problem

A program compilation shows many severe (-S) errors in the PROCEDURE DIVISION code for statements that appear to be coded correctly.

Symptom

The user sees many compiler messages such as


IGYDS1089-S "?" was invalid. Scanning was resumed at the next area "A" item, level-number, or the start of the next clause.


These errors are seen on COBOL verbs in the PROCEDURE DIVISION such as "MOVE" and "ADD".

Cause

The user had coded an EXEC SQL DECLARE ... CURSOR ... statement that was missing the END-EXEC. near the end of the DATA DIVISION of his program.
Many of the statements in his PROCEDURE DIVISION were flagged as invalid syntax with IGYDSnnnn messages which usually describe errors in the DATA DIVISION. The DS in the IGYDSnnnn-S messages indicates that they are data related messages.

Environment

DB2

Diagnosing The Problem

Run the DB2 PreProcessor to see if there are any additional messages produced.
When the DB2 PreProcessor was used, the same program produced this error message:
DB2 SQL PRECOMPILER MESSAGES
DSNH004I S DSNHLEXC PROCEDURE DIVISION COULD NOT BE FOUND.
but there was nothing similar in the CoProcessor listing.

Resolving The Problem

Add an END-EXEC. to terminate each EXEC SQL statement. Don't forget the period after the END-EXEC.

************************

Here is an explanation of what happened in this case.

When the CoProcessor found an EXEC SQL statement, it went into SQL mode and collected information to pass through to the DB2 interface for processing. This continued until an END-EXEC. terminator was found.

While in an EXEC SQL statement COBOL syntax and rules were not checked. The user may code what are normally COBOL reserved words and numeric sequences that have a different meaning for DB2, so there is very little COBOL evaluation of the contents.

In the case described, the next valid END-EXEC found was in the PROCEDURE DIVISION, so the PROCEDURE DIVISION statement itself was considered to be within the EXEC SQL statement and the compiler did not recognize it as a COBOL language statement.

The errors about the other statements were because the compiler was still processing the DATA DIVISION.

In this case, no PROCEDURE DIVISION code was generated. The Enterprise COBOL compiler did not flag the program with a missing PROCEDURE DIVISION statement because COBOL does not require one. It is possible to create a program with just a DATA DIVISION or an error message list with just PROGRAM-ID. ERRMSG.

[{"Product":{"code":"SS6SG3","label":"Enterprise COBOL for z\/OS"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":"Compile","Platform":[{"code":"PF035","label":"z\/OS"}],"Version":"3.4;4.1;4.2","Edition":"","Line of Business":{"code":"LOB17","label":"Mainframe TPS"}}]

Document Information

Modified date:
08 August 2018

UID

swg21302809