Switching Locales

You can switch from one locale to another any number of times while a program runs. This technique is useful for writing reports that use multiple currencies, or reports that have different sections for different locales.

To switch to another locale, use the ALTER-LOCALE command. For example, to switch to the Spanish locale:

alter-locale locale = 'Spanish'

From this point in the program, the locale is Spanish.

Consider this code example:

begin-procedure print_data_in_spanish
   ! Save the current locale
   let $old_locale = $sqr-locale
   ! Change the locale to "Spanish"
   alter-locale locale = 'Spanish'
   ! Print the data
   do print_data
   ! restore the locale to the previous setting
   alter-locale locale = $old_locale
end-procedure

In this code example, the locale is switched to Spanish and later restored to the previous locale before it was switched. To do that, the locale setting before it is changed is read in the$sqr-locale reserved variable and stored in $old_locale. The value of $old_locale is then used in the ALTER-LOCALE command at the end of the procedure.