Problem with LIKE in cursor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MarcinD
    New Member
    • Feb 2008
    • 2

    #1

    Problem with LIKE in cursor

    Hi all,

    DB2 on AS/390. I read from table using cursor:

    DECLARE SAMPLCUR1 CURSOR
    WITH ROWSET POSITIONING FOR
    SELECT
    COL1, COL2, COL3
    FROM TABLENAME
    WHERE
    COL4 LIKE :WS-SOMEVAR
    FOR FETCH ONLY
    WITH UR

    and from this I get e.g. 10 rows at once. Problem is, that LIKE in statement above doesn't work, when WS-SOMEVAR contain an SPACE e.g. WS-SOMEVAR = 'SANTA C%'. It works fine if WS-SOMEVAR = 'SANTA%'.
    I've tried to replace all existing SPACES to underline '_' and set WS-SOMEVAR = 'SANTA_C%' but it still doesn't work.
    By 'doesn't work' I mean that it returns zero records (SQLCODE = +100).

    I checked this SELECT query in Spufi and there all cases work fine.

    Is there an trick to force normal working of that query in cobol program ? or maybe can anyone suppose what is the reason ?


    Thx for your help

    Marcin Domaslawski
  • MarcinD
    New Member
    • Feb 2008
    • 2

    #2
    OK I've found solution.

    For others with same problem:
    when e.g. WS-VAR is PIC X(20) and we pass 'SANTA C%' (8 characters) - rest of the variable's buffer should be filled by '%'

    Marcin Domaslawski

    Comment

    Working...