SET LOCALE

Short Reference

Syntax

SET LOCALE LANGUAGE lang [COUNTRY cntry] [MODIFIER mod].

Extras:

1. ... COUNTRY cntry

2. ... MODIFIER mod

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. For lang, a character-type (and before release 6.10 flat) data object must be specified. 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 COUNTRY and MODIFIER 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 entered in lang, and a country key must be entered 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 codepage of a Unicode system is always UTF-16 and is not influenced by the statement SET LOCALE. After SET LOCALE is executed, however, the non-Unicode codepage 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 explicity, 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 codepage from the column CHARCO. If no entry exists in the table TCP0C for the specified key, a treatable exception results.

The codepage specified by the key in TCP0C must be released as as a system codepage for the current SAP system. Otherwise a treatable exception will occur. This results in different consequences for single codepage systems and MDMP systems:

A non-Unicode codepage can be released as a system codepage by entering the SAP codepage number in the database table TCPDB, which is maintained 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.

Addition 1

... COUNTRY cntry

Effect:

The text environment is country-specific. By default, the country key is used that is associated with the language specified in lang in the database table TCP0D. The country key can also be explictly specified using the addition COUNTRY . For cntry, a character-type (before release 6.10 flat) data object is used that contains a country key with a maximum of three characters.

Note:

The addition COUNTRY should not be used. If possible, the implicitly set country key should be used instead.

Addition 2

... MODIFIER mod

Effect:

The addition MODIFIER is currently not required and should be omitted. If it is specified, a character-type (and before release 6.10 flat) data object with a maximum of eight characters should be used, which is ignored anyway.

Note:

The addition MODIFIER is intended for setting different locales for a language within a country, for example, for sorting according to different sort criteria. The SAP standard system does not currently support >locales.

Notes:

Examples:

Effect of the locale of the text environment on sorting: In Unicode and non-Unicode systems, "ch" is interpreted as a single letter in a Spanish (or, for example, Czech) text environment, and is thus sorted in a different way than in an English text environment. In a Spanish text environment in a Unicode system, a double "ll" is sorted as two separate letters. In non-Unicode systems, however, Spanish locales can be used, (for example Spanish_Spain.1252 on Windows NT), which interpret "ll" as a single character and sort it accordingly. The last SET LOCALE statement can be used to reset the text environment to the logon language.

DATA text_tab TYPE HASHED TABLE OF string
              WITH UNIQUE KEY table_line.

INSERT: `polo`    INTO TABLE text_tab,
        `pollo`   INTO TABLE text_tab,
        `chunky`  INTO TABLE text_tab,
        `crunchy` INTO TABLE text_tab.

SET LOCALE LANGUAGE 'E'.
SORT text_tab AS TEXT.
PERFORM write_text_tab.

SET LOCALE LANGUAGE 'S'.
SORT text_tab AS TEXT.
PERFORM write_text_tab.

SET LOCALE LANGUAGE ' '.

FORM write_text_tab.
  FIELD-SYMBOLS <line> TYPE string.
  LOOP AT text_tab ASSIGNING <line>.
    WRITE / <line>.
  ENDLOOP.
  SKIP.
ENDFORM.

Effect of the codepage of the text environment on the statement TRANSLATE ... TO UPPER CASE: In Unicode systems, content of text that is coded according to UTF-16 ("00E400F600FC") is converted in the same way in all text environments ("00C400D600DC"). In non-Unicode single codepage systems the program triggers an exception, because different codepages belong to the language keys "E" and "R" (SAP codepage numbers 1100 and 1500). In MDMP systems in which the codepages 1100 and 1500 are released, the binary content of text ("E4F6FC" in codepage 1100) is converted differently according to the codepage. In a text environment with the codepage 1100, the characters are interpreted as umlauts. In a text environment with the codepage 1500, these are cyrillic characters. When converting to upper case, the system searches in the codepage for the appropriate character according to the text environment, and converts it accordingly. The result for codepage 1100 is "C4D6DC", and for codepage 1500 is "C4A6AC".

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

ASSIGN text TO <hex> CASTING.
text = 'äöü'.
WRITE / <hex>.

SET LOCALE LANGUAGE 'E'.
TRANSLATE text TO UPPER CASE.
WRITE / <hex>.

text = 'äöü'.
SET LOCALE LANGUAGE 'R'.
TRANSLATE text TO UPPER CASE.
WRITE / <hex>.

SET LOCALE LANGUAGE ' '.

Exceptions

Catchable Exceptions

CX_SY_LOCALIZATION_ERROR

Non-Catchable Exceptions