Tip

Formatting currency in SAPscript

Currency formatting is easy in reports, with the "currency" option in the statement.

But in SAPscript, when no currency reference is set for an amount field, default formatting of two decimal places will occur. This may sometimes be unacceptable -- especially with exceptional currencies like

    Requires Free Membership to View

'JPY', 'KRW', 'LUF', 'TND,' etc. The default formatting affects not only the number of decimal places, but also the position of decimal point, which results in wrong amounts being displayed on the output.

This can be prevented by setting the correct currency reference, using database structures that have amount fields with currency references. The amount has to be populated in a structure's amount field and proper currency key in the currency reference field and then using the structure's amount field in the layout set rather than using a global variable of type P.

(e.g. Use of KOMK-FKWRT for populating the amount and KOMK-WAERK for holding the corresponding currency key. This will use the currency reference relation defined in the structure KOMK.)

NOTE: This formatting works similarly even for the global variables defined with like reference to structure's amount field when the amount field's currency reference field is populated with the required currency key.
 

Driver Program
* Data Declaration
DATA: NET_AMOUNT LIKE KOMK- FKWRT.


* Code: KOMK- FKWRT = 234.50. NET_AMOUNT = 987.65. KOMK-WAERK = 'JPY'
Layout &KOMVD-KERT& => The output will be 23450 &NET_AMOUNT& => The output will be 98765
&KOMVD-KERT& would have been printed as 234.50 if the currency key (KOMK-WAERK) were USD and as 23.450 if the currency key (KOMK-WAERK) were TND.

This was first published in October 2005

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.