Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
DTxt s 1024 inz
DTxtOut s 15 inz
TxtOut = %subst(%TrimL(Txt):1:15);
return;
The test program fails on the %subst operation.
RNX0100- Length or start position is out of range for the string operation.
I've never seen this before but is this because all
blanks are removed and the "Txt" field is null or maybe has no point of reference for value?
It is because TXT is being trimmed, therefore the %SUBST applies to the resulting value. For example, assume:
txt = ' HELLO WORLD';
Then you do the operation: %TRIML(TXT)
The intermediate result is 'HELLO WORLD' which has a length of 11, not 15. Then you do %SUBST(%TRIML(TXT):1:15) you are trying to extract 15 positions from a value that has only 11.To correct it, avoid specifying the last value for %SUBST (15 in your example) and allow it to default. That will extract to the end of the field or value.Having said that, your %SUBST has no value or purpose in this expression. It does nothing but introduce the potential for errors as you've discovered.
Thanks Bob once again!
TxtOut = %TrimL(Txt) ;
You only want 15 characters which is the length of TxtOut anyway. If the %TrimL returns fewer characters, no problem, TxtOut is cleared before the assignment occurs, so TxtOut would have trailing blanks.
Ringer