ABAP Keyword Documentation →  ABAP − Reference →  Program Parameters →  Language Environment →  Text Environment → 

SET LOCALE LANGUAGE  Syntax Diagram

Short Reference

Syntax

SET LOCALE LANGUAGE lang [obsolete_parameters].

Effect

This statement defines the text environment for all programs of the current internal session for the languages specified in lang, and sets sy-langu to the value of lang. The statement has two obsolete additions COUNTRYand MODIFIER that should no longer be used.

lang expects a character-like data object. This must contain a language key with a maximum length of one character, and this value must be contained in the column SPRAS of the database table T002. If the data object lang only contains blank characters, the logon language of the current user is used and the additions are ignored.

The statement SET LOCALE has a different effect depending on whether the system is a Unicode system or a non-Unicode system.

Setting the Text Environment in a Unicode System

In a Unicode system, a language key must be specified in lang, and a country key must be specified in cntry, for which locale properties must be defined in the ICU library of the application server. The possible language keys are contained in the SPRAS column of the database table T002. The locale of the text environment is set accordingly, and influences how internal tables and extracts are sorted using the statement SORT with the addition AS TEXT.

The code page of a Unicode system is always UTF-16 (the ABAP programming language supports the subset UCS-2) and is not influenced by the statement SET LOCALE. After SET LOCALE is executed, however, the non-Unicode code page that would be set by the statement in a non-Unicode system (see below), is used for specific statements such as reading and writing legacy files for conversions.

Setting the Text Environment in a Non-Unicode System

In a non-Unicode system, the language key specified in lang, combined with the current operating system of the application server (system field sy-opsys) and the country key taken explicitly from the database table TCP0D or set explicitly, must produce a valid key for the database table TCP0C. This key is used to extract the name of the operating system specific locale from the column LOCALE and the number of the non-Unicode code page from the column CHARCO. If no entry exists in the table TCP0C for the specified key, a handleable exception is raised.

The code page specified by the key in TCP0C must be released as as a system code page for the current AS ABAP. Otherwise a handleable exception is raised. This has different consequences for single code page systems and MDMP systems:

A non-Unicode code page can be released as a system code page by entering the SAP code page number in the database table TCPDB, which is edited using the executable program RSCPINST. If the database table TCPDB is empty, it is handled as if it contains a single entry with the number 1100.

Programming Guideline

If possible, do not switch the text environment within the coding

Notes

Example

This example demonstrates the effect of the code page of the text environment on the statement TRANSLATE ... TO UPPER CASE: In Unicode systems, the content of text ("00E400F600FC") that is coded in accordance with UCS-2 is transformed in the same way in all text environments ("00C400D600DC"). In non-Unicode single code page systems, the program raises an exception, because different code pages are associated with the language keys "E" and "R" (SAP code page numbers 1100 and 1500). In MDMP systems in which the code pages 1100 and 1500 are released, the binary content of text ("E4F6FC" in codepage 1100) is converted differently according to the code page. In a text environment with the code page 1100, the characters are interpreted as umlauts. In a text environment with the code page 1500, these are Cyrillic characters. When converting to uppercase, the system searches in the code page for the appropriate character according to the text environment, and converts it accordingly. The result for code page 1100 is "C4D6DC", and for code page 1500 is "C4A6AC".

DATA text TYPE c LENGTH 3.
FIELD-SYMBOLS <hex> TYPE x.

ASSIGN text TO <hex> CASTING.
text = 'äöü'.
cl_demo_output=>write( <hex> ).

SET LOCALE LANGUAGE 'E'.
TRANSLATE text TO UPPER CASE.
cl_demo_output=>write( <hex> ).

text = 'äöü'.
SET LOCALE LANGUAGE 'R'.
TRANSLATE text TO UPPER CASE.
cl_demo_output=>write( <hex> ).

SET LOCALE LANGUAGE ' '.

cl_demo_output=>display( ).

Exceptions

Catchable Exceptions

CX_SY_LOCALIZATION_ERROR

Non-Catchable Exceptions