ABAP Keyword Documentation → ABAP − Reference → Language Environment → Language Settings → Text Environment Language and Text Environment
SET LOCALE LANGUAGE
Other versions: 7.31 | 7.40 | 7.54
Syntax
SET LOCALE LANGUAGE lang [obsolete_parameters].
Effect
This statement sets the text environment language of the current
internal session to the value specified in lang
. This configures the
text environment for all programs in the internal session.
The text environment language
lang
expects a character-like data object containing a language key (with a maximum of one character) for which
locale properties are defined
in the ICU library of the AS ABAP. The possible language keys are contained in the SPRAS column of the
database table T002. The locale of the text environment is set accordingly. If the data object lang
contains only blanks, the
logon language of the current
user session is used.
The statement SET LOCALE LANGUAGE
sets the no-modifiable
code page of the text environment. In a Unicode system, this is always
UTF-16 (and the ABAP programming language supports the subset
UCS-2). After SET
LOCALE LANGUAGE 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.
(See the additions LEGACY
,
and NON-UNICODE
of the statement OPEN DATASET
.)
If possible, this non-Unicode code page is taken from the column CHARCO of the database table TCP0C. The key used here is created from the current operating system of the
host computer of the
current AS Instance (system field sy-opsys
), the language key specified in lang
, and a language ID set implicitly from the database table TCP0D or
set explicitly.
System Fields
If the statement SET LOCALE LANGUAGE
is executed successfully, it sets the
system field sy-langu
to the value specified in lang
.
Programming Guideline
If possible, do not switch the text environment within the code
Notes
-
The text environment of an internal session should only be changed for the following purposes:
- Processing character-like data objects that are in a different language to the logon language of
the current user. The text environment language is important for the statements
SORT ... AS TEXT
andCONVERT TEXT
.
- Legacy files can be read and written.
- After processing in a changed text environment, the text environment should be reset to the previous text environment.
-
The statement
SET LOCALE LANGUAGE
sets the text environment language specified insy-langu
and returned by the method GET_LANGUAGE of the class CL_ABAP_SYST. It does not set the logon language returned by the method GET_LOGON_LANGUAGE. -
Do not confuse the statement
SET LOCALE LANGUAGE
with the statementSET LANGUAGE
, used for loading the texts of a text pool. -
Instead of the
SET LOCALE
statement, the four function modules whose names begin with SCP_MIXED_LANGUAGES_ can also be used to define or change the current text environment, and to reset it to the original text environment. -
The statement has two obsolete additions,
COUNTRY
andMODIFIER
, which should no longer be used.
Example
Sets the text environment to a valid value.
DATA langu TYPE sy-langu.
cl_demo_input=>request( CHANGING field = langu ).
TRY.
SET LOCALE LANGUAGE langu.
CATCH cx_sy_localization_error INTO DATA(exc).
cl_demo_output=>write( exc->get_text( ) ).
ENDTRY.
cl_demo_output=>display(
|Logon language: { cl_abap_syst=>get_logon_language( )
}\nText environment language: { cl_abap_syst=>get_language( )
}\nsy-langu: { sy-langu }| ).
Executable Example
Exceptions
Handleable Exceptions
CX_SY_LOCALIZATION_ERROR
-
Cause: Using the tables TCP0D and TCP0C, a character set was detected that
is not released in your system. The released character sets are in the table TCPDB. Normally this table
contains exactly one character set and this runtime error occurs because the system has attempted to use a non-compatible language.
Runtime error:TEXTENV_CODEPAGE_NOT_ALLOWED
-
Cause: No entry exists (for the current platform) in the SAP text environment
table TCP0C for the specified keys
lang
,cntry
, andmod
.
Runtime error:TEXTENV_KEY_INVALID
Non-Handleable Exceptions
-
Cause: Selection of a 'binary' text environment using the modifier
'BINARY',
'C'
,'POSIX'
, or'RAW'
.
Runtime error:TEXTENV_BINARY_NOT_SUPPORTED
-
Cause: One of the key values
lang
,cntry
, ormod
is longer than the corresponding fields LANGU, COUNTRY, or MODIFIER in the SAP text environment table TCP0C.
Runtime error:TEXTENV_KEY_TOO_LONG