Wednesday, September 19, 2007

Convert Case:

Many times we have faced situation to convert upper case to lower case and vice versa. In RPG we use the XLATE opcode and in RPGLE we use %XLATE for it.

D up C 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
D lo C 'abcdefghijklmnopqrstuvwxyz'
D string S 10A inz('rpg dept')

/FREE

string = %XLATE(lo:up:'rpg dept');
// string now contains 'RPG DEPT'

string = %XLATE(up:lo:'rpg dept':6);
// string now contains 'RPG Dept'
/END-FREE

We can achieve the same functionality in CL by using an API.
The Convert Case (OPM, QLGCNVCS; ILE, QlgConvertCase) API provides a case conversion function that can be directly called by any application program. This API can be used to convert character data to either uppercase or lowercase.
This API supports conversion for single-byte, mixed-byte, and UCS2 (Universal Multiple-Octet Coded Character Set with 16 bits per character) character sets. For the mixed-byte character set data, only the single-byte portion of the data is converted. This API does not convert double-byte character data from any double-byte character set (DBCS) or from a mixed-byte character set.
This API can base case conversion on a CCSID, whereas the Convert Data (QDCXLATE) API uses only table objects.
Required Parameter Group:

1 Request control block Input Char(*)
2 Input data Input Char(*)
3 Output data Output Char(*)
4 Length of data Input Binary(4)
5 Error code I/O Char(*)

No comments: