Sign in

docs RPG Reference

%TRIML (Trim Leading Characters)

%TRIML (Trim Leading Characters)

%TRIML(string {: characters to trim {: *NATURAL | *STDCHARSIZE}}})

%TRIML with only one parameter returns the given string with any leading blanks removed.

%TRIML with two parameters returns the given string with any leading characters that are in the characters to trim parameter removed.

The string can be character, graphic, or UCS-2 data.

If the characters to trim parameter is specified, and it does not have the same type and CCSID as the string parameter, it is converted to the type and CCSID of the string parameter.

The second or third parameter can be *NATURAL or *STDCHARSIZE to override the current CHARCOUNT mode for the statement. If this parameter is specified, it must be the last parameter.

For information about the CHARCOUNT mode affects %TRIML, see %TRIM with CHARCOUNT NATURAL.

When specified as a parameter for a definition specification keyword, the string parameter must be a constant.

Note: Specifying %TRIML with two parameters is not supported for parameters of Definition keywords.

For more information, see String Operations or Built-in Functions.

Figure 1. %TRIML Example

 *..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
 * LOCATION will have the value 'Toronto, Ontario  '.

 /FREE
     // Trimming blanks
     Location = %triml('  Toronto, Ontario  ');
     // LOCATION now has the value 'Toronto, Ontario  '.

     // Trimming other characters

     trimmed = %triml('$******5.27***        ' : '$* ');
     // trimmed is now '5.27***        '