ILE RPG sort sequence

The ILE RPG feature (an option of the IBM® WebSphere® Development Studio for iSeries™ licensed program) provides the possibility for a user to specify a sort sequence table and use it in comparison operations performed with non-numeric data.

For each of the supported languages, two tables (a shared-weight and unique-weight) are included with the server. With sort sequence support you can create sort sequence tables based on the existing ones.

The control specifications are specifications that provide the ILE RPG for iSeries compiler with information about your program and your server. The sort sequence used in ILE RPG for iSeries programs is controlled by all of the following items:

The alternative collating sequence field (ALTSEQ) in the control specifications allows the following values:

blank
No alternative collating sequence is used in the RPG program. The normal collating sequence is used in the RPG program. The compile options SRTSEQ and LANGID are ignored.
*NONE
No alternative collating sequence is used in the RPG program. The normal collating sequence is used in the RPG program. The compile options SRTSEQ and LANGID are ignored.
*SRC
The alternative collating sequence is used in the RPG program, according to the tables entered at the end of the RPG program. The alternative collating sequence table is loaded at compile time, and ordering, sorting, comparing, and match field processing is done according to that table.

The SORTA and LOOKUP operation codes do not use specified alternative collating sequence tables.

The SRTSEQ and LANGID parameters on the Create RPG Module and Create Bound RPG Program commands are ignored.

*EXT
The alternative collating sequence is specified outside of the RPG program. RPG compiler imports an external sort sequence table, based on the SRTSEQ and LANGID parameters on the Create RPG Module and the Create Bound RPG Program commands.

The SORTA and LOOKUP function with the arrays and tables at compile time and processing time take effect only when you specify D in the control specifications.

The sort sequence table to be used by the program can be determined at compile time or when the job is run. If the SRTSEQ parameter of the Create RPG Module and Create Bound RPG Program commands:

Notes:
  1. If the table to be stored with the program object at compile time does not exist, a table defining hexadecimal sort sequence and tagged with a CCSID value of 65535 is used.
  2. If the sort sequence table and the CCSID of the job running the program differ, the table is converted to the CCSID of the job.

SORTA and LOOKUP operation codes

The implementation of compare operation codes, match field and control field processing with the sort sequence tables is the same for the alternative collating sequence and for the sort sequence support. Compare operation codes are ANDxx, COMP, CABxx, CASxx, DOUxx, DOWxx, IFxx, ORxx, and WHxx. Additional functions provided with the SORTA and LOOKUP operation codes follow:

SORTA
The data in the array is sorted according to the sort sequence table.
LOOKUP
To provide proper table searching, the sort sequence table is used with the search arguments in the arrays and tables.

The search argument and either the table or array element are compared using the sort sequence table.

The array and table data are checked using the sort sequence table, whenever ascending or descending sequence is specified. If the SRTSEQ and LANGID parameter values resolve to retrieve the sort sequence table again at run time, then the array and table elements are loaded without a sequence check at the compile time. The sequence checks are performed at run time, according to the sort sequence table.

Related concepts
Sort sequence (QSRTSEQ) system value
Language identifier (QLANGID) system value
Sort sequence tables
Country and region identifiers
ILE COBOL sort sequence