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 - 896 days ago
Last viewed on: 20 Feb 2019 (1503 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)

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: 2 years 5 months 15 days 21 hours 59 minutes ago
Edited: Wed, 07 Sep, 2016 at 15:56:27 (897 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: 2 years 5 months 15 days 21 hours 56 minutes ago
Edited: Wed, 07 Sep, 2016 at 16:45:50 (897 days ago)

Thanks Bob once again!

Posted by: Ringer
Premium member *
Comment on: %TRIML and %SUBST with a blank field
Posted: 2 years 5 months 15 days 6 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