确定 ABAP 中的活动格式设置 [英] Determining the active formatting settings in ABAP

查看:24
本文介绍了确定 ABAP 中的活动格式设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为 ABAP 文档格式设置说明:

格式设置如下:

  • 在内部会话开始时,它们由当前用户的用户主记录中的固定值中的相关默认设置确定.

使用语句 SET COUNTRY,当前内部会话的此默认设置可以使用特定于国家/地区的格式覆盖.

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

但作为 ABAP 文档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 COUNTRY 与语句 SET LOCALE LANGUAGE 的过时添加 COUNTRY 混淆,用于设置文本环境.特别是,它没有对应的 GET COUNTRY 语句.

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.

确实,ABAP 文档GET LOCALE - 过时的参数 提到:

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

附加的 COUNTRY 旨在明确读取当前文本环境的国家/地区键.cntry 需要一个类似字符的数据对象.这个加法的功能没有完全实现,结果未定义.

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.

语句 GET LOCALE 的添加 COUNTRY 不会提取可以使用 SET COUNTRY 设置的格式设置.

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

这让我有点困惑.我可以使用 FM SUSR_GET_USER_DEFAULTS 确定我的用户默认值.我可以从表 T005X 中找出国家的设置.但我无法确定设置了哪个特定的国家/地区格式,甚至是否在活动会话中设置了!

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!

额外问题:有没有办法在调试器中解决这个问题?

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

推荐答案

ABAP 声明 SET COUNTRY 可能会改变日期格式、时间格式(从 ABAP 7.02 开始)和数字格式,但官方没有反向方法获取当前活动的国家/地区代码(如您在问题中引用的,基于 ABAP 文档).这很合乎逻辑,因为例如当前的数字格式可能与当前的国家/地区代码不同,因此最好直接测试您需要使用的格式类型,如下所示.

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. 要检测当前的日期格式,请使用返回字符的官方方式,其可能的值在ABAP 日期格式文档):

  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( ).

  • 要检测当前的时间格式,使用返回一个字符的官方方式:

  • To detect the current time format, use the official way which returns a character:

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

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

    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 到 23)
    • 1 : 12:05:10 PM(0 到 12)
    • 2 : 12:05:10 pm(0 到 12)
    • 3 : 00:05:10 PM(0 到 11)
    • 4 : 00:05:10 pm(0 到 11)

    要检测当前的数字格式,基于@Gert Beukema 的想法,您可以执行以下操作:

    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' ).
    

    注意:此表达式返回的值 XY 与表列中使用的值相同 <代码>USR01-DCPFM 和 T005X-XDEZP.

    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.

    这篇关于确定 ABAP 中的活动格式设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆