Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

SPELL_AMOUNT not i want

Former Member
0 Kudos

hi,

currently my smartform for invoice printout, the amount in word display, is by performing with FM :SPELL_AMOUNT. however, the output i have is not what i want.

example: the amount is MYR 71,200.00

actual output : Seven Hundred Twelve Thousand Only.

i want the output to be as below:

Seventy One Thousand Two Hundred Only.

how am i going to do so? is there a FM suite on this?

please help. thanks

13 REPLIES 13

varma_narayana
Active Contributor
0 Kudos

Hi ..

The FM is <b>SPELL_AMOUNT </b>only for this Req.

Try with the proper value.

reward if Helpful.

Former Member
0 Kudos

Try HR_IN_CHG_INR_WRDS function module.

data: amt type PC207-BETRG.

data : AMT_IN_WORDS(40) type c.

parameters : p_amt like PC207-BETRG.

CALL FUNCTION 'HR_IN_CHG_INR_WRDS'

EXPORTING

amt_in_num = p_amt

IMPORTING

AMT_IN_WORDS = AMT_IN_WORDS

  • EXCEPTIONS

  • DATA_TYPE_MISMATCH = 1

  • OTHERS = 2

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

write:/ AMT_IN_WORDS.

Hope this helps.

ashish

Former Member
0 Kudos

hi ,

use this FM 'HR_IN_CHG_INR_WRDS'

reward points if useful

0 Kudos

hi,

thank, the amount in word worked. however, it show aas rupees. which i dont want. because this is in malaysia ringgit. any way to do so?

0 Kudos

Hi,

Here is the working code for this fm. I have added two zeros after the number and it is working fine. If you just enter 21130, it will show wrong result.

data: l_string LIKE SPELL.

CALL FUNCTION 'SPELL_AMOUNT'

EXPORTING

AMOUNT = '21130.00'

CURRENCY = 'MYR'

FILLER = ' '

LANGUAGE = SY-LANGU

IMPORTING

IN_WORDS = l_string

  • EXCEPTIONS

  • NOT_FOUND = 1

  • TOO_LARGE = 2

  • OTHERS = 3

.

Hope this helps.

ashish

0 Kudos

hi,

i already mentioned, that 'SPELL_AMOUNT' does not shows result i want. is there any other existing FM or ways to do so? thanks

0 Kudos

Bee,

It is working correct for me, even when i pass ',' in the amount -

data: l_string LIKE SPELL.

CALL FUNCTION 'SPELL_AMOUNT'

EXPORTING

AMOUNT = '21,130.00'

CURRENCY = 'MYR'

FILLER = ' '

LANGUAGE = SY-LANGU

IMPORTING

IN_WORDS = l_string.

  • EXCEPTIONS

  • NOT_FOUND = 1

  • TOO_LARGE = 2

  • OTHERS = 3

check sy-subrc eq 0.

What problem are you facing? Other than this fm, i believe there is no other fm available for this requirement.

ashish

0 Kudos

Use following code for amount conversion...

report zrept_rupee_conversion .

data: begin of gtab,

result(5) type c, index type i,

end of gtab.

data: begin of giritab,

res1(20),

end of giritab.

data: begin of giriline,

result(20) type c,index type i,

end of giriline.

data: begin of girijtab,

result(20) type c, index type i,

end of girijtab.

data: begin of common part variables,

number type zkwert,

ans(250),

init(17), initnam(1), initno type i , init1(17),

cnam1(14), cnam2(1), cnam3(20),cnam4(200), point(2),jpoint,

kpoint,lpoint1(10), lpoint2(10),lpoint(30),fpoint,

cnt1 type i, cnt2 type i, cnt3 type i,

flhun, flth, flla, flcr1,flcr2, flchu1, flchu2, flpt, res(5),

itab like gtab occurs 0 with header line,

line like giriline ,

ktab like giritab occurs 0 with header line,

jtab like girijtab occurs 0 with header line,

end of common part variables.

&----


*& Form COVERSION1

&----


form coversion1 using number changing ans.

clear: gtab,

giritab,

giriline,

girijtab,

line ,

ans,

init, initnam, initno , init1,

cnam1, cnam2, cnam3,cnam4, point,jpoint,

kpoint,lpoint1, lpoint2,lpoint,fpoint,

cnt1 , cnt2, cnt3 ,

flhun, flth, flla, flcr1,flcr2, flchu1, flchu2, flpt, res.

refresh :

itab ,

ktab ,

jtab .

init = number.

init1 = init.

cnt1 = strlen( init ).

cnt2 = cnt1 - 1.

do cnt1 times.

initnam = init+0(1).

shift init by 1 places left.

if initnam = '.'.

cnam1 = init1+0(initno).

endif.

initno = initno + 1.

enddo.

do cnt1 times.

cnam2 = init1+0(1).

shift init1 by 1 places left.

if cnam2 = '.'.

point = init1+0(2).

exit.

endif.

enddo.

do 2 times.

jpoint = point+0(1).

shift point by 1 places left.

if sy-index = 1.

kpoint = point.

endif.

perform points.

enddo.

cnt1 = strlen( cnam1 ).

do cnt1 times.

cnam2 = cnam1+0(1).

perform calcu .

shift cnam1 by 1 places left.

enddo.

sort itab descending by index.

loop at itab.

if sy-tabix = 1.

jtab-result = itab-result.

jtab-index = itab-index.

append jtab.

else.

if itab-result = 'One ' and ( sy-tabix = 2 or sy-tabix = 5 or

sy-tabix = 7 or sy-tabix = 9 ).

perform teens.

move space to line-result.

modify jtab from line index cnt3 transporting result .

else.

if itab-result <> space.

perform ties.

else.

jtab-result = itab-result.

jtab-index = itab-index.

append jtab.

endif.

endif.

endif.

cnt3 = sy-tabix.

res = itab-result.

endloop.

skip.

loop at jtab.

case sy-tabix.

when 10.

if jtab-result <> space.

if flcr1 = 'X' and flcr2 = 'X'.

concatenate jtab-result 'Hundred Crores' into line-result

separated by ' '.

modify jtab from line index sy-tabix transporting result.

else.

concatenate jtab-result 'Hundred AND' into line-result

separated by ' '.

modify jtab from line index sy-tabix transporting result.

endif.

endif.

when 9.

if flcr1 = 'X'.

if jtab-result <> space.

concatenate jtab-result 'Crores' into line-result

separated by ' '.

modify jtab from line index sy-tabix transporting result.

else.

flcr2 = 'X'.

endif.

endif.

when 8.

if jtab-result <> space.

concatenate jtab-result 'Crores' into line-result

separated by ' '.

modify jtab from line index sy-tabix transporting result.

else.

flcr1 = 'X'.

endif.

when 7.

if flla = 'X'.

if jtab-result <> space.

concatenate jtab-result 'Lacs' into line-result

separated by ' '.

modify jtab from line index sy-tabix transporting result.

endif.

endif.

when 6.

if jtab-result <> space.

concatenate jtab-result 'Lacs' into line-result

separated by ' '.

modify jtab from line index sy-tabix transporting result.

else.

flla = 'X'.

endif.

when 5.

if jtab-result <> space.

if flth = 'X'.

concatenate jtab-result 'Thousand' into line-result

separated by ' '.

modify jtab from line index sy-tabix transporting result.

endif.

endif.

when 4.

if jtab-result <> space.

concatenate jtab-result 'Thousand' into line-result

separated by ' '.

modify jtab from line index sy-tabix transporting result.

else.

flth = 'X'.

endif.

when 3.

if jtab-result <> space.

if flchu1 = 'X' and flchu2 = 'X'.

concatenate jtab-result 'Hundred' into line-result

separated by ' '.

else.

concatenate jtab-result 'Hundred AND' into line-result

separated by ' '.

endif.

modify jtab from line index sy-tabix transporting result.

else.

flhun = 'X'.

endif.

when 2.

if jtab-result = space.

flchu2 = 'X'.

endif.

when 1.

if jtab-result = space.

flchu1 = 'X'.

endif.

endcase.

endloop.

*SORT JTAB ASCENDING BY INDEX.

loop at jtab.

if sy-tabix = 1.

cnam4 = jtab-result.

else.

concatenate jtab-result cnam4 into cnam4 separated by space.

endif.

endloop.

if lpoint2 = space and lpoint1 = space.

lpoint = 'only'.

else.

concatenate 'Paise' lpoint2 lpoint1 'only' into lpoint separated by

space.

endif.

if cnam4 <> space.

shift cnam4 left deleting leading space.

concatenate 'Rupees' cnam4 lpoint into ans separated by space.

*WRITE : / 'RUPEES', CNAM4.

*WRITE : / ANS.

endif.

endform. "COVERSION1

*WRITE : / LPOINT NO-GAP.

form ties.

jtab-index = itab-index.

if sy-tabix = 2 or sy-tabix = 5 or sy-tabix = 7 or sy-tabix = 9.

case itab-result.

when 'Two '.

jtab-result = 'Twenty'.

when 'Three'.

jtab-result = 'Thirty'.

when 'Four '.

jtab-result = 'Fourty'.

when 'Five '.

jtab-result = 'Fifty'.

when 'Six '.

jtab-result = 'Sixty'.

when 'Seven'.

jtab-result = 'Seventy'.

when 'Eight'.

jtab-result = 'Eighty'.

when 'Nine '.

jtab-result = 'Ninety'.

when space.

jtab-result = space.

endcase.

else.

jtab-result = itab-result.

endif.

append jtab.

endform. "TIES

&----


*& Form TEENS

&----


  • text

----


form teens.

jtab-index = itab-index.

case res.

when 'One '.

jtab-result = 'Eleven'.

when 'Two '.

jtab-result = 'Twelve'.

when 'Three'.

jtab-result = 'Thirteen'.

when 'Four '.

jtab-result = 'Fourteen'.

when 'Five '.

jtab-result = 'Fifteen'.

when 'Six '.

jtab-result = 'Sixteen'.

when 'Seven'.

jtab-result = 'Seventeen'.

when 'Eight'.

jtab-result = 'Eighteen'.

when 'Nine '.

jtab-result = 'Nineteen'.

when space.

jtab-result = 'Ten'.

endcase.

append jtab.

endform. "TEENS

&----


*& Form CALCU

&----


  • text

----


form calcu .

itab-index = sy-index.

case cnam2.

when '1'.

itab-result = 'One'.

when '2'.

itab-result = 'Two'.

when '3'.

itab-result = 'Three'.

when '4'.

itab-result = 'Four'.

when '5'.

itab-result = 'Five'.

when '6'.

itab-result = 'Six'.

when '7'.

itab-result = 'Seven'.

when '8'.

itab-result = 'Eight'.

when '9'.

itab-result = 'Nine'.

when '0'.

itab-result = space.

endcase.

append itab.

endform. "CALCU

&----


*& Form POINTS

&----


  • text

----


form points.

if sy-index = 2.

if fpoint = space.

case jpoint.

when '1'.

lpoint1 = 'One'.

when '2'.

lpoint1 = 'Two'.

when '3'.

lpoint1 = 'Three'.

when '4'.

lpoint1 = 'Four'.

when '5'.

lpoint1 = 'Five'.

when '6'.

lpoint1 = 'Six'.

when '7'.

lpoint1 = 'Seven'.

when '8'.

lpoint1 = 'Eight'.

when '9'.

lpoint1 = 'Nine'.

when '0'.

lpoint1 = space.

endcase.

endif.

endif.

if sy-index = 1.

case jpoint.

when '1'.

perform lpointy.

when '2'.

lpoint2 = 'Twenty'.

when '3'.

lpoint2 = 'Thirty'.

when '4'.

lpoint2 = 'Forty'.

when '5'.

lpoint2 = 'Fifty'.

when '6'.

lpoint2 = 'Sixty'.

when '7'.

lpoint2 = 'Seventy'.

when '8'.

lpoint2 = 'Eighty'.

when '9'.

lpoint2 = 'Ninety'.

when '0'.

lpoint2 = space.

endcase.

endif.

endform. "POINTS

&----


*& Form LPOINTY

&----


  • text

----


form lpointy.

case kpoint.

when '1'.

lpoint2 = 'Eleven'.

when '2'.

lpoint2 = 'Twelve'.

when '3'.

lpoint2 = 'Thirteen'.

when '4'.

lpoint2 = 'Fourteen'.

when '5'.

lpoint2 = 'Fifteen'.

when '6'.

lpoint2 = 'Sixteen'.

when '7'.

lpoint2 = 'Seventeen'.

when '8'.

lpoint2 = 'Eighteen'.

when '9'.

lpoint2 = 'Nineteen'.

when '0'.

lpoint2 = 'Ten'.

endcase.

lpoint1 = space.

fpoint = 'X'.

endform. "LPOINTY

<b>manipulate this report to get the desired output...</b>

<b>call this report in your SAP Script calling report to convert the amount in words...</b>

e.g.

perform coversion1(zrept_rupee_conversion) using l_amount changing l_words.

0 Kudos

Hi Ben,

Pass only 71,200 in place of 71,200.00 in FM 'SPELL_AMOUNT'.

u will get desired output.

actually if u pass 71,200.00 then it also considers zeros after decimal.

so truncate it as any decimal encounters and then pass it to FM.

Regards,

Hemant

0 Kudos

hi,

for FM "SPELL-AMOUNT"

the output for let say $71,200.00 will be

SEVEN HUNDRED TWELVWE THOUSAND ONLY.

i this is not the case. this is for US standard. i want the output to be

SEVENTY ONE THOUSAND TWO HUNDRED ONLY.

so i am wondering is there any existing FM or program for this? else will it be very hard to create a program on this? or any way to do it?

thanks

0 Kudos

Are you passing correct currency to this function module?

Because i am getting same output as you have explained.

ashish

0 Kudos

try the code given above...

it'l give desired results...

Former Member
0 Kudos

Hi,

I think it is better u write a fresh function module for this...

Sample code is shown below.

You can incorporate and no: of currency type to this..

FUNCTION znew_spell_amount.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(CURRENCY) LIKE SY-WAERS

*" VALUE(AMOUNT)

*" EXPORTING

*" VALUE(IN_WORDS)

*" EXCEPTIONS

*" ERROR

*"----


DATA wrk_decimal(20).

CALL FUNCTION 'SPELL_AMOUNT'

EXPORTING

amount = amount

currency = currency

filler = ' '

language = sy-langu

IMPORTING

in_words = spell

EXCEPTIONS

not_found = 1

too_large = 2

OTHERS = 3.

IF sy-subrc NE 0.

RAISE error .

ENDIF .

----


SELECT SINGLE * FROM tcurc

WHERE waers = currency .

CHECK sy-subrc EQ 0.

SELECT SINGLE * FROM tcurt

WHERE waers = currency

AND spras = 'E' .

CHECK sy-subrc EQ 0.

SET LOCALE LANGUAGE sy-langu.

SET LOCALE LANGUAGE space.

TRANSLATE tcurt-ktext TO UPPER CASE.

*----


CASE tcurc-waers.

WHEN 'USD'.

wrk_decimal = 'AND CENTS'.

WHEN 'INR'.

wrk_decimal = 'AND PAISE'.

  • when 'ITL'.

  • when 'JPY'.

  • Add new curr.s here

WHEN OTHERS.

wrk_decimal = 'AND DECIMALS'.

ENDCASE.

----


IF spell-decword = 'ZERO'.

CONCATENATE

spell-word

'ONLY'

INTO in_words SEPARATED BY space .

ELSE.

CONDENSE wrk_decimal.

CONCATENATE tcurt-ktext

spell-word

wrk_decimal

spell-decword

'ONLY'

INTO in_words SEPARATED BY space .

ENDIF.

----


ENDFUNCTION.

reward points if helpful.

Thanks and Regards,

Litta