InfoSphere Optim

 View Only
  • 1.  LUA and empty strings

    Posted Mon February 04, 2019 02:38 AM
    Hi,

    Does anyone have experience with LUA and empty strings?
    How to check if a string is empty?
    "string.len" returns 25 for an empty varchar(25) column...

    Thanks,
    Fritz

    ------------------------------
    FRIEDRICH PFNEISL
    Optim SME
    Austria
    ------------------------------

    #InfoSphereOptim
    #Optim


  • 2.  RE: LUA and empty strings

    Posted Mon February 04, 2019 04:25 PM
    ​Hi,

    Which platform?

    ------------------------------
    Greg Czaja
    Optim for z/OS Development
    Unicom Systems Inc.
    ------------------------------



  • 3.  RE: LUA and empty strings

    Posted Tue February 05, 2019 10:57 AM
    I suggest you open a PMR with the Optim Distributed support team. I recall having to adjust the respective ​code for zero length string handling.
    On z/OS, one gets 0 length, as expected: Value: >< length: 0 using
    1 value = optim.source.getcolumnvalue()                           
    2 print ('Value: >' .. value .. '< length: ' .. string.len(value))

    ------------------------------
    Greg Czaja
    Optim for z/OS Development
    Unicom Systems Inc.
    ------------------------------



  • 4.  RE: LUA and empty strings

    Posted Wed February 06, 2019 03:29 PM
    Try comparing it to Nil.  This has worked for me.

    Ex.  If variable == Nil then
                 do something
            Else
                 do nothing
             End

    ------------------------------
    Trong Bo Senior Environment Administrator
    ------------------------------



  • 5.  RE: LUA and empty strings

    Posted Thu February 07, 2019 03:15 AM
    Hi, 

    the problem we had when comparing a blank string is that if you look at the string and the data type is varchar 12, you get the value left oriented and filled out with blank to the left.
    (
    We run DB2 for iSeries through federation server)

    if you run  a string.len on a "blank" string you get 12 in this case (12 blank characters)

    I solved the problem by creating this funktion and using regex to validate the string:
    (Checking if the string starts with one or more blanks)
    function isBlank(x)
       return tostring(x):find("^%s+$")
    end

    and use it like:
     if (isBlank(srcvalue))then
       target.column.setvalue(source.column.getvalue())
    else
       target.column.setvalue(newvalue)
    end

    Best regards, 
    Per

    ------------------------------
    Per Wallqvist
    ------------------------------