Google Search - Blog...........

ABAP - Currency Formatting in SAP Scripts


REQUIREMENT

We have to display amount i.e., WRBTR (4,500.00) from the table BSEG (Accounting Document Segment) in the format 450,000 where the document number (BELNR) and plant (BUKRS) are as specified in the selection screen. Invoice gets generated for the country Korea when we enter the document number and plant as 1600000000 and 3040. But unlike the reports, SAP SCRIPT by default displays the amount with two decimal places. This results in displaying incorrect amount for different countries. We cannot use the keyword 'CURRENCY' while coding inside the SAP Script. Then how can we achieve the currency formatting using SAP Scripts? This can be done by setting correct currency reference, using database structures that have amount field with currency references. This is explained in detail as follows.

SOLUTION

For an example, consider a structure called KOMK (Pricing Communication Header). It has two fields i.e., the currency reference field and the amount field.

1. WAERK - SD document currency (Description)
DATA TYPE: CUKY, LENGTH: 5.
2. FKWRT- Net value in document currency (Description)
DATA TYPE: CURR, LENGTH: 15.
In the report, we manipulate the amount to be displayed on the SAP Script i.e., WF_AMOUNT. It is written as shown below.
* Data Declaration.
DATA: WF_AMOUNT LIKE KOMK-FKWRT.
* Coding part (hard coded the value for simplicity)
SELECT SINGLE *FROM BSEG
WHERE BELNR = '1600000000' and
BUKRS = '3040' and
BUZID = '' and
KOART = 'S'.
WF_AMOUNT = BSEG-WRBTR.
KOMK-WAERK = 'KRW'.
(OR)
If BSEG structure has a field for currency reference, we can use the same structure for displaying amount in respective format.
* Data Declaration.
DATA: WF_AMOUNT LIKE BSEG-WRBTR.
* Coding part
WF_AMOUNT = BSEG-WRBTR.
BSEG-PSWSL = 'KRW'.

Then in SAP script, print as follows

,,Amount,,&wf_Amount&
OUTPUT:
Amount 450,000

No comments:

Post a Comment