Reputation: 23
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.
Upvotes: 1
Views: 408
Reputation: 734
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.
Upvotes: 1
Reputation: 932
If you want to deal with the value without leading blanks, you can use %trim
or %trimL
. The former will trim spaces from the front and end. The latter will only trim spaces from the front (left).
newOrder = %trimL( originalOrder );
Although your example is a bit odd. Either you typo'd what you want (two 3's?) or if you really do want to insert a 3, then that would require more work. Let me know.
Edit: Maybe this logic better answers what you're looking to do.
To count the number of non-blanks, you can do this:
valueCount = %len( %trim( originalOrder ) );
And if you need to know the number of blanks instead, it's simply:
blankCount = %len( originalOrder ) - %len( %trim( originalOrder ) );
I hope that answers your question.
Upvotes: 1