ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

SQL0312 Error

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

  • SQL0312 Error

    Hi all

    i iva seen many discussion about the error SQL0312, but sincerely, i don't be able to undestand why i receive this error;

    if i compile a program with this instruction :
    ......

    D QCUSTCDT E DS Qualified Template
    D MainDs DS Qualified
    D CUSNUM_W Like(CUSNUM)
    D LSTNAM_W Like(LSTNAM)
    // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    .....

    ExEC SQL
    FETCH NEXT FROM mainCursor INTO :MAINDS;

    Dow SqlStt = '00000' and ySflNrrPag <=ySfl££SfPg;

    pri_ScanRek();

    ....

    receive the following error

    Position 48 Variable MAINDS not defined or not usable.



    If i change the field definition in the mainds in this way:

    D QCUSTCDT E DS Qualified Template
    D MainDs DS Qualified
    D CUSNUM_W 6S 0
    D LSTNAM_W 8

    i compile with no error SQL0312

    why happend this, and wich workaround if i want define my fields with like ??

    i have to use this code in v5r4 and v6r1



    thanks in adcance

  • #2
    Re: SQL0312 Error

    show us all the sql code leading up to this.
    Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

    Comment


    • #3
      Re: SQL0312 Error

      The SQL precompiler needs to be able to figure out the data type and length of your variable in order to move data into it properly. For some reason, it's unable to figure out what the type/length is -- and that's why it's issuing SQL0312.

      The SQL precompiler is not as smart as the RPG compiler, so it's sometimes unable to figure out the definition of avariable, even if the RPG compiler would have no trouble.

      The only advice I can give you is to try to figure out what's confusing SQL, and change it.

      Comment


      • #4
        Re: SQL0312 Error

        Are CUSNUM and LSTNAM by any chance display file fields? The SQL pre-compiler doesn't like display file fields (at v5r3 anyway) and therefore have to be explicitly defined.
        Regards

        Kit
        http://www.ecofitonline.com
        DeskfIT - ChangefIT - XrefIT
        ___________________________________
        There are only 3 kinds of people -
        Those that can count and those that can't.

        Comment

        Working...
        X