Monday, May 13, 2013

Convert Number To words Using ABAP


Today I want to share some ABAP code samples that you can use to convert numbers or amount into words using SPELL_AMOUNT function module.

Here’s the ABAP Sample code:

data:
lw_spell LIKE spell,
saywords(150),
lv_text TYPE ltext,
p_amt TYPE eban-preis,
p_amt2(15),
p_waers type eban-waers.
START-OF-SELECTION.
p_amt = ’123450′.
p_waers = ‘USD’.
SELECT SINGLE ktext INTO lv_text
FROM tcurt
WHERE spras = sy-langu
AND waers = p_waers.
TRANSLATE lv_text to UPPER CASE.
CALL FUNCTION ‘SPELL_AMOUNT’
EXPORTING
amount = p_amt
currency = p_waers
filler = ‘ ‘
language = sy-langu
IMPORTING
in_words = lw_spell.
DATA: lv_cent TYPE spell.
lw_spell-decimal = lw_spell-decimal / 10.
IF lw_spell-decimal IS NOT INITIAL.
CALL FUNCTION ‘SPELL_AMOUNT’
EXPORTING
amount = lw_spell-decimal
* currency = lw_vbak-waerk
filler = ‘ ‘
language = sy-langu
IMPORTING
in_words = lv_cent.
ENDIF.

IF NOT lv_cent-word IS INITIAL.
CONCATENATE lw_spell-word ‘AND’ lv_cent-word ‘CENTS’
lv_text INTO saywords
SEPARATED BY space.
ELSE.
CONCATENATE lw_spell-word lv_text INTO saywords
SEPARATED BY space.
ENDIF.
WRITE p_amt to p_amt2 CURRENCY p_waers.
WRITE:/ p_amt2, saywords.
“end code

Run the program and you will see the number has been converted into words.
18-0ct-10-01

1 comment: