Programming Languages on Power

Power Programming Languages

IBM Power, including the AIX, IBM i, and Linux operating systems, support a wide range of programming languages, catering to both traditional enterprise applications and modern development needs.


#Power

 View Only

SQLCODE -311 with VARCHAR and BOOLEAN in WHERE clause (since 7.5)

  • 1.  SQLCODE -311 with VARCHAR and BOOLEAN in WHERE clause (since 7.5)

    Posted Wed February 07, 2024 07:16 AM

    Hi,

    I have a strange case in an SQLRPGLE program. Here is my example code, to eventually reproduce this:
    **free
    ctl-opt actgrp(*new);

    dcl-s bBool ind inz(*on);
    dcl-s sVar varchar(100) inz('Hello');
    dcl-s nCount int(10) inz;

    prTest();
    prTest();

    *inlr = *on;
    return;

    dcl-proc prTest;
     exec sql select count(*)
              into :nCount
              from sysibm.sysdummy1
              where '   ' = :sVar and :bBool ;
     return;
    end-proc;
     
    When running/debugging the program, the SQLCODE is *ZERO after the first procedure call. 
     
    But after the second procedure call, the SQLCODE is -311, which means "Length in varying-length, LOB, or XML host variable not valid". 
     
    If I remove either the Boolean or the Varchar variable from the statement, it runs fine. Changing ":bBool" to ":bBool = '1'" or anything else doesn't help. 
     
    If I add the line
     
    sql_00004 = *blank;
     
    just before the EXEC SQL it runs also fine. This is the buffer before the VARCHAR field in the SQL host variables DS, that the Pre-Compiler defines. And the content of this "buffer" is the only thing that differs from call 1 to call 2. 
     
    But this shouldn't happen? Or should it? What am I doing wrong?
     
    From what I can see, it happens only, if the program was compiled on 7.5. If it was compiled on an earlier release, it seems to run fine on 7.5.
    TIA for every hint. 
    Daniel

    #SQL