CONVERT TEXT

CONVERT - Conversion to a sortable format

Effect

CONVERT TEXT converts a text t to an immediately locale-specific sortable format. The source field t must be of type C or W. The target field sc should be of type X and at least 16 times (for type C) or 4 times (for type W) as long as the source field.

'Immediately locale-specific sortable' means that the statement

SORT itab BY sc [ASCENDING | DESCENDING].

returns the same result as

SORT itab BY t AS TEXT [ASCENDING | DESCENDING].

if sc is the outcome of using CONVERT TEXT to convert t.

' Locale-specific sortable' means that the ordering of characters depends on the text environment.

When an internal mode is opened (in other words, when a roll area is opened), the text environment is automatically set to the active user's language as specified in the user master record. If necessary, however, you can change the text environment explicitly in your program by using the SET-LOCALE statement.

SORT ... AS TEXT allows you to sort internal tables and extract datasets according to the locale without first having to perform an explicit date conversion with CONVERT TEXT. Provided you only want sorted output which is locale-specific, CONVERT TEXT is not necessary.

You can use CONVERT TEXT in the following scenarios:

The immediately locale-specific sortable format generated by CONVERT TEXT depends on the platform for its content and space requirements.
For a source field with length n, you can calculate the minimum length x of the auxiliary field (sufficient for all platforms), using the following formula:


Source field with type C: x = 24*n + 24
Source field with type W: x = 8*n + 8


The minimum length of the auxiliary field is significantly less on some platforms, and may also change with an operating system upgrade (see ISO C function strxfrm).

Refer to

Rules for Locale-Specific Sorting

.

Example

DATA: BEGIN OF TAB OCCURS 0, 
		TEXT(10)   TYPE C, 
		XTEXT(160) TYPE X, 
	END OF TAB. 
... 
LOOP AT TAB. 
  CONVERT TEXT TAB-TEXT INTO SORTABLE CODE TAB-XTEXT. 
  MODIFY TAB. 
ENDLOOP. 
SORT TAB BY XTEXT. 
... 
READ TABLE TAB WITH KEY XTEXT = TAB-XTEXT BINARY SEARCH. 
IF SY-SUBRC = 0. 
  ... 
ENDIF.