Host Variables in SQL Embbeded in Cobol

5 pts.
Tags:
I have this piece of code in SQLCBLLE source member:
       identification division.
       program-id. TST02.
       data division.
       working-storage section.

           Exec Sql
                Include SQLCA
           End-Exec.

       01  TR01-REC.
           COPY DDS-ALL-FORMATS OF TST1PF.

       01  TEST-REC.
           05 WS-FLD1    like FLD1.


       linkage section.
       procedure division.
      *...............................................................
       main.

           exec sql
               set :ws-fld1 = upper("teste")
           end-exec

           GoBack
           .
FLD1 is a field that exists on the file TST1PF.
The SQL Pre-compiler gives me error message:  
the variable WS-FLD1 is not usable or not defined. 
I have tried defining the file and the field inside of sql global declarations, but the behaviour is the same. 
What am i doing wrong? Thank you. 
System Version: V6R1M0.
 

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta

    The error is thrown by the SQL pre-compiler. The "pre-compiler" runs before the COBOL compiler runs. The LIKE clause for WS-FLD1 is not processed until the compiler runs, so WS-FLD1 is not available when the "pre-compiler" looks for a definition because no definition has been created yet.

    If you change your SQL SET statement to reference :FLD1 instead of :WS-FLD1, it should compile. The SQL precompiler can use the COPY statement to find FLD1, but it can't compile the definition for WS-FLD1.

    See the Character host variables in COBOL applications that use SQL topic in the Information Center. Note that the syntax diagram does not include LIKE as part of a valid field definition.

    You can always use COPY again to create a second definition in Working Storage if you don't want to use the original FLD1 definition.

    Tom

    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following