简体   繁体   English

确定 ABAP 中的活动格式设置

[英]Determining the active formatting settings in ABAP

As the ABAP documentation of Formatting Settings explains:正如格式设置ABAP 文档所解释的那样:

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 .使用语句 SET COUNTRY,可以使用特定于国家/地区的格式覆盖当前内部会话的此默认设置。

But as the ABAP documentation of SET COUNTRY makes clear, there is no way to query what's actually been set with this statement:但正如SET COUNTRYABAP 文档所阐明的那样,无法查询此语句实际设置的内容:

Do not confuse the statement SET COUNTRY with the obsolete addition COUNTRY of the statement SET LOCALE LANGUAGE, used for setting the text environment.不要将语句 SET COUNTRY 与用于设置文本环境的语句 SET LOCALE LANGUAGE 的过时添加 COUNTRY 混淆。 In particular, it does not have a corresponding GET COUNTRY statement.特别是,它没有相应的 GET COUNTRY 语句。

Indeed, the ABAP documentation of GET LOCALE - obsolete parameters mentions:事实上, GET LOCALEABAP 文档 - 过时的参数提到:

The addition COUNTRY was intended for reading the country key of the current text environment explicitly.添加 COUNTRY 旨在明确读取当前文本环境的国家/地区键。 cntry expects a character-like data object. cntry 需要一个类似字符的数据对象。 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.语句 GET LOCALE 的添加 COUNTRY 不会提取可以使用 SET COUNTRY 设置的格式设置。

Which leaves me with a bit of a conundrum.这让我有点困惑。 I could determine my user defaults with FM SUSR_GET_USER_DEFAULTS .我可以使用 FM SUSR_GET_USER_DEFAULTS确定我的用户默认值。 I could figure out the setting for the country from table T005X .我可以从表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?额外问题:有没有办法在调试器中解决这个问题?

Maybe you can use the function module CLSE_SELECT_USR01 .也许您可以使用功能模块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.我的默认语言环境是 DE,所以我得到了小数的实际设置。

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 :)因为过去没有时间机器从电话中获取语言环境:)

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). ABAP 语句SET COUNTRY可能会更改日期格式、时间格式(自 ABAP 7.02 起)和数字格式,但官方没有获得当前活动国家/地区代码的反向方法(正如您在问题中引用的那样,基于 ABAP 文档)。 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 ):要检测当前日期格式,请使用返回字符的官方方法,其可能值在日期格式ABAP 文档中描述):

     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):它返回以下值之一,示例值对应于中午 + 5 分 10 秒(如果输出至少 11 个字符,则给出示例值):

    • 0 : 12:05:10 (0 to 23) 0 : 12:05:10 (0 到 23)
    • 1 : 12:05:10 PM (0 to 12) 1 : 12:05:10 下午(0 到 12)
    • 2 : 12:05:10 pm (0 to 12) 2 : 12:05:10 pm (0 到 12)
    • 3 : 00:05:10 PM (0 to 11) 3 : 00:05:10 PM(0 到 11)
    • 4 : 00:05:10 pm (0 to 11) 4 : 00:05:10 pm (0 到 11)
  3. To detect the current number format , based on the idea from @Gert Beukema, you may do as follows:要检测当前数字格式,基于@Gert Beukema 的想法,您可以执行以下操作:

     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 .此表达式返回的XY与表列USR01-DCPFMT005X-XDEZP使用的值相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM