Hi ,
use this one....
function module....
FUNCTION Z_CONVERT_AMOUNT_TO_WORDS.
*"----
""Local interface:
*" IMPORTING
*" VALUE(F_AMOUNT) LIKE KONV-KAWRT
*" VALUE(F_CURRENCY) LIKE EKKO-WAERS
*" EXPORTING
*" REFERENCE(WORDS) LIKE SPELL-WORD
*" EXCEPTIONS
*" ZERO_VALUE
*" INCORRECT_AMOUNT
*" AMOUNT_HIGH
*" INVALID_CURRENCY
*"----
tables : tcurt.
data: maxno type p.
data : words1 like SPELL.
SELECT SINGLE * FROM TCURt WHERE WAERS = F_CURRENCY
and SPRAS = 'EN'.
if sy-subrc <> 0.
raise invalid_currency.
endif.
if F_CURRENCY = 'INR'.
maxno = 10 ** 10.
if ( F_AMOUNT >= maxno ).
raise AMOUNT_HIGH.
endif.
data declaration----
data: ten(10),single(6),final(130),dec(20),res type i,rp(7).
data: a1 type i,a2 type i,str(20),d type p,m type i,wrdrep(20).
data: cntr type i,f1 type i,f2 type i,f3 type i,f4 type i,f5 type i.
data: f6 type i,f7 type i,f8 type i,f9 type i,f10 type i.
d = ( F_AMOUNT * 100 ) div 100.
res = ( F_AMOUNT * 100 ) mod 100.
if res > 100.
raise incorrect_amount.
endif.
f1 = res div 10.
f2 = res mod 10.
perform setnum using f1 f2 changing wrdrep.
f1 = 0. f2 = 0.
dec = wrdrep.
cntr = 1.
*Go in a loop dividing the numbers by 10 and store the
*residues as a digit in f1 .... f9
while ( d > 0 ).
m = d mod 10.
d = d div 10.
case cntr.
when 1. f1 = m.
when 2. f2 = m.
when 3. f3 = m.
when 4. f4 = m.
when 5. f5 = m.
when 6. f6 = m.
when 7. f7 = m.
when 8. f8 = m.
when 9. f9 = m.
when 10. f10 = m.
endcase.
cntr = cntr + 1.
endwhile.
cntr = cntr - 1.
*Going in loop and sending pair of digits to function setnum to get
*the standing value of digits in words
while ( cntr > 0 ).
if ( cntr <= 2 ).
perform setnum using f2 f1 changing wrdrep.
concatenate final wrdrep into final separated by ' '.
elseif ( cntr = 3 ).
if ( f3 <> 0 ).
perform setnum using 0 f3 changing wrdrep.
concatenate final wrdrep 'Hundred' into final separated by ' '.
endif.
elseif ( cntr <= 5 ).
if ( f5 <> 0 ) or ( f4 <> 0 ).
perform setnum using f5 f4 changing wrdrep.
concatenate final wrdrep 'Thousand' into final separated by ' '.
endif.
if ( cntr = 4 ).
cntr = 5.
endif.
elseif ( cntr <= 7 ).
if ( f7 <> 0 ) or ( f6 <> 0 ).
perform setnum using f7 f6 changing wrdrep.
concatenate final wrdrep 'Lakh' into final separated by ' ' .
endif.
elseif ( cntr <= 9 ).
perform setnum using f9 f8 changing wrdrep.
concatenate final wrdrep 'Crore' into final separated by ' ' .
elseif ( cntr = 10 ).
perform setnum using 0 f10 changing wrdrep.
concatenate final wrdrep 'Hundred' 'And' into final separated by ' '.
endif.
cntr = cntr - 2.
endwhile.
*Output the final
if ( final = ' One' ).rp = 'Rupee'.else. rp = 'Rupees'.endif.
if ( final = '' ) and ( dec = '' ).
final = 'NIL'.
elseif ( final = '' ).
concatenate 'Paise' dec 'Only' into final separated by ' ' .
elseif ( dec = '' ).
concatenate rp final 'Only' into final separated by ' ' .
else.
concatenate rp final 'Paise' dec 'Only' into final separated by ' '
.
endif.
words = final.
else.
call function 'SPELL_AMOUNT'
EXPORTING
AMOUNT = F_AMOUNT
CURRENCY = F_CURRENCY
FILLER = ' '
LANGUAGE = SY-LANGU
IMPORTING
IN_WORDS = words1
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
OTHERS = 3
.
if sy-subrc = 0.
words = words1-word. endif.
concatenate tcurt-ktext words 'Only' into words separated by ' '
.
endif.
endfunction.
&----
*& Form SETNUM
&----
converts a number into words *
----
--> a1,a2 two digits for 2nd and 1st place
<-- str outpur in words
----
data: ten(10),single(6),str(20).
*
form setnum using a1 a2 changing str.
ten = ''.single = ''.
if ( a1 = 1 ).
case a2.
when 0. ten = 'Ten'.
when 1. ten = 'Eleven'.
when 2. ten = 'Twelve'.
when 3. ten = 'Thirteen'.
when 4. ten = 'Fourteen'.
when 5. ten = 'Fifteen'.
when 6. ten = 'Sixteen'.
when 7. ten = 'Seventeen'.
when 8. ten = 'Eighteen'.
when 9. ten = 'Nineteen'.
endcase.
else.
case a2.
when 1. single = 'One'.
when 2. single = 'Two'.
when 3. single = 'Three'.
when 4. single = 'Four'.
when 5. single = 'Five'.
when 6. single = 'Six'.
when 7. single = 'Seven'.
when 8. single = 'Eight'.
when 9. single = 'Nine'.
endcase.
case a1.
when 2. ten = 'Twenty'.
when 3. ten = 'Thirty'.
when 4. ten = 'Forty'.
when 5. ten = 'Fifty'.
when 6. ten = 'Sixty'.
when 7. ten = 'Seventy'.
when 8. ten = 'Eighty'.
when 9. ten = 'Ninety'.
endcase.
endif.
if ( single <> '' ) and ( ten <> '' ).
concatenate ten single into str separated by ' '.
elseif single = ''.
str = ten.
else.
str = single.
endif.
endform. " SETNUM
cheers,
Simha.
<b>Reward all the helful answers...</b>
Add a comment