对货币中的数字进行分组并删除前导零

发布于 2024-12-11 13:09:37 字数 231 浏览 1 评论 0原文

我想知道

  1. 如何进行数字分组

当我物有所值时

  1. ,例如 3000000(300 万)我想在屏幕上打印 3.000.000(从最后一个字符开始每三个字符有一个点)删除值前面的零

当我从表中选择一个值并将其打印在屏幕上时,该值会自动用零填充:例如 129 变为 0000129

I want to know how to do

  1. digit grouping

when I have value for money for example 3000000 ( 3million) i want to print 3.000.000 on the screen (there is a dot every three character from the last character)

  1. Remove zeroes in front of value

when I select a value from table and print it on the screen, the value get padded with zeroes automatically: e.g. 129 becomes 0000129

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

海之角 2024-12-18 13:09:37

WRITE 语句允许您指定货币。示例:

DATA price TYPE p DECIMALS 2.
price = '3000000'.
WRITE: / price CURRENCY 'USD'.

请注意,这不会解释数字本身,而只是根据您指定的货币在某些位置添加逗号和点。因此,如果您有一个值为 3000000 的整数,并且用货币 USD 写入它,则结果将是 30.000,00

我建议你阅读关于WRITE语句的F1帮助信息,因为除了这个之外还有很多选项。

--

删除前导零是通过使用转换例程来完成的。
CONVERSION_EXIT_ALPHA_INPUT 将添加前导零,CONVERSION_EXIT_ALPHA_OUTPUT 将删除它们。
可以将这些例程添加到字典中的域中,因此转换将自动完成。例如 MATNR 类型:

DATA matnr TYPE matnr.
matnr = '0000129'.
WRITE: / matnr.

这将输出 129,因为域 MATNR 指定了转换例程。

例如,对于没有此类型的类型:

DATA value(7) TYPE n.
value = '0000129'.
WRITE: / value.

输出将为 0000129。您可以调用 CONVERSION_EXIT_ALPHA_OUTPUT 例程来实现不带前导零的输出:

DATA value(7) TYPE n.
value = '0000129'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
  EXPORTING
    input  = value
  IMPORTING
    output = value.
WRITE: / value.

The WRITE statement allows you to specify a currency. Example:

DATA price TYPE p DECIMALS 2.
price = '3000000'.
WRITE: / price CURRENCY 'USD'.

Note that this does not interpret the number itself, but just adds commas and dots at certain positions depending on the currency you specify. So in the event you have an integer with the value of 3000000 and you write it with currency USD the result will be 30.000,00.

I suggest you read the F1 help information on the WRITE statement, because there are a lot more options besides this one.

--

Removing leading zeroes is done by using a conversion routine.
The CONVERSION_EXIT_ALPHA_INPUT will add leading zeroes and CONVERSION_EXIT_ALPHA_OUTPUT will remove them.
It is possible to add these routines to a Domain in the dictionary, so the conversion will be done automatically. For example the MATNR type:

DATA matnr TYPE matnr.
matnr = '0000129'.
WRITE: / matnr.

This will output 129 because the Domain MATNR has a conversion routine specified.

In the case of a type which does not have this, for example:

DATA value(7) TYPE n.
value = '0000129'.
WRITE: / value.

The output will be 0000129. You can call the CONVERSION_EXIT_ALPHA_OUTPUT routine to achieve the output without leading zeroes:

DATA value(7) TYPE n.
value = '0000129'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
  EXPORTING
    input  = value
  IMPORTING
    output = value.
WRITE: / value.
天涯沦落人 2024-12-18 13:09:37

另请注意,由 WRITE 语句触发的类数字类型的输出转换由用户主数据中的属性控制。
应在那里配置小数分隔符和数字分组。

您可以在用户主事务中检查这一点,例如 SU01 或 SU01D。

Please also note that output conversion for numberlike types - triggered by the WRITE statement - is controlled by a property in the user master data.
Decimal separator and digit grouping should be configured there.

You could check this in the user master transactions e.g. SU01 or SU01D.

尐籹人 2024-12-18 13:09:37

要删除零填充,请使用 NO-ZERO 语句。对于千位分隔符,我没有看到任何问题,因为它是 ABAP 打印 P 类型值的标准方式。下面是示例代码。

REPORT  ZZZ.

DATA:
  g_n TYPE n LENGTH 10 VALUE '129',
  g_p TYPE p LENGTH 12 DECIMALS 2 VALUE '3000000'.

START-OF-SELECTION.
  WRITE /: g_n, g_p.
  WRITE /: g_n NO-ZERO, g_p.

这会产生输出。

000000129
           3.000.000,00
      129
           3.000.000,00

For removing the zero padding use NO-ZERO statement. For the thousand separator I do not see any problem because it is a standard way ABAP prints values of type P. Here is a sample code.

REPORT  ZZZ.

DATA:
  g_n TYPE n LENGTH 10 VALUE '129',
  g_p TYPE p LENGTH 12 DECIMALS 2 VALUE '3000000'.

START-OF-SELECTION.
  WRITE /: g_n, g_p.
  WRITE /: g_n NO-ZERO, g_p.

This produces the output.

000000129
           3.000.000,00
      129
           3.000.000,00
能否归途做我良人 2024-12-18 13:09:37

要删除前导零,您可以执行以下操作:

data: lv_n type n length 10 value '129'.

shift lv_n left deleting leading '0'.

For removing leading zeros, you can do the following:

data: lv_n type n length 10 value '129'.

shift lv_n left deleting leading '0'.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文