Handling Errors in Locale Operations
- DEFAULT locale
- CURRENT locale
- Specific locales.
SPECIAL-NAMES. LOCALE "MYLOCALE" IN LIBRARY "MYLIB" IS newlocale.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 group-item.
05 num-edit PIC $99.99 SIZE 8 LOCALE newlocale.
PROCEDURE DIVISION.
MOVE 40 to num-edit.
In the above example a specific locale mnemonic-name newlocale
has
been defined. This mnemonic-name is used in the definition of variable num-edit
. Since the mnemonic-name is referenced in the program, the
first time the above program is called, the ILE COBOL runtime tries to find the
locale MYLOCALE
in library MYLIB
and load it into memory.
- Locale does not exist in the specified library
- Library for locale does not exist
- Not enough authority to the locale or locale library.
These types of failures are typical of most other IBM i objects. In any of the above scenarios an escape message (usually LNR7096) is issued. Once a locale object is located it must be loaded by the ILE COBOL run-time. Loading a locale object requires the allocation of various spaces, if space is not available an escape message is issued (usually LNR7070).
SPECIAL-NAMES. LOCALE "ALOCALE" IS alocale.
DATA DIVISION.
WORKING-STORAGE SECTION.
O1 group-item.
05 num-edit PIC +$9(4).99 SIZE 10 LOCALE alocale.
* num-edit2 is based on the current locale
05 num-edit2 PIC +$9(4).99 SIZE 10 LOCALE.
05 locale-name PIC X(10) VALUE "FRANCE".
05 locale-lib PIC X(10) VALUE "MYLIB".
MOVE 345.67 TO num-edit.
* set the current locale to "ALOCALE" in library "*LIBL".
SET LOCALE LC_ALL FROM alocale.
MOVE 678.02 TO num-edit2.
* set the current locale to "FRANCE" in library "MYLIB".
SET LOCALE LC_ALL FROM locale-name
IN LIBRARY locale-lib.
MOVE 678.02 TO num-edit2.
The first form references a locale mnemonic-name in the SPECIAL-NAMES paragraph,
and just like in the previous example is resolved and loaded the first time
the program is called. In the second SET statement, the locale name is taken
from the contents of identifier locale-name
and the library where
the locale exists is taken from the contents of identifier locale-lib
. In this case the resolve and load of the locale object is done
when the SET statement is run. With this form of the SET statement if the
locale can not be resolved an escape message (usually LNR7098) is issued.
It is issued for the same type of reasons as LNR7096 mentioned previously.