2
votes

As the ABAP documentation of Formatting Settings explains:

The formatting settings are set as follows:

  • At the start of an internal session they are determined by the related default settings in the fixed values in the user master record of the current user.

  • Using the statement SET COUNTRY, this default setting for the current internal session can be overwritten using country-specific formats.

But as the ABAP documentation of SET COUNTRY makes clear, there is no way to query what's actually been set with this statement:

Do not confuse the statement SET COUNTRY with the obsolete addition COUNTRY of the statement SET LOCALE LANGUAGE, used for setting the text environment. In particular, it does not have a corresponding GET COUNTRY statement.

Indeed, the ABAP documentation of GET LOCALE - obsolete parameters mentions:

The addition COUNTRY was intended for reading the country key of the current text environment explicitly. cntry expects a character-like data object. The function of this addition was not implemented in full and the result is undefined.

The addition COUNTRY of the statement GET LOCALE does not extract the formatting setting that can be set using SET COUNTRY.

Which leaves me with a bit of a conundrum. I could determine my user defaults with FM SUSR_GET_USER_DEFAULTS. I could figure out the setting for the country from table T005X. But I have no way of figuring out which specific country format was set, or even if one was set in the active session!

How do I determine which formatting settings are currently active?

Bonus question: is there a way to figure this out in the Debugger?

2
Why do you need to know this - any special application requirement or just general developer curiosity? In most cases I've seen, it's not a question of checking what is set, just pick up the sledge hammer and enforce the setting you need :-)vwegert
@vwegert True, and I'm aware that the reason I need it is because I'm doing something I shouldn't be doing. :) Unfortunately I have to parse and analyse output data that's prepared for screen display from potentially dozens of different form sources. I'd obviously prefer to work with the source data but that's not an option and that means I have to figure out whether I'm dealing with a comma or a dot as a separator in my output values so I can convert numbers to floats. The issue then is that some sources will be using SET COUNTRY while some will rely on the user defaults.Lilienthal
How about the pragmatic approach of writing a know value, say '1000.00' to a string and checking the result?Gert Beukema
@GertBeukema That does indeed seem like the only reliable way of accomplishing this. I was rather hoping there was some obscure standard way of doing it to avoid such a kludge. :)Lilienthal

2 Answers

4
votes

Maybe you can use the function module CLSE_SELECT_USR01.

The following example:

REPORT test.

START-OF-SELECTION.
  DATA: decimal_sign , separator.

  PERFORM output.
  SET COUNTRY 'US'.
  PERFORM output.


FORM output.
  CALL FUNCTION 'CLSE_SELECT_USR01'
*   EXPORTING
*     USERNAME               = sy-uname
*     IV_DELETE_BUFFER       = ' '
    IMPORTING
*     X_USR01      =
*     DATE_FORMAT  =
      decimal_sign = decimal_sign
      separator    = separator.
  WRITE: / 'DECIMAL_SIGN', decimal_sign, 'separator', separator.
ENDFORM.

shows: enter image description here

My default locale is DE, so I get the actual setting for decimals.

From your comment:

Unfortunately I have to parse and analyse output data that's prepared for screen display from potentially dozens of different form sources.

Do you get the output at runtime or a previous run? Because there is no time machine to get the locale from a call in the past :)

2
votes

The ABAP statement SET COUNTRY may change the date format, the time format (since ABAP 7.02) and the number format, but there's officially no reverse way to get the current active country code (as you quoted in your question, based on the ABAP documentation). It's quite logical because, for instance, the current number format may be different from the current country code, so it's better to test the directly the kind of format you need to use, as follows.

  1. To detect the current date format, use the official way which returns a character, whose possible values are described in the ABAP documentation of Date Formats):

    DATA(current_date_format) = CL_ABAP_DATFM=>GET_DATFM( ).
    
  2. To detect the current time format, use the official way which returns a character:

    DATA(current_time_format) = CL_ABAP_TIMEFM=>GET_ENVIRONMENT_TIMEFM( ).
    

    It returns one of the following values, with an example value corresponding to noon + 5 minutes and 10 seconds (the example value is given if it's output on at least 11 characters):

    • 0 : 12:05:10 (0 to 23)
    • 1 : 12:05:10 PM (0 to 12)
    • 2 : 12:05:10 pm (0 to 12)
    • 3 : 00:05:10 PM (0 to 11)
    • 4 : 00:05:10 pm (0 to 11)
  3. To detect the current number format, based on the idea from @Gert Beukema, you may do as follows:

    DATA(current_number_format) = SWITCH usr01-dcpfm( 
                                  |{ 1000 NUMBER = ENVIRONMENT DECIMALS = 1 }| 
                                  WHEN '1.000,00' THEN ' '
                                  WHEN '1,000.00' THEN 'X'
                                  WHEN '1 000,00' THEN 'Y' ).
    

    NB: the values , X and Y which are returned by this expression are the same values as those used in tables-columns USR01-DCPFM and T005X-XDEZP.