Midrange News for the IBM i Community


Posted by: George Fuste
IBM i developer
Jacksonville, FL
%TRIML and %SUBST with a blank field
has no ratings.
Published: 07 Sep 2016
Revised: 08 Sep 2016 - 292 days ago
Last viewed on: 27 Jun 2017 (596 views) 

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.

%TRIML and %SUBST with a blank field Published by: George Fuste on 07 Sep 2016 view comments(3)

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?                                

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: %TRIML and %SUBST with a blank field
Posted: 9 months 20 days 6 hours 7 minutes ago
Edited: Wed, 07 Sep, 2016 at 15:56:27 (293 days ago)

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.

Posted by: GFuste
Premium member *
Jacksonville, FL
Comment on: %TRIML and %SUBST with a blank field
Posted: 9 months 20 days 6 hours 4 minutes ago
Edited: Wed, 07 Sep, 2016 at 16:45:50 (293 days ago)

Thanks Bob once again!

Posted by: Ringer
Premium member *
Comment on: %TRIML and %SUBST with a blank field
Posted: 9 months 19 days 8 hours 13 minutes ago

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