Skip to main content

Problem:

A Cobol program contains the following EXEC SQL PREPARE statement

        MOVE 'SELECT TEMP_CODE,TEMP_NAME     

-      ' FROM TEMP' TO  WS-SQL.            

        EXEC SQL                             

               PREPARE DY1 FROM :WS-SQL      

        END-EXEC.            

The host variable is defined as

01   WS-SQL      PIC X(80).

When compiled, the program compiles without errors, but when run the program returns an SQLCODE of -84.

               

Resolution:

To identify the problem, simply compile the program with MESSAGE LEVEL set to WARNINGS.

There are no syntax problems with the PREPARE statement.

The issue is in the way that the host variable, WS-SQL, is defined.

The correct definition should be a VARCHAR definition.  

So in Cobol it would be...

01  WS-SQL.                          

    49 WS-SQL-LEN       PIC S9(4) COMP.

    49 WS-SQL-TEXT     PIC X(80).     

This will correct the problem and the statement will return the correct value in WS-SQL and an SQLCODE of  000.

Old KB# 2404

#EnterpriseDeveloper
#MFDS