Determining the active formatting settings in ABAP

前端 未结 2 718
一生所求
一生所求 2021-01-15 05:24

As the ABAP documentation of Formatting Settings explains:

The formatting settings are set as follows:

  • At the start of an internal sessio

相关标签:
2条回答
  • 2021-01-15 06:00

    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.

    0 讨论(0)
  • 2021-01-15 06:04

    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:

    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 :)

    0 讨论(0)
提交回复
热议问题