I was trying to replace some characters in my working string in the rpgle program but was not getting it. I just researched that %xlate is an opcode that can be used to replace certain characters in the string with other replacement characters. I got one example converting from lower to upper case using %xlate in rpgle. What are all the uses of %xlate in rpgle? Please explain with an example of each use.
We can use
%xlate
in RPGLE to translate values according to from, to, and start positions. Therefore, we can either translate from lower to upper case or from upper case to lower case.The first parameter of
%xlate
contains characters to be replaced, the second parameter contains their replacement values, the third parameter is the string to be translated, and the fourth parameter is the starting position for the translation and is optional to pass. The default value is 1 for the fourth parameter if it is not passed, the fifth parameter is again optional and here we can pass values either *NATURAL or *STDCHARSIZE.%XLATE(from: to: string : startpos : *NATURAL | *STDCHARSIZE)
If the first parameter is longer than the second, any extra characters in the first parameter are ignored. The first three parameters can be of type character, graphic, or UCS-2 and all first three parameters must have the same type.
Translate from lower to upper case using %xlate in RPGLE:
Translate from upper to lower case using %xlate in RPGLE: