ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Column or global variable not found

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Column or global variable not found

    Hi, I'm new to "modern" RPG, and trying to learn.

    I have some code giving the error "Column or global variable VARXYZSav not found.

    In my code, I thought I defined it properly:

    dcl-s VARXYZSav zoned(5 : 0);

    But getting the error here:

    exec sql
    set VARXYZSav = :VARXYZ;

    SQL0206 Position 18 Column or global variable VARXYZSav not found.

    ==== I also get the error Here with a different field. Trying to update a column in a table from another column in the same table

    exec sql
    UPDATE TABLEA
    SET Field1# = Field2
    SQL0206 Position 18 Column or global variable Field2 not found.
    WHERE ........

    Thanks in advance





  • #2
    I'm not good enough at SQL to provide a correct statement. But I do know that you appear to have got it backwards. The colon indicates a host variable i.e. a variable in the program. So you can reference :VARXYZSav but unless VARXYZ is also declared in the RPG you cannot reference it with the colon.

    Can't comment on the second one because you haven't supplied the whole SQL so I have no way of seeing where the variable is specified.

    Comment


    • #3
      Is Field2 in the update an RPG variable? If so, it would need the colon. If not, like Jon said we'd need to see the rest of the statement.

      Comment


      • #4
        Originally posted by MFisher View Post
        Hi, I'm new to "modern" RPG, and trying to learn.

        I have some code giving the error "Column or global variable VARXYZSav not found.

        In my code, I thought I defined it properly:

        dcl-s VARXYZSav zoned(5 : 0);

        But getting the error here:

        exec sql
        set VARXYZSav = :VARXYZ;

        SQL0206 Position 18 Column or global variable VARXYZSav not found.

        ==== I also get the error Here with a different field. Trying to update a column in a table from another column in the same table

        exec sql
        UPDATE TABLEA
        SET Field1# = Field2
        SQL0206 Position 18 Column or global variable Field2 not found.
        WHERE ........

        Thanks in advance



        On your your exec sql set VARXYZSav = :VARXYZ; command - what are you trying to accomplish? Are you trying to assign RPG variable VARXYZ to an RPG variable XARXYZSav? If so - you don't need the EXEC sql for that ...
        Code:
        VARXYZSav = VARXYZ;
        On the latter - field2 must not be in your table.

        Comment


        • #5
          You missed the colon before VARXYZSav!
          Code:
          exec sql
          set [COLOR=#FF0000][B]:[/B][/COLOR]VARXYZSav = :VARXYZ;
          ... but why you want to do this kind of statement with an SQL Set statement instead of just using RPG, i.e. VARXYZSav = VARXYZ?

          Code:
          exec sql
          UPDATE TABLEA
          SET Field1# =[COLOR=#FF0000][B] :[/B][/COLOR]Field2
          SQL0206 Position 18 Column or global variable Field2 not found.
          WHERE ........

          Comment

          Working...
          X