Oct 8, 2011

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

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 word and 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.

spell_amount function module

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

ABAP Spell Amount FM



2 comments :

yektek training said...

very useful information thank you

kpop said...

Thank you. Still helpful in 2018.