TRANSLATE

Variants:


1. TRANSLATE c TO UPPER CASE.



2. TRANSLATE c TO LOWER CASE.



3. TRANSLATE c USING r.



4. TRANSLATE c ...FROM CODE PAGE g1...     TO CODE PAGE g2.



5. TRANSLATE f ...FROM NUMBER FORMAT n1... TO NUMBER FORMAT n2.


Depending on whether byte or character string processing is carried out, the operands can only be byte-type or character-type (see Overview).

The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Only character-type fields allowed in string processing.

In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs.

See String processing

Variant 1

TRANSLATE c TO UPPER CASE.

Variant 2

TRANSLATE c TO LOWER CASE.



Effect

The first variant converts all lowercase letters in c to uppercase. The second variant converts all uppercase letters to lowercase.

Example

DATA letters(3) TYPE C.
MOVE 'abc' TO letters.
TRANSLATE letters TO UPPER CASE.

letters now has the contents 'ABC'.

Note

The classification of upper- and lowercase, and the actual characters used are determined by the current text environment (see SET LOCALE LANGUAGE). Problems may occur when the system converts the characters, if the wrong language has been specified in SET LOCALE LANGUAGE, or if data has been processed that does



Variant 3

TRANSLATE c USING r.


Effect

Replaces all the characters in the field c according to the rule in field r. c1 containscharacter pairs. The second character in each pair replaces the first. If r does not contain a character in c, this character remains unchanged. r can also be a variable.

Example

DATA: letters(20) TYPE C VALUE 'abcabcabcXab',
      change(15)  TYPE C VALUE 'aXbaYBabZacZ'.
TRANSLATE letters USING change.

letters now contains 'XaZXaZXaZXXaZ'.



Variant 4

TRANSLATE c ...FROM CODE PAGE g1 ...TO CODE PAGE g2.


Parts marked with " ..." are interchangeable


TRANSLATE c TO   CODE PAGE g2.

TRANSLATE c FROM CODE PAGE g1.

Instead you can use conversion classes.

Effect

Converts the contents of the field c from character set g1 to character set g2. This variant uses the conversion table g1 to determine the SAP character, which is then used to determine the new character from g2.

Transaction SPAD allows you to display and maintain character sets. If one of the conversion tables does not exist, the runtime error CONVERSION_CODEPAGE_UNKNOWN occurs. Conversion combinations that are maintained as part of the runtime system for performance reasons do not trigger runtime errors, and you cannot change them using Transaction SPAD.

Example

DATA c(72) TYPE C.
TRANSLATE c FROM CODE PAGE '1110' TO CODE PAGE '0100'.

This statement converts the contents of field c from the HP-UX character set to IBM EBCDIC.

Note

Fields with types I, P, F, and X remain unchanged by the conversion. The syntax check only allows character fields for specifying the codepage. However, since the codepage is maintained in table TCP00 as a type N field with length 4, you should use this type.



Variant 5

TRANSLATE f ...FROM NUMBER FORMAT n1 ...TO NUMBER FORMAT n2.


Parts marked with " ..." are interchangeable


TRANSLATE f TO NUMBER FORMAT n1.

TRANSLATE f FROM NUMBER FORMAT n1.

Instead you can use conversion classes.

Effect

Converts the number formats in f. Currently, the number formats '0000' (HP, SINIX, IBM) and '0101' (DEC-alpha OSF) are supported. Other formats trigger the runtime error TRANSLATE_WRONG_NUM_FORMAT . If you omit FROM NUMBER FORMAT or TO NUMBER FORMAT, the system uses the system number format.

Example

DATA: f TYPE F,
      hex(2) TYPE X,
      nform LIKE tcp00-cpcodepage.
...
* The contents of fields hex and f are stored in /ARCHIV
* from another platform. hex is stored in a valid number
* form when it is saved, and can therefore be read on
* all platforms.

READ DATASET '/ARCHIV' INTO hex.
READ DATASET '/ARCHIV' INTO f.
nform = hex.  "Conversion from non-host-specific. HEX into N(4)
TRANSLATE f FROM NUMBER FORMAT nform.

Effect

Converts the contents of f from the nform format of a given platform into the system representation.

Note

This converts fields with types I and F. As in variant 4, you should define the number formats with type N and length 4.

You can display system codepage and number formats using the function module SYSTEM_FORMAT. This allows you to store additional information for archiving purposes.



Note

Performance:

Converting lowercase letters to uppercase (or the other way round) in a 10 byte character field requires around 7 msn (standardized microseconds).
If you use ... c USING c1... to replace two characters of a 10 byte character field,the runtime is around 9 msn.



Exceptions



Non-Catchable Exceptions

Related

REPLACE, OVERLAY, Conversion Classes

Additional help

Converting to Upper or Lower Case or Converting Characters