(SAP / ABAP) Group numbers and delete 0 (zero) before the value

I'm still new to ABAP and I want to know how to do this 1. digit Grouping 2. remove 0 before the value

  • grouping of numbers when I have a value for money, for example 3,000,000 (3 million), I want to print 3,000,000 on the screen (there is a dot every three characters from the last character)

  • Delete 0 (zero) before the value when I select a value from the table and print it on the screen, the value gets 0 on the left side Exam database value: 129, when I put it in the internal table and print it, it becomes 0000129

Thank you comrade

+4
source share
4 answers

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

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

Please note that this does not interpret the number itself, but simply adds commas and periods to certain positions depending on the currency you specify. Therefore, if you have an integer with a value of 3000000 , and you write it using the USD currency, the result will be 30.000,00 .

I suggest you read the F1 help information in the WRITE instruction, as there are many more options besides this.

-

Leading zeros are removed using the conversion procedure. CONVERSION_EXIT_ALPHA_INPUT will add leading zeros, and CONVERSION_EXIT_ALPHA_OUTPUT will remove them. You can add these routines to the domain in the dictionary, so the conversion will be performed automatically. For example, type MATNR :

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

This will lead to conclusion 129 , because in the MATNR domain the specified conversion procedure.

In the case of a type that 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 procedure to achieve a result without leading zeros:

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

To remove zero fill use the NO-ZERO instruction. For the thousandth separator, I see no problem, because this is the standard way that ABAP prints values ​​of type P. Here is an example 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 outputs the result.

 000000129 3.000.000,00 129 3.000.000,00 
+1
source

Also note that the output conversion for numeric types initiated by the WRITE statement is controlled by the property in the user master data. The decimal separator and grouping of digits must be configured there.

You can verify this in the user's main transactions, for example. SU01 or SU01D.

+1
source

To remove leading zeros, you can do the following:

 data: lv_n type n length 10 value '129'. shift lv_n left deleting leading '0'. 
0
source

All Articles