How To Convert Amount In Words In SAP ABAP

Convert amount to words, Means user enter amount in currency and this currency amount convert to word. For an example: In India, user enter 250 means 250 rupees and this amount convert to word in Two Hundred Fifty rupees.

In SAP ABAP, Use amount to word conversion in different places as per the client requirement. Now this days, More clients are required total amount converted into amount in word. In SAP ABAP use different function module to perform in this type of conversion amount to word. Follows some Examples of this conversions.


convert-amount-words-sap-abap-decoderp


Example - 1 :

Using of HR_IN_CHG_INR_WRDS Function Module

In this example user enter a amount as a number and output is show both user entered amount and converted amount in word.

DATA: WORD TYPE CHAR100.

PARAMETERS NUMBER TYPE PC207-BETRG.
NUMBER = '2378'.

CALL FUNCTION 'HR_IN_CHG_INR_WRDS'
    EXPORTING
      AMT_IN_NUM = NUMBER
    IMPORTING
      AMT_IN_WORDS = WORD
    EXCEPTIONS
      DATA_TYPE_MISMATCH = 1
      OTHERS = 2 .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

write: 'Number: ',number,/,'In Word: ',word.


Output:

Number: 2378 In Word: two thousand three hundred seventy-eight

Explanation:

In this example, keyword 'Number' is a variable that store amount, those amount do you want to convert and data type of this variable is PC207-BETRG. keyword 'Word' is a variable that store converted amount in word and data type of this variable is char or string , if you declare other data type then some time have you show error message or dump. If you does not want to convert Indian rupees to word , but you want other country amount. So, follow the next example .

Example - 2 :

If you want to convert any country amount as like USD, INR, EUR amount. So use this function module.

Using of SPELL_AMOUNT Function Module

In this example user enter a amount as a number, billing document number, billing date and output is show converted amount in word.

tables: vbrk.

DATA: IN_WORDS TYPE SPELL,
          LV_AW         TYPE CHAR100. ""final output store in the variable

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: so_fkdat FOR vbrk-fkdat,
                                so_vbeln FOR vbrk-vbeln.
SELECTION-SCREEN END OF BLOCK b1.

select single vbeln,fkdat,waerk into @data(wa_vbrk) from vbrk where vbeln in @so_vbeln and fkdat in @so_fkdat.

CALL FUNCTION 'SPELL_AMOUNT' """" TO CONVERT AMOUNT INTO WORDS """""
     EXPORTING
          AMOUNT = '3120.56' " Amount or Total Amount
         CURRENCY = WA_VBRK-WAERK " Currency key
         LANGUAGE = SY-LANGU
     IMPORTING
         IN_WORDS = IN_WORDS
     EXCEPTIONS
         NOT_FOUND = 1
         TOO_LARGE = 2
        OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

IF SY-SUBRC EQ 0.

IF WA_VBRK-WAERK = 'EUR' .

CONCATENATE IN_WORDS-WORD 'Euro and' IN_WORDS-DECWORD 'Cents Only' INTO LV_AW SEPARATED BY SPACE.

ELSEIF WA_VBRK-WAERK = 'USD' .

CONCATENATE IN_WORDS-word 'Dollar and' IN_WORDS-DECWORD 'Cents Only' INTO LV_AW SEPARATED BY space.

ELSEIF WA_VBRK-WAERK = 'INR' .

CONCATENATE IN_WORDS-WORD 'Rupees and' IN_WORDS-DECWORD 'Paisa Only' INTO LV_AW SEPARATED BY SPACE.

ELSEIF WA_VBRK-WAERK = 'GBP' .

CONCATENATE IN_WORDS-WORD 'Pounds and' IN_WORDS-DECWORD 'Pence Only' INTO LV_AW SEPARATED BY SPACE.

ELSEIF WA_VBRK-WAERK = 'MYR' .

CONCATENATE IN_WORDS-WORD 'Ringgit and' IN_WORDS-DECWORD 'Cents Only' INTO LV_AW SEPARATED BY SPACE.

ELSEIF WA_VBRK-WAERK = 'AUD' .

CONCATENATE IN_WORDS-WORD 'Aussie and' IN_WORDS-DECWORD 'Cents Only' INTO LV_AW SEPARATED BY SPACE.

ENDIF.
ENDIF.

write : 'Amount in word is ', LV_AW.

Output:(Assume Currency key is USD and this program use AMOUNT = '3120.56'.)

Amount in word is : three thousand one hundred twenty Dollars and fifty-six Cents Only


More related SAP ABAP posts:

Post a Comment

0 Comments