You are on page 1of 2

How to Spell Numbers using ABAP Spell_Amount Function Module

SAP professionals can use ABAP Spell_Amount function module in order to spell numbers and currency values into string variables. It is very easy in different languages the answer of "How to Spell Numbers in SAP" using Spell_Amount ABAP function module. In this ABAP tutorial, developers will find a sample ABAP report using Spell_Amount to convert numeric value or currency amount entered in the selection screen into string and display on the screen using Write command. I frequently use SPELL_AMOUNT function module to display gross amount or total value in words on SAP Smartform output of invoice records. What makes Spell_Amount perfect for spelling price, amount fields and number values is it can spell in different languages. The Spell_Amount function module excepts a Language input parameter and returns the spell in the input language. Either German, English, Turkish, Spanish, Russian, ABAP developers can easily return decimal values and integer part of the number seperately easily. Since the Spell_Amount return a SPELL type structure, developers should be aware of both fields wordand decword of the output structure. The decword will return limited values from 0 to 99 for example. But the integer part word can handle greater numeric values.

Here is the ABAP report source code that ABAP developers can use in order to convert numeric values, numbers and currencies into string. The following ABAP report is using Spell_Amount in order to spell numbers into string variables and display on the output screen. PARAMETERS: pLANGU LIKE T002-SPRAS DEFAULT SY-LANGU, pCURR LIKE TCURC-WAERS DEFAULT 'USD', pAMOUNT LIKE VBAP-MWSBP , pFILLER(1) TYPE C DEFAULT ' '.

DATA : WS_SPELL TYPE SPELL.

CALL FUNCTION 'SPELL_AMOUNT' EXPORTING AMOUNT = pAMOUNT CURRENCY = pCURR FILLER = pFILLER LANGUAGE = pLANGU "SY-LANGU

IMPORTING IN_WORDS = WS_SPELL EXCEPTIONS NOT_FOUND = 1 TOO_LARGE = 2 OTHERS = 3 . IF sy-subrc <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ELSE. WRITE :/ WS_SPELL-word , WS_SPELL-decword. ENDIF. Here is the selection screen of the ABAP report ZSPELLAMOUNT.

And this is the output screen displaying the spelling of input number value in given language

If you also want to display the currency code, for example USD or UAH, you can use VBRK-WAERK for example. And concatenate WAERK field with WS_SPELL-word and WS_SPELL-decword spelled amount text. It is also possible to query SAP table TCURT using ABAP SELECT statement as seen below for short name of the document currency. SELECT SINGLE * FROM TCURT WHERE WAERS = pCURR And then you can use the TCURT-KTEXT field for currency text instead of displaying WAERK field directly.

You might also like