ILE RPG sort sequence
The ILE RPG feature, an option of the IBM Rational Development Studio for i licensed program, provides the possibility for a user to specify a sort sequence table and to use the table in comparison operations that are performed with nonnumeric data.
For each of the supported languages, two tables (a shared-weight table and a unique-weight table) are included with the system. With sort sequence support, you can create sort sequence tables based on the existing ones.
The control specifications provide the ILE RPG compiler with information about your program and your system. The sort sequence used in ILE RPG programs is controlled by all of the following items:
- The control specifications.
- The SRTSEQ (sort sequence table) parameter on the Create RPG Module and the Create Bound RPG Program commands.
- The LANGID (language identifier) parameter on the Create RPG Module and the Create Bound RPG Program commands.
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:
- Is set to *HEX, no sort sequence table is used.
- Specifies a table name, then that table is stored with the program object to be used when the job is run. For system-supplied default sort sequence tables for the supported languages, refer to Sort sequence tables.
- Is set to *LANGIDSHR or *LANGIDUNQ, the shared-weight or unique-weight table for the language determined by the LANGID parameter is stored with the program object. For a list of valid language identifiers, refer to Language and country and region identifiers.
- Is set to *JOB, the SRTSEQ parameter of the compile time job is used to determine the sort sequence. The table is stored with the program object.
- Is set to *JOBRUN, the attributes of the job running the compiled program determine the sort sequence to be used. If the SRTSEQ attribute of the job refers to the LANGID, the LANGID stored with the program object is used. If the LANGID stored with the program is also *JOBRUN, the LANGID of the runtime job is used.
- 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.
- 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.