%BINARYSORT meta-SQL element
Syntax
%BINARYSORT(Recname)
Description
Any in-memory sorting performed using COBOL language functions is performed as a binary sort in the current character set used for COBOL processing, and may not necessarily match the sort order returned by the database in response to an Order By clause. Should you require the database to return data sorted using a binary sort of its encoding rather than the default linguistically-correct sort, you must use the %BINARYSORT meta-SQL function around each column in the Where or Order By clause where binary ordering is important.
However, for z/OS implementations, keep in mind that this binary sorting is only equivalent when the COBOL program is run z/OS server. For example, the binary sort produced in COBOL differs from the binary sort produced by the database, as the database is encoded in extended binary-coded decimal interchange code (EBCDIC) and the client is in an ASCII-based encoding. Therefore, %BINARYSORT should only be used in COBOL programs that are not run using the RemoteCall function, where the z/OS platform is not supported as a RemoteCall server.
When running against non-z/OS systems, %BINARYSORT can be used in both RemoteCall and non-RemoteCall programs.
Note:
Using %BINARYSORT in
Where and Order By clauses negates the use of any indexes, as most
databases can't use indexes for functional comparisons. (For example, WHERE %BINARYSORT(column)
> 'X'). Use this syntax only when sorting equivalence of
SQL statement results and COBOL memory order is required.
Parameters
| Parameter | Description |
|---|---|
|
Recname |
Specify the record name to use with the sorting. |
Example
SELECT RECNAME FROM PSRECDEFN WHERE %BINARYSORT(RECNAME) < %BINARYSORT('xxx')
SELECT RECNAME FROM PSRECDEFN ORDER BY %BINARYSORT(RECNAME)