Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

translate

Former Member
0 Likes
752

HI..

what is the use of translate statement. please explain.

regards

prajwal.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
697

Hi,

Check this one.

TRANSLATE text {TO {UPPER|LOWER} CASE}

| {USING pattern}.

Extras:

1. ... TO {UPPER|LOWER} CASE

2. ... USING pattern

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 pattern. The variable text must be character-type.

Note

There are two obsolete variants of this statement:

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.

Note

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 is entered. Data loss will occur if a conversion between the source and target language has not been defined. To avoid this type of inconsistency, you must appropriately set the text environment using the SET LOCALE statement prior to the conversion.

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 pattern

Effect

If you specify USING, the characters in text are converted according to the rule specified in pattern. pattern must be a character-type data object whose contents are interpreted as a sequence 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 pattern 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 pattern 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 pattern are taken into account for data objects. If pattern contains an uneven number of characters, the last character is ignored. If pattern is a blank string, no replacements take place.

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'.

Rewards points if it is useful.

HI..

what is the use of translate statement. please explain.

regards

prajwal.

4 REPLIES 4
Read only

Former Member
0 Likes
698

Hi,

Check this one.

TRANSLATE text {TO {UPPER|LOWER} CASE}

| {USING pattern}.

Extras:

1. ... TO {UPPER|LOWER} CASE

2. ... USING pattern

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 pattern. The variable text must be character-type.

Note

There are two obsolete variants of this statement:

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.

Note

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 is entered. Data loss will occur if a conversion between the source and target language has not been defined. To avoid this type of inconsistency, you must appropriately set the text environment using the SET LOCALE statement prior to the conversion.

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 pattern

Effect

If you specify USING, the characters in text are converted according to the rule specified in pattern. pattern must be a character-type data object whose contents are interpreted as a sequence 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 pattern 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 pattern 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 pattern are taken into account for data objects. If pattern contains an uneven number of characters, the last character is ignored. If pattern is a blank string, no replacements take place.

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'.

Rewards points if it is useful.

Read only

Former Member
0 Likes
697

TRANSLATE

Syntax

TRANSLATE text {TO {UPPER|LOWER} CASE}

| {USING pattern}.

Extras:

1. ... TO {UPPER|LOWER} CASE

2. ... USING pattern

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 pattern. The variable text must be character-type.

Note

There are two obsolete variants of this statement:

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.

Note

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 is entered. Data loss will occur if a conversion between the source and target language has not been defined. To avoid this type of inconsistency, you must appropriately set the text environment using the SET LOCALE statement prior to the conversion.

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 pattern

Effect

If you specify USING, the characters in text are converted according to the rule specified in pattern. pattern must be a character-type data object whose contents are interpreted as a sequence 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 pattern 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 pattern 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 pattern are taken into account for data objects. If pattern contains an uneven number of characters, the last character is ignored. If pattern is a blank string, no replacements take place.

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'.

TRANSLATE - CODE PAGE, NUMBER FORMAT

Variants:

1. TRANSLATE dobj [FROM CODE PAGE cp1] [TO CODE PAGE cp2].

2. TRANSLATE dobj [FROM NUMBER FORMAT nf1] [TO NUMBER FORMAT nf2].

Effect

Translation of the content of a data object to another code page or to another number format (byte sequence).

Variant 1

TRANSLATE dobj [FROM CODE PAGE cp1] [TO CODE PAGE cp2].

Effect

The character-like content of a data object dobj is translated from code page cp1 to code page cp2. If dobj does not have a character-like data type, no translation takes place. If dobj is a structure, only the components with character-like data type are translated. Apart form strings, no deep data objects can be specified for dobj.

When specifying the code pages cp1, cp2, data objects of data type n with the length 4 are expected, which upon execution of the statement must contain an SAP code page number of the column CPCODEPAGE in the database table TCP00.

At least one of the additions FROM CODE PAGE or TO CODE PAGE must be specified. If one of the additions is not included, the code page of the current system is used instead of the missing code page cp2 or cp2.

Variant 2

TRANSLATE dobj [FROM NUMBER FORMAT nf1] [TO NUMBER FORMAT nf2].

Effect

The platform-dependent numeric content of a data object dobj is translated from number format nf1 to number format nf2. If dobj is not of data type i or f, the translation does not take place. If dobj is a structure, only the components of the data type i or f are translated. Apart from strings, no deep data objects can be specified for dobj.

When specifying the number formats nf1, nf2, data objects of data type n with the length 4 are expected, which upon execution of the statement must contain either the value "0000" for the platforms HP, SINIX, IBM, or "0101" for the platform DEC-OSF.

At least one of the additions FROM NUMBER FORMAT or TO NUMBER FORMAT must be specified. If one of the additions is not used, the number format of the current platform is used instead of the missing number format nf1 or nf2.

Note

These variants of the TRANSLATE statement are not allowed in Unicode programs. Their functions are replaced with methods of the following conversion classes:

CL_ABAP_CONV_IN_CE

Reading data from a byte-like data object and converting from an external format to the system format.

CL_ABAP_CONV_OUT_CE

Converting data from the system format to an external format and writing in a byte-like data object.

CL_ABAP_CONV_X2X_CE

Converting data from an external format to another external format.

When opening legacy files in the ABAP file interface, you can directly convert during reading and writing files.

Example

Translating the components of a structure. The character-like component text is translated from the code page "1100" (HP-UX) to the code page "0100" (IBM- EBCDIC). The numeric component num is converted from the number format "0000" (for platforms by HP, IBM, or Siemens, for example) to the number format "0101" (for platforms provided by DIGITAL, for example).

DATA: BEGIN OF struc,

text(80) TYPE c LENGTH 80 VALUE 'I know You know',

num TYPE i VALUE 2505,

END OF struc.

TRANSLATE struc FROM CODE PAGE '1100'

TO CODE PAGE '0100'.

TRANSLATE struc FROM NUMBER FORMAT '0000'

TO NUMBER FORMAT '0101'.

Exceptions

Non-Catchable Exceptions

Cause: Invalid number format.

Runtime Error: TRANSLATE_WRONG_NUM_FORMAT

Read only

varma_narayana
Active Contributor
0 Likes
697

Hii Prajwal

TRANSLATE command has two uses

1. To convert a string to UPPER/LOWER Case.

Eg:

DATA : V_NAME(20) VALUE 'varma'.

Translate V_name to Upper case.

Write:/ V_name.

2. For replacing one set of characters with another set of characters.

Eg:

DATA: V_STR(20) VALUE 'CATRATBAT'.

TRANLATE V_STR USING 'AOTP'.

****Replaces all occurences of A with O and T with P

WRITE:/ V_STR.

      • the output will be COPROPBOP.

<b>reward if Helpful</b>

Read only

0 Likes
697

thanks to all

Regards

Prajwal.k