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 translates the individual characters of the character-like data object text
.
Either CASE
can be used to translate the case or USING
can be used for a translation by pattern. The variable text
must be a character-like variable.
Addition 1
... TO {UPPER|LOWER} CASE
Effect
If UPPER
is specified, all lowercase letters of the data object text
are translated to uppercase. If LOWER
is specified, all uppercase letters are translated to lowercase.
Note
To modify the case of the letters in a character string in an operand position, a
case function can be used that includes the functions of the statement TRANSLATE
.
Example
After the translation, 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 USING
is specified, the characters in text
are translated in accordance with 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. A search is performed in
text, beginning with the first pair, for the first character in every pair. Every occurrence
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 respected.
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 respected for data objects. If mask
contains an odd number of characters, the last character is ignored. If mask
is an empty string, no replacements are made.
Note
To translate a character string in an operand position, a
translate function that includes the functions of the statement TRANSLATE
can also be used.
Example
Translates the characters "A" to "B", "a" to "b" and back. After implementation, text
contains "Abracadabra".
DATA text TYPE string.
text = `Barbcbdbarb`.
TRANSLATE text USING 'ABBAabba'.