RPGLE built in functions - skill-at/AS-400-Training GitHub Wiki

1.%SUBST(string :Starting position : length)

This will be used to extract part of string. Note : Length parameter is not mandatory if whole string needs to be extracted from start position till end.

image

2.%SCAN : This is used to search character inside a string. This will return first position of character.

%scan(char to be scanned : string where char needs to be scanned :start position )

3 %CHAR : To change numeric/date value to a character. %char(value which needs to be converted) This also has second parameter, If we are converting date to a character value second parameter can be used to define date format which input variable is having.

4.%XLATE : This is used for translation purpose. %xlate(from:To:String)

This will translate all characters from one value to another value in string. It can also be used to translate set of characters within a constant.

5.%len () : This built in function is used to get length of string

  1. %trim() , %triml() , %trimr(): This built in functions are used to trim spaces/characters in particular string from both ends/ left/right.

  2. %CHECK %CHECK function is used to find the position for non-occurrence of a character in a string. The format of this function is %CHECK(comparator : base string {: Start position}).

8.%CHECKR function is used to find the position for non-occurrence of a character in a string from Right. The format of this function is %CHECK(comparator: base string {: Start position}) image image

Program to convert lower case to upper case using XLATE. Here 2 constants are defined and values are provided using const keyword.

image

9 %DEC : %DEC converts the value of the first parameter to decimal (packed) format.9. %DEC : %DEC converts the value of the first parameter to decimal (packed) format.

  1. %DATE is used to convert char/decimal value to date. %date(first parameter , second parameter) First parameter will be string/expression which needs to be converted to date. Second parameter will be the date format of input.

  2. %days . This is used to convert number into a duration which is number of days. This can be later used to add/subtract days from date field.

  3. %months . This is used to convert number into a duration which is number of months. This can be later used to add/subtract months from date field..

  4. %years . This is used to convert number into a duration which is number of years. This can be later used to add/subtract months from date field.

  5. %Timestamp : This will covert expression to TIMESTAMP , if nothings is specified this will return current time stamp.