Locale considerations
A locale is a collection of language-specific and culture-specific conventions for information processing. A locale makes information about language and culture available at run time so that the same program can display or process data differently for different countries or cultures.
For additional information about locales and the details of setting locales for specific languages and cultures, see Setting the locale in the COBOL for Linux on x86 Programming Guide.
Compile-time versus runtime locale
In general, the COBOL run time determines the locale in effect when the COBOL application is activated. However, the following processing is based on the locale in effect at compile time:
- Evaluation
of user-defined names and literal values
The compiler uses the code page indicated by the locale in effect at compile time to evaluate the source program. This includes the evaluation of user-defined names and literal values.
When a literal value is associated with a data item such that code page conversion is required, the code page in effect at run time is used for the data item. For an item of class alphanumeric with native ASCII encoding, the code page indicated by the locale in effect at run time is used. For an item of class alphanumeric with EBCDIC encoding, the EBCDIC code page in effect at run time is used.
- Evaluation of collating
sequences
When the COLLSEQ(LOCALE) compiler option or the NCOLLSEQ(LOCALE) compiler option is in effect, the compile-time locale determines the following values:
- The
range of characters specified by literals in a THRU phrase
for the following language elements:
- A condition-name VALUE clause
- An EVALUATE statement
- An ALPHABET clause in the SPECIAL-NAMES paragraph
- A CLASS clause in the SPECIAL-NAMES paragraph
- The ordinal positions of characters specified in a SYMBOLIC CHARACTERS clause
- The
range of characters specified by literals in a THRU phrase
for the following language elements:
The following sections describe the effects of locales on COBOL runtime processing.
Code pages
The runtime locale is used to determine:
- The code page for the encoding of alphanumeric and DBCS data items that have native (non-EBCDIC) encoding. The EBCDIC code page in effect is used when the CHAR(EBCDIC) compiler option is specified, the EBCDIC_CODEPAGE environment variable is not set, and the data item is described without the NATIVE phrase.
- Case mappings for the UPPER-CASE and LOWER-CASE intrinsic functions
- The output code page for the DISPLAY-OF intrinsic function when a codepage argument is omitted. The EBCDIC code page in effect is used when the CHAR(EBCDIC) compiler option is specified, the EBCDIC_CODEPAGE environment variable is not set, and the data item is described without the NATIVE phrase.
- The source code page for the NATIONAL-OF intrinsic function when a codepage argument is omitted. The EBCDIC code page in effect is used when the CHAR(EBCDIC) compiler option is specified, the EBCDIC_CODEPAGE environment variable is not set, and the data item is described without the NATIVE phrase.
- The code page for conversion of data for accepting into data items of usage NATIONAL with the ACCEPT statement
- The code page for conversion of data for displaying from data items of usage NATIONAL with the DISPLAY statement
Two runtime code pages can be in effect: one for native data (non-EBCDIC data) and one for host data (EBCDIC data). For information about how these runtime code pages are determined, see Specifying the code page for character data in the COBOL for Linux on x86 Programming Guide.
Collating sequences
In general, COBOL for Linux® uses the collating sequence defined by the runtime locale when the COLLSEQ(LOCALE) compiler option or the NCOLLSEQ(LOCALE) compiler option is in effect. COLLSEQ(LOCALE) affects alphanumeric and DBCS data items; NCOLLSEQ(LOCALE) affects items described with USAGE NATIONAL.
When COLLSEQ(BINARY) or NCOLLSEQ(BINARY) is specified, a binary collating sequence is used.
In some cases, the language rules specify the use of a non-locale collating sequence regardless of the setting of the COLLSEQ or NCOLLSEQ compiler option. For example:
- A binary collating sequence is always used for indexed file keys.
- A collating sequence specified in the PROGRAM COLLATING SEQUENCE clause of the OBJECT-COMPUTER paragraph is used for alphanumeric comparisons.
- A collating sequence specified in the PROGRAM COLLATING SEQUENCE clause of the OBJECT-COMPUTER paragraph is used for SORT or MERGE statements with alphanumeric keys, unless the COLLATING SEQUENCE phrase is specified in the SORT or MERGE statement.
- A collating sequence specified in the COLLATING SEQUENCE phrase of a SORT or MERGE statement is used for alphabetic keys and alphanumeric keys.
Supported locales
COBOL for Linux supports locales for certain combinations of language, country, and code page. System environment variables identify the runtime locale in effect for specific locale categories. For details, see Using environment variables to specify a locale in the COBOL for Linux on x86 Programming Guide.