ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Character String and Byte String Processing → Statements for Character String and Byte String Processing
Other versions: 7.31 | 7.40 | 7.54
CONVERT TEXT text INTO SORTABLE CODE hex.
The content of the operand
text is converted to a sortable byte string and
the result is assigned to the target field
hex. The data object
text itself remains unchanged.
text must be of the type
text is a
character-like expression position. The following can be specified for
- An existing byte-like variable.
An inline declaration
DATA(var), where a variable of type
The content of
text must contain valid characters. The sortable byte string
is defined by platform such that a size comparison or standard sort of multiple of these fields produces an order in which the source fields
text are sorted by the
locale defined in the current
text environment. The text environment is set when an
session is opened or by using the statement
If the target field
hex is of type
x and its length
is not sufficient for the byte string, an exception that cannot be handled is raised. If the length
is greater than that of the byte string, it is filled with hexadecimal 0 on the right. The minimum length
for all platforms is calculated as 24 times the length of
text plus 24, but
can be significantly shorter for some platforms. If
hex is of type
xstring, its length is adapted automatically.
CONVERT TEXT statement is designed to fill an index column (in internal
tables) by which the rows of the table can be sorted by locale. Since internal tables can also be sorted
by locale directly by using the
AS TEXT addition of the
CONVERT TEXT is especially useful in the following cases:
- If an internal table is sorted by locale and then subjected to a binary search using the statement
READ TABLEor using a table expression.
- An internal table is to be sorted more than once by locale. Using a sortable byte string ensures better performance than when using the
- Indices for database tables are to be structured in accordance with a locale.
- Textual comparisons are to be made between character-like data objects.
The characters "a" and "Z" are compared directly after they have been converted by CONVERT
TEXT. While "Z" is in front of "a" for the majority of code pages in direct comparisons, the comparison of the converted values returns the expected textual order. See also the
SORT for internal tables.
IF 'a' > 'Z'. cl_demo_output=>write_text( `'a' > 'Z'` ). ELSE. cl_demo_output=>write_text( `'a' < 'Z'` ). ENDIF. CONVERT TEXT: 'a' INTO SORTABLE CODE DATA(ax), 'Z' INTO SORTABLE CODE DATA(zx). IF ax > zx. cl_demo_output=>write_text( `'a' > 'Z'` ). ELSE. cl_demo_output=>write_text( `'a' < 'Z'` ). ENDIF. cl_demo_output=>display( ).
Cause: One of the operands has an invalid data type.
Cause: The source field has invalid content.
Cause: The target field is too small.