Search code examples
db2-400rpgle

How to parse data in RPG


I have an order number which is character 10 positions.

I would like to know where the leading blanks end. Only blanks. So if the number is

' 012345' I want 012345 - Can I do this in RPG? I have tried some FREE codes but have trouble getting to work in general. So I prefer the old way or Free is ok if we must.

So what i need to know is, how many positions of the 10 position field are having data? so if the data is 012345 this means 6 positions are filled and 4 are blanks.


Solution

  • Use %scan to locate the blank.

    dcl-s source char(10) inz('12345');
    dcl-s pos zoned(5);
    
    pos = %scan(' ':source) - 1;
    *inlr = *on;
    

    After the eval pos = 5.