Sort (QLGSORT) API


  Required Parameter Group:

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

  Optional Parameter Group:

7 Returned records feedback Output Char(*)
8 Length of returned records feedback Input Binary(4)

  Default Public Authority: *USE

  Threadsafe: No

The Sort (QLGSORT) API provides a generalized sort function that can be directly called by any application program. This API can be used to sort data in files or data in an input buffer with a single call. This API can also be used to initialize a sort function where a series of calls using the Sort Input/Output (QLGSRTIO) API is done to repeatedly add data to be sorted as a set of records and return sorted data as a set of records.

The following types of sort operations can be done with the API:

The sort allows the application to indicate whether character data should be sorted as a binary (hexadecimal) sort or sorted using a national language sort sequence for obtaining sort results consistent with a specific locale. When specifying a character field as binary (hexadecimal), the national language sort sequence is not used. The hexadecimal sort is helpful if DBCS-graphic data is being sorted. This sort can also be used to define character fields that contain hexadecimal or bit data. The caller can indicate if character data being sorted might contain double-byte characters. This type of field is considered a DBCS-open field, where DBCS data is surrounded by control characters. If a field is defined as such, the API will apply a national language sort sequence only to the single-byte data in the field. Performance may be slower when this type of character field is defined because of additional checking that occurs for DBCS data. If a field is defined as a single-byte field but DBCS data exists in the field, the national language sort sequence is applied to the DBCS data as if it were single-byte data, which may result in an unexpected sequence.

The sort allows a character field to contain 2-byte characters in UCS-2. If a field is defined as such, the API will apply a UCS-2 national language sort sequence if specified in the national language sort information.

The sort allows a character field to be variable length. All occurrences of the variable length character field have the same maximum length. The actual data length is defined by a 2-byte binary value that immediately precedes the character field. When using a variable length field, all bytes between the actual data length and the maximum data length are sorted as if they were blanks. Variable length fields are allowed only when sorting buffers of data or when using files for both input and output.

The sort allows a record to be defined for variable length record access. When using variable length record access, a 2-byte binary value indicates the actual data length of the record. When sorting records of different length, the shorter record is logically padded to the length of the longer record with blanks. This occurs only if the sort specification refers to a key size greater than the actual record length of the shorter record. This support is mutually exclusive of variable-length-field sort support. It is allowed only when sorting buffers of data and when using externally described database files. When using database files for both input and output, the file must be defined as having all fixed length fields except for the last field. The last field must be variable length.

The sort also allows fields to be defined as null capable. Fields that are set to null sort higher than any non-null value. Null support is allowed only when sorting buffers of data and when using externally described database files for both input and output.

The QLGSORT API requires that no earlier sort be active for this job at the time the sort is called. This is especially important when the QLGSORT API is called to initialize a sort and the QLGSRTIO API is repeatedly called to add data to the sort or return data from the sort. When retrieving data from the sort using the QLGSRTIO API, the normal operation is to continue calling QLGSRTIO until all of the data is returned. Whenever a get request is made and there is no more data to be returned, the sort is ended. If a get request is made and data still remains to be returned, the sort is still active until another get request is made and all of the data is returned. Another way to end the sort is to specify Cancel (request type 4) on the QLGSRTIO API call. The cancel request causes the sort to end immediately, regardless of whether there is still data to be returned. Whenever a sort is active and QLGSORT is called again by the same job, an error is returned.

When using the QLGSRTIO API to put data to the sort and the output is to be put in output files, the end put operation on the call to the QLGSRTIO API causes the data to be sorted and the output to be generated. The sort is then ended without the need to call QLGSRTIO with a cancel request.

When QLGSORT is called once to perform sorting of data in an input data buffer or in files, with the output going to an output data buffer or files, the sort is ended within that one call. All internal spaces have been deleted. Subsequent calls to the QLGSORT API are therefore valid.

If input files are specified and an error occurs with any of them, an error message is returned and no sorting occurs. It is up to the caller to determine if the QLGSORT API must be called again to perform the sort operation. There is no capability to continue with the previous sort.

If output files are specified, the file member of a physical output file is cleared before the sorted data is put to the file. If output files are specified and an open or put error occurs with any of the files, the sort continues to put data to the files that are not in error. For some I/O errors, an inquiry message is sent to the system operator message queue (QSYSOPR). Processing stops until a reply is received for the message. If all of the output files are in error, a message is returned indicating that the data was sorted but there were no valid output files in which to put the data.


Authorities and Locks

Input File Authority
*USE

Input File Library Authority
*USE

Output File Authority
Both *OBJOPR and *ADD or both *OBJALT and *ADD

Output File Library Authority
*USE

Sort Sequence Table Authority
*USE

Sort Sequence Table Library Authority
*USE

Input File Lock
*SHRNUP

Output File Lock
*EXCL

Sort Sequence Table Lock
*SHRNUP

Required Parameter Group

Request control block
INPUT; CHAR(*)

Information defining the sort, such as whether a list of files or an input data buffer will be sorted. It also defines the keys to be used for the sort. Refer to Format of Request Control Block for details.

Input data buffer
INPUT; CHAR(*)

The input data to be sorted. The calling program is responsible for adding all of the data to be sorted to this parameter before calling the QLGSORT API. The input data buffer parameter must contain the data to be sorted when the type of request field is 4, 5, or 6. For information on how to format this buffer, see Buffer Layout Examples.

This parameter is ignored when the type of request field is 1, 2, 3, 7, or 8 because either the file data will be sorted or the data will be provided through calls to the QLGSRTIO API.

Output data buffer
OUTPUT; CHAR(*)

The sorted output data to be returned to the calling program. The output data buffer parameter will contain the sorted output data when the type of request field in the request control block is 2 or 5.

This parameter is ignored when the type of request field is 1, 3, 4, 6, 7, or 8 because data is either provided in output files or through calls to the QLGSRTIO API. For information on how this buffer is formatted, see Buffer Layout Examples.

The QLGSORT API returns only the data that the buffer can hold, up to the length of data that is available to be returned. The size of the output data buffer must be greater than or equal to the record length field of the request control block. This is to ensure that at least one record can be provided as output. The output data buffer parameter can be the same as the input data buffer parameter.

Length of output data buffer
INPUT; BINARY(4)

The maximum length of the output data to be returned to the calling program in the output data buffer parameter. If this length is larger than the actual size of the output data buffer parameter, the results may not be predictable. The length of output data buffer must be at least as large as the record length value specified in the request control block when the type of request field in the request control block is 2 or 5. If it is not, an error is returned.

The length of output data must be set to 0 when the type of request field is 1, 3, 4, 6, 7, or 8 because the data is returned either as output files or through calls to the QLGSRTIO API. The maximum length allowed is 16MB less 512 bytes.

Length of returned data
OUTPUT; BINARY(4)

The actual length of the output data added to the output data buffer parameter. When no output data is returned, this parameter is set to 0.

Error code
I/O; CHAR(*)

The structure in which to return error information. For the format of the structure, see Error Code Parameter.


Optional Parameter Group

Returned records feedback
OUTPUT; CHAR(*)

The number of records added to each output file to be returned to the calling program. The returned records feedback parameter contains the number of records added to each output file.

This parameter is ignored when the type of request field is 2, 3, 5, 6, 7, or 8. This is because data is returned in buffers or through calls to the QLGSRTIO API.

The number of records added to each output file corresponds to the list of files specified in the request control block. To receive results, you must also set the options field in the request control block to 4, 5, 6, or 7.

See Format of Returned Records Feedback Information for details.

Length of returned records feedback
INPUT; BINARY(4)

The length of the returned records feedback parameter to be returned to the calling program. If this length is larger than the actual size of the returned records feedback parameter, the results may not be predictable. The minimum length is 8. See the Format of Returned Records Feedback Information for details.

This parameter is ignored when the type of request field is 2, 3, 5, 6, 7, or 8. This is because data is returned in buffers or through calls to the QLGSRTIO API.


Format of Request Control Block

For a description of the fields in this format, see Field Descriptions.

Offset Type Field
Dec Hex
0 0 BINARY(4) Length of request control block
4 4 BINARY(4) Type of request
8 8 BINARY(4) Reserved
12 C BINARY(4) Options
16 10 BINARY(4) Record length
20 14 BINARY(4) Record count
24 18 BINARY(4) Offset to key list
28 1C BINARY(4) Number of keys
32 20 BINARY(4) Offset to national language sort information
36 24 BINARY(4) Offset to input file list
40 28 BINARY(4) Number of input files
44 2C BINARY(4) Offset to output file list
48 30 BINARY(4) Number of output files
52 34 BINARY(4) Length of key entry
56 38 BINARY(4) Length of national language sort sequence information
60 4C BINARY(4) Length of input file entry
64 50 BINARY(4) Length of output file entry
68 54 BINARY(4) Offset to null byte map
72 58 BINARY(4) Offset to variable length record access information
76 6C BINARY(4) Reserved
Note: Format of entries in the key list. The following fields are repeated for each key entry. The decimal and hexadecimal offsets depend on the number of key entries. The first key entry is found by using the offset to key list field. At least one key must be specified. Sorting will be done on the keys in the order they are specified.
    BINARY(4) Key starting position
    BINARY(4) Key string size
    BINARY(4) Key data type
    BINARY(4) Sort order
    BINARY(4) Ordinal position of key field
Note: Format of national language sort information. The following fields are not repeated. The decimal and hexadecimal offsets depend on the number of key entries. The first field is found by using the offset to national language sort information field. If you want a hexadecimal sort instead of a national language sort, set the offset to national language sort information field to 0. In this case, you do not need to specify the sort sequence fields.
    CHAR(20) Qualified sort table name
    BINARY(4) Sort sequence CCSID
    CHAR(10) Sort sequence language ID
    CHAR(256) Sort sequence table
Note: Format of entries in the input file list. The following fields are repeated for each input file entry. The decimal and hexadecimal offsets depend on the number of input file entries and the number of key entries. The first input file entry is found by using the offset to input file list field. If the input data buffer parameter contains data to be sorted, or data will be provided through the QLGSRTIO API, the offset to input file list field must be set to 0.
    CHAR(20) Qualified input file name
    CHAR(10) Input member name
    BINARY(4) Variable length record access
    BINARY(4) Null-capable fields
Note: Format of entries in the output file list. The following fields are repeated for each output file entry. The decimal and hexadecimal offsets depend on the number of input file list entries and key list entries. The first output file entry is found by using the offset to output file list field. If the sorted records are to be returned in the output data buffer, or data will be returned through calls to the QLGSRTIO API, the offset to output file list field must be set to 0.
    CHAR(20) Qualified output file name
    CHAR(10) Output member name
    BINARY(4) Variable length record access
    BINARY(4) Null-capable fields


Format of Returned Records Feedback Information

For a description of the fields in this format, see Field Descriptions.

Offset Type Field
Dec Hex
0 0 BINARY(4) Bytes available
4 4 BINARY(4) Bytes returned
8 8 BINARY(4) Offset to start of returned records array
12 C BINARY(4) Number of output files
    ARRAY of BINARY(4) Returned records


Field Descriptions

Bytes available. The number of bytes of data available to be returned. All available data is returned if enough space is provided.

Bytes returned. The number of bytes of data returned.

Input member name. The name of the member in the input file. A value of *FIRST indicates that the first member of the file will be used. A value of *LAST indicates that the last member of the file will be used. If the specified member does not exist, an error is returned and no sorting is done.

Key data type. The following are the values that may be specified:

0 Signed binary.
1 Signed binary floating point.
2 Signed zoned decimal.
3 Signed packed decimal.
4 Character with national language sort sequence applied, if specified. DBCS data will be treated as single-byte data.
5 Mixed character with national language sort sequence applied, if specified, only to single-byte data.
6 Character with no national language sort sequence applied, if specified.
7 Unsigned packed decimal. All numbers will have the sign forced positive ('F'X).
8 Unsigned zoned decimal. All numbers will have the sign forced positive ('F'X).
9 Unsigned binary.
10 Zoned decimal with a sign over the leading digit. The sign occupies the left-most 4-bits of the value.
11 Zoned decimal with a separate trailing sign. Valid values are +, -, and blank.
12 Zoned decimal with a separate leading sign. Valid values are +, -, and blank.
13 Date in the form of MM/DD/YY, where:
YY Year
MM Month
DD Day
14 Date in the form of DD/MM/YY
15 Date in the form of DD.MM.YYYY
16 Date in the form of MM/DD/YYYY
17 All other date/time formats
18 Time in the form of HH:MM xM, where:
HH Hour
MM Minute
x A or P
19 Variable length character with national language sort sequence applied, if specified. DBCS data will be treated as single-byte data.
20 Variable length mixed character with national language sort sequence applied, if specified, only to single-byte data.
21 Variable length character with no national language sort sequence applied, if specified.
22 Variable length UCS-2 character with national language sort sequence applied, if specified.
23 UCS-2 character with national language sort sequence applied, if specified.

The use of any other value will cause an error to be returned.

Key starting position. The starting position of the key field in the record. The starting position must be greater than 0 and cannot exceed the record length specified in the record length field, or an error is returned.

The same key starting position is used for all records to be sorted. Padding of blanks occurs on records that are shorter than the record length field. If a key starting position is within the area that is padded, these records are normally sorted into the first positions.

For key data types 19, 20, 21, and 22, the starting position should be byte 0 of the 2-byte length that precedes the character data.

Key string size. The number of bytes to be used for sorting this field. If the key field data type is 19, 20, 21, or 22, this must be the maximum length of the field in single bytes not including the 2-byte binary length in front of the data. The key string size must be greater than 0, and the string size plus the key starting position cannot exceed the record length field; otherwise, an error is returned. Also, the sum of the size of all of the keys cannot exceed 2000 bytes. If the sum exceeds this maximum, an error is returned.

Note: Data that is encoded in UCS-2 requires 2 bytes for each character.

Length of input file entry. The total length of the input file entry. If specified, the minimum length must be 30 bytes. If the input file includes any of the following, the length of the entry must be 38 bytes:

Length of key entry. The total length of the key entry. If a null key is allowed, the key length must be 20 bytes. If specified, the minimum length must be 16 bytes.

Length of national language sort sequence information. The total length of the national language sort sequence information. If specified, the minimum length must be 290 bytes.

Length of output file entry. The total length of the output file entry. If specified, the minimum length must be 30 bytes. If the output file includes either of the following, the length of the entry must be 38 bytes:

Length of request control block. The total length of the request control block. The minimum size is 72 bytes, which allows for one key in the key list, no input or output files, and no national language sort sequence information. An error is returned if the length specified is less than the minimum.

Null-capable fields. Whether null-capable fields are supported in a file. The possible values follow:

0 The file does not contain null-capable fields.
1 The file contains null-capable fields. This value is allowed only when sorting externally described database files.

Number of input files. The number of input files specified in the input file list. If the number of input files is 0 and the request type field is 1,2, or 3 (file sort), an error is returned. Up to 32 input files can be specified.

Number of keys. The number of keys specified in the request control block. The sum of the lengths of all of the key fields cannot exceed 2000 bytes. Therefore the number of keys is limited to a maximum of 2000,which allows each key to be 1 byte long. At least one key field must be defined.

Number of output files. The number of output files specified in the output file list. If the number of output files is 0 and the request type field is 1, 4, or 7 (file output), an error is returned. Up to 32 output files can be specified.

Offset to input file list. The offset to the start of the input file list structure. If data in the input data buffer parameter is being sorted, or input data will be provided by the QLGSRTIO API, the input file list structure is not required and this offset must be set to 0.

Offset to key list. The offset to the start of the key list structure. At least one key must be defined in the key list structure, or an error is returned.

Offset to national language sort information. The offset to the start of the national language sort information structure. If you want a hexadecimal sort instead of a national language sort, set this offset to 0. In this case, you do not need to specify the sort sequence fields.

Offset to null byte map. The offset to the start of the null byte map. The null byte map contains a 1-byte value for each field in the record. The order of the bytes corresponds to the order of the fields. If the field contains null data, the value should be set to 1; otherwise, the value should be 0.

This offset must be set if there are null-capable fields in the input buffer. If there are no null-capable fields in the input buffer, the value must be set to 0. Also, the value must be set to 0 if the type of request is 1, 2, 3, 4, or 7. See the Buffer Layout Examples for information on how to format this buffer.

Offset to output file list. The offset to the start of the output file list structure. If data is being returned in the output data buffer parameter or if the QLGSRTIO API will be used to return the sorted data, the output file list structure is not required and this offset must be set to 0.

Offset to start of returned records array. The offset to the returned records array.

Offset to variable length record access information. The offset to the start of the variable length record access information. This offset must be set if variable length record access is being used for buffer processing.

The offset should be set to the maximum length of the actual user-defined data for a record in a buffer or file plus 1 byte. For example, if the largest user data in the buffer is 80 bytes, this field would be 81. At offset 81 within each record to be sorted, a 2-byte binary value is set to indicate the actual length of the user data.

When used in conjunction with null-capable fields, this offset value must be less than the value specified for the offset to null byte map field. This offset must be 0 unless the type of request is 5, 6, or 8 and the buffer contains variable length records.

Options. Additional options to be handled by the sort. The following values are defined:

0 No options used.
1 Log record count messages. One message is returned in the job log for each output file indicating the number of records written to the output file. When output files are not used, one message is returned indicating the total number of records sorted.
2 Throw away duplicate keyed records when writing to files requiring unique keys. The normal processing is to maintain duplicates in the order in which they are received. This option allows for succeeding data to be written to the file or buffer by bypassing records with duplicate keys. If this option is not selected and a duplicate key is encountered when writing data to a database file defined to have unique keys, a message is returned. No further data is entered into the file.
3 Log record count messages and throw away duplicate keyed records. This option is a combination of options 1 and 2.
4 Store record count for each file in the returned records feedback. When output files are not used, a message is returned to the job log indicating the total number of records sorted.
5 Store record count for each file in the returned records feedback and log record count messages. When output files are not used, a message is returned to the job log indicating the total number of records sorted. This option is a combination of options 1 and 4.
6 Store record count for each file in the returned records feedback and throw away duplicate keyed records. This option is a combination of options 2 and 4.
7 Store record count for each file in the returned records feedback, log record count messages, and throw away duplicate keyed records. This option is a combination of options 1, 2, and 4.

Ordinal position of key field. The ordinal position of the key field relative to all fields within the record. This value must be set if sorting on a null-capable field.

Output member name. The name of the member in the output file. A value of *FIRST indicates that the first member of the file should be used. A value of *LAST indicates that the last member of the file should be used.

Qualified input file name. The name of a file whose data is to be sorted, and the library in which it is located. The first 10 characters contain the file name, and the second 10 characters contain the library name.

The library name can have the following special values:

*LIBL The current library list.
*CURLIB The job's current library.

All values must be padded with blanks to the right of the value.

If a file is specified that does not exist or is unavailable (for example, locked), an error is returned for that file and no further files are read. No sorted data is returned for any of the files already read without errors.

The QLGSORT API supports database (both logical and physical), diskette, and tape files. Any other file type is not recognized and an error is returned. Variable length record access and null-capable fields are supported for externally described database files only.

The data in each of the files is sorted as the common record length specified in the record length field. However, if the file contains variable length fields or uses variable length record access, the data is sorted using the actual length of the data. The data is truncated or padded with blanks as necessary when the record length of the input file is different than the record length value.

The total length of all the records in all the input files cannot exceed 16MB for the data to be returned in the output data buffer parameter. If your files have more data than this, you should consider having the output data sent to output files, or use the QLGSRTIO API to repeatedly retrieve sets of sorted data.

Qualified output file name. The name of a file that is to receive sorted data, and the library in which it is located. The first 10 characters contain the file name, and the second 10 characters contain the library name.

The library name can have the following special values:

*LIBL The current library list.
*CURLIB The job's current library.

All values must be padded with blanks to the right of the value.

If a file is specified that does not exist or is unavailable (for example, locked), a diagnostic error is returned indicating the error and the file in error. If an error occurs when the file is opened or put, a message is returned indicating the error and the file in error. For some I/O errors, an inquiry message is sent to the system operator message queue (QSYSOPR). Processing stops until a reply is received for the message. The QLGSORT API continues to put data to the other files that do not have errors. If none of the output files could be opened, an error message is returned indicating that the sort was successful but there were no files in which the sorted data could be returned.

The QLGSORT API supports database (both logical and physical), diskette, and tape files. Any other file type is not recognized and an error is returned, but the sort continues to provide output to any other output file types that are supported. Variable length record access and null-capable fields are supported for externally described database files only. The same file can be used both as an input and as an output file.

If the sorted output is returned in the output data buffer parameter, or returned using the QLGSRTIO API, the output file list is not used. If the number of output files field is greater than 0, there must be exactly that number of output files specified, or an error is returned.

Each output file contains the full sorted set of records unless an error occurred for a file. Record truncation or padding of blanks occurs when writing to the output file and when the file record length is different than the sorted record length. One reason to have more than one output file is to provide a backup or shadow of your output data as it is being sorted.

Qualified sort table name. The name of a sort table to be used for sorting the character data, and the library in which it is located. The first 10 characters contain the sort table name, and the second 10 characters contain the library name.

When a qualified sort table name is specified, the sort sequence language ID and sort sequence table fields are ignored.

The following special values are supported for the table name. These values must be in uppercase, left-justified, and padded with blanks to the right of the value.

*JOB The sort sequence of the job.
*JOBRUN The API treats this value the same as *JOB.
*LANGIDUNQ The unique-weight sort sequence table that is associated with the sort sequence language ID field.
*LANGIDSHR The shared-weight sort sequence table that is associated with the sort sequence language ID field.
*HEX The hexadecimal value of the characters.
*TABLE The sort sequence table provided in the sort sequence table field.

Note: Both *JOB and *JOBRUN are accepted to accommodate calls from other programs that accept both values and for which the two have different semantics.

The following special values are supported for the library name. These values must be in uppercase, left-justified, and padded with blanks to the right of the value.

*LIBL The user's library list.
*CURLIB The current library.

If a special value is used for the table name, the second 10 characters used for the library name must be blank.

Record count. The number of records that exist in the input data buffer parameter when input data is to be sorted. Only the number of records specified in the record count field are sorted, even if more than this number exist in the input data buffer parameter. The record count multiplied by the record length must not be greater than 16MB.

The record count field must be greater than 0 when the type of request field is 4, 5, or 6 (input data to be sorted). If it is not, an error is returned.

The record count field must be set to 0 when the type of request field is 1, 2, 3, 7, or 8 because input files are being sorted or the data will be provided by the QLGSRTIO API. If it is not, an error is returned.

Record length. The record length that the sort uses for processing. When a data buffer is being sorted, this is the maximum length of a record in the buffer. The value includes the following:

For example, assume a user record contains five fields having a total length of 80 bytes, supports nulls, and is processed using variable length record access. The record length field would be 87. That is, 80 for the logical record, 2 for the length of the record, and 5 for the null byte map.

When a list of files is being sorted, this record length defines the length used for sorting all the files. If the data is to be returned in the output data buffer, the record count multiplied by the record length cannot be greater than 16MB.

If an input file has a record length that is longer than the specified record length, it is truncated. If an input file has a record length that is shorter, it is padded with blanks.

When data is being provided through the QLGSRTIO API, this record length defines the length used for sorting all the records. Each set of records added to the sort through the QLGSRTIO API defines a record length for that set. Records that are longer than the record length defined here are truncated. Records that are shorter are padded with blanks.

The following special value is defined:

0 QLGSORT assumes the maximum record length to be that of the first input file processed. If 0 is specified when an input data buffer is being sorted, or if data is being provided through calls to the QLGSRTIO API, an error occurs.

Reserved. A reserved field. This field must be set to 0.

Returned records. The number of records returned in an output file.

Sort order. The order to be used for sorting.

The following special values are defined:

1 Sort in an ascending sequence.
2 Sort in a descending sequence.

Sort sequence CCSID. The CCSID to be used, along with the sort sequence language ID, for retrieving the national language sort sequence table for sorting the character data.

The valid values for this parameter are:

0 The CCSID of the job is the CCSID of the sort sequence table to be used.
1-65533 A valid CCSID in this range must be specified or an error is returned.
65535 The CCSID of the sort sequence table that is found should be used. No CCSID conversion should be done on the found table.

The following table summarizes when the CCSID value is required and when it will be ignored based on the value in the qualified sort table name field in the request control block.

Qualified Sort Table Name CCSID
*JOB Required
*JOBRUN Required
*LANGIDUNQ Required
*LANGIDSHR Required
*HEX Ignored
*TABLE Ignored
Table name and library Ignored

Sort sequence language ID. The language ID to be used to obtain a national language sort sequence table for sorting the character data. All values must be padded with blanks to the right of the value and must be in uppercase.

Possible values for this parameter are:

*JOB The language identifier of the job.
*JOBRUN The API treats this value the same as *JOB.
Specific language identifier A valid 3-character language identifier. For example, Danish would be "DAN". See the globalization topic for a complete list of valid language identifiers.

Note: Both *JOB and *JOBRUN are accepted to accommodate calls from other programs that accept both values and for which the two have different semantics.

The following table summarizes when the sort sequence language ID is required and when it is ignored based on the value in the qualified sort table name field in the request control block.

Qualified Sort Table Name Language ID
*JOB Required
*JOBRUN Required
*LANGIDUNQ Required
*LANGIDSHR Required
*HEX Ignored
*TABLE Ignored
Table name and library Ignored

Sort sequence table. The sort table to be used for sorting the character data. This field is only used when the qualified sort table name field is *TABLE. Otherwise, it is ignored. If UCS-2 data is to be sorted, use the QLGRTVSS API to retrieve a UCS-2 sort sequence table.

Type of request. The type of sort operation being requested. The following values are defined:

1 Input files are sorted, and the output goes to an output file.
2 Input files are sorted, and the output goes to the output data buffer parameter.
3 Input files are sorted, and the output is held for the QLGSRTIO API to retrieve one set at a time.
4 Data in an input data buffer is sorted, and the output goes to an output file.
5 Data in an input data buffer is sorted, and the output goes to the output data buffer parameter.
6 Data in an input data buffer is sorted, and the output is held for the QLGSRTIO API to retrieve one set at a time.
7 Input data is provided by the QLGSRTIO API, and the output goes to an output file.
8 A sort is initialized so that data can be provided through the QLGSRTIO API one set at a time and retrieved one set at a time through the QLGSRTIO API.

The following table summarizes the input source and output target for each type of request.

Type of Request Source Target
1 Input files Output files
2 Input files Output data buffer
3 Input files QLGSRTIO API calls
4 Input data buffer Output files
5 Input data buffer Output data buffer
6 Input data buffer QLGSRTIO API calls
7 QLGSRTIO API calls Output files
8 QLGSRTIO API calls QLGSRTIO API calls

If the input files contain variable length fields, null fields, or use variable length record access, the only type of request allowed is 1.

If the input buffer contains variable length fields, null fields, or uses variable length record access, the only type of requests allowed are 5, 6, or 8.

Variable length record access. Whether variable length record access should be used for input or output files.

The possible values follow:

0 Do not use variable length record access.
1 Use variable length record access. This value is allowed only when using externally described database files. All fields but the last one in the file are defined as fixed length, and the last field is defined as variable length.


Buffer Layout Examples

The following examples show the layout of the buffer for fixed and variable length fields, null-capable fields, and variable length record access. The null byte map indicates whether the field is null (1) or contains data (0).

Buffer with Fixed Length Fields

If the sort includes none of the following, the record length field is set to the total number of bytes for all the fields:

Following is an example of a buffer containing 4 fields that are fixed length. The record length and the fields used for the sort are indicated.

Field 1          Char 8
Field 2          Char 10
Field 3          Char 3
Field 4          Char 10

Record length = 31
Sort on fields 1 and 3

Field 1 Field 2 Field 3 Field 4
JJJJJJJJ
FFF
KKKKK
A1B2C3D4E5
A5B4C3D2E1
A1B2C3D4E5
XXX
YY
ZZZ
1111111111
222222
33333333

Buffer with Variable Length Character Fields

This is an example of a buffer that contains variable length fields. The length of the each variable length field must be contained in a 2-byte binary value that precedes the data.

Field 1          Char 8
Field 2          Char 10
Field 3          Char 3
Field 4 is variable length character

Record length = 33 (31 bytes for the maximum length
                    of the data plus 2 bytes for
                    the field length)
Sort on fields 1 and 3

Field 1 Field 2 Field 3 Field 4
Data Data Data Length Data
JJJJJJJJ
FFF
KKKKK
A1B2C3D4E5
A5B4C3D2E1
A1B2C3D4E5
XXX
YY
ZZZ
10
6
8
1111111111
222222
33333333

Buffer with Variable Length Character Fields and Null-Capable Fields

If the buffer contains variable length fields and null-capable fields, the null byte map must follow the record. The offset to the null byte map is set in the offset to null byte map field. The null byte map contains one byte for each field. The bytes correspond to the field order. For example, for null byte map 0010, fields 1, 2, and 4 contain data and field 3 is null.

The position of each key must be set in the ordinal position of key field.

Field 1                     Char 8
Field 2                     Char 10
Field 3 is null capable     Char 3
Field 4 is variable length character

Record length = 37 (31 bytes for the maximum length
                    of the data plus 2 bytes for
                    the field length of field 4 plus
                    4 bytes for the null byte map)
Sort on fields 1 and 3

Field 1 Field 2 Field 3 Field 4 Null Byte Map
Data Data Data Length Data
JJJJJJJJ
FFF
KKKKK
A1B2C3D4E5
A5B4C3D2E1
A1B2C3D4E5
XXX
*NULL
ZZZ
10
6
8
1111111111
222222
33333333
0000
0010
0000

Buffer with Variable Length Record Access and Null-Capable Fields

If the buffer contains variable length records, the actual length of the record must be added to the end of the data. It must precede the null byte map.

Field 1                     Char 8
Field 2                     Char 10
Field 3 is null capable     Char 3
Field 4 is variable length character

Record length = 37 (31 bytes for the maximum length
                    of the data plus 2 bytes for
                    the user record length plus
                    4 bytes for the null byte map)
Sort on fields 1 and 3

Field 1 Field 2 Field 3 Field 4 Actual Record Length Null Byte Map
Data Data Data Data
JJJJJJJJ
FFF
KKKKK
A1B2C3D4E5
A5B4C3D2E1
A1B2C3D4E5
XXX
*NULL
ZZZ
1111111111
222222
33333333
31
27
29
0000
0010
0000


Error Messages

Message ID Error Message Text
CPF2115 E Object &1 in &2 type *&3 damaged.
CPF2207 E Not authorized to use object &1 in library &3 type *&2.
CPF24B4 E Severe error while addressing parameter list.
CPF3BC6 E Sort sequence &1 not valid.
CPF3BC7 E CCSID &1 outside of valid range.
CPF3BC8 E Conversion from CCSID &1 to CCSID &2 is not supported.
CPF3BC9 E Conversion from CCSID &1 to CCSID &2 is not defined.
CPF3BCC E Language identifier &1 not valid.
CPF3BD3 E Sort already active.
CPF3BD5 E Sort request control block field &1 is not valid.
CPF3BD6 E Key field &1 is not valid for key number &2.
CPF3BD7 E Key size exceeds maximum.
CPF3BD8 E Input file entry &3 field &4 is not valid.
CPF3BD9 E Output file entry &3 field &4 is not valid.
CPF3BDA E No output files could be opened.
CPF3BDB E Sort internal storage limit exceeded.
CPF3BDC E Duplicate keys encountered for file &1 in library &2.
CPF3BE2 E Returned record feedback length not valid.
CPF3BE4 E Buffer information is not valid. Reason &1.
CPF3BE6 E Number of parameters, &1, entered for this API was not valid.
CPF3BE7 E File &1 in library &2 or file entry &4 has error &3.
CPF3BF0 E Sort sequence table specified or supplied is not valid.
CPF3C90 E Literal value cannot be changed.
CPF3CF1 E Error code parameter not valid.
CPF5715 E File &1 in library &2 not found.
CPF9504 E An invalid search order was specified.
CPF9801 E Object &2 in library &3 not found.
CPF9802 E Not authorized to object &2 in &3.
CPF9803 E Cannot allocate object &2 in library &3.
CPF9810 E Library &1 not found.
CPF9812 E File &1 in library &2 not found.
CPF9820 E Not authorized to use library &1.
CPF9830 E Cannot assign library &1.
CPF9845 E Error occurred while opening file &1.
CPF9846 E Error while processing file &1 in library &2.
CPF9872 E Program or service program &1 in library &2 ended. Reason code &3.


API introduced: V2R3
Top | National Language Support APIs | APIs by category