ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Character String and Byte String Processing → Statements for Character String and Byte String Processing
TRANSLATE
Other versions: 7.31 | 7.40 | 7.54
Syntax
TRANSLATE text {TO {UPPER|LOWER} CASE}
| {USING mask}.
Extras
1. ... TO {UPPER|LOWER} CASE
2. ... USING mask
Effect
This statement converts the case or single characters of the character-type data object text
.
The statement CASE
can be used for the conversion to upper/lower case;
USING can be used for the conversion according to a mask. The variable text
must be character-type.
Addition 1
... TO {UPPER|LOWER} CASE
Effect
If you specify UPPER
, all lower-case letters of the data object text
are converted to upper case. If you specify LOWER
, all upper-case letters are converted to lower case.
Notes
In non-Unicode systems, the conversion of the upper/lower case depends on the
text environment.
Problems may occur if the language of the text environment differs from the language in which the data
to be processed was entered. To avoid this type of inconsistency, you have to set the text environment
accordingly using the SET LOCALE
statement prior to the conversion.
-
To modify the uppercase/lowercase of a character string in an operand position, you can use a
case function that includes the functions of the statement
TRANSLATE
.
Example
After the conversion, the variable text
contains "CAREFUL WITH THAT AXE, EUGENE".
DATA text TYPE string.
text = `Careful with that Axe, Eugene`.
TRANSLATE text TO UPPER CASE.
Addition 2
... USING mask
Effect
If you specify USING
, the characters in text
are converted according to the rule specified in the data object mask
. mask
is a
character-like expression position whose value is interpreted as a string of character pairs.
text
is searched for the first character of each pair, starting with the
first pair, and each location found is replaced with the second character of the pair. The search is
case-sensitive. If mask
contains a character multiple times as the first
character of a pair, only the first pair is taken into account. A character in text
that has already been replaced cannot be replaced again in the same TRANSLATE
statement. Therefore, if the second character of a pair in mask
appears as
the first character of a subsequent pair, the second pair affects only the original characters in text
.
Trailing blanks in data objects text
and mask
are taken into account for data objects. If mask
contains an uneven number
of characters, the last character is ignored. If mask
is a blank string, no replacements take place.
Note
To translate a character string in an operand position, you can also use a
translate function that includes the functions of the statement TRANSLATE
.
Example
Converts the characters "A" to "B", "a" to "b", and vice versa. text
contains "Abracadabra" after the conversion.
DATA text TYPE string.
text = `Barbcbdbarb`.
TRANSLATE text USING 'ABBAabba'.
This translation does not reflect the current version of the documentation.