Application Development and Automation 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: 
Read only

SPELL_AMOUNT not working

Former Member
0 Likes
5,558

hi frends, in our import PO the PO amount is nt converted correctly to the words. For e.g : $ 4340.91

it is reading as "US DOLLAR four thousnad three hundered forty and nine thousand one hundered cents only "

the code in the smartforms is ok :

clear : W_T685T.

*data :l_effective like komv-kwert.
clear : l_effective.


loop at IT_T685T into W_T685T.
l_effective = l_effective + W_T685T-kwert.
endloop.

data : amount type P DECIMALS 4.
amount = l_effective.

if ZXEKKO-waers = 'INR'.


    CALL FUNCTION 'HR_IN_CHG_INR_WRDS'
      EXPORTING
        AMT_IN_NUM         = amount
      IMPORTING
        AMT_IN_WORDS       = in_words-word
      EXCEPTIONS
        DATA_TYPE_MISMATCH = 1
        OTHERS             = 2.

*increased length from 9 to 10


CALL FUNCTION 'ZMMF_HR_IN_CHG_INR_WRDS'
EXPORTING
AMT_IN_NUM         = amount
IMPORTING
AMT_IN_WORDS       = in_words-word
EXCEPTIONS
DATA_TYPE_MISMATCH = 1
OTHERS             = 2.
*end


else.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT    = amount
CURRENCY  = ZXEKKO-waers
LANGUAGE  = SY-LANGU
IMPORTING
IN_WORDS  = in_words
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
OTHERS    = 3.
endif.

select single * from TCURT into wa_tcurt where spras = sy-langu and WAERS =
ZXEKKO-waers.
condense in_words-word.
condense in_words-decword.

if ZXEKKO-waers <> 'INR'.
translate in_words-word to lower case.
translate in_words-decword to lower case.
translate in_words-word(1) to upper case.
concatenate wa_tcurt-ktext in_words-word 'and' in_words-decword 'only'
into in_words-word
separated by space.
find substring 'cents' in in_words-word.
if sy-subrc = 0.
replace substring 'cents' in in_words-word with space.
endif.

find substring 'only' in in_words-word.
if sy-subrc = 0.
replace substring 'only' in in_words-word with space.
endif.

concatenate in_words-word 'cents' 'only'
into in_words-word
separated by space.


else.
find substring 'Paise' in in_words-word.
if sy-subrc = 0.
replace substring 'Rupees' in in_words-word with 'and'.
else.
replace substring 'Rupees' in in_words-word with space.
endif.
translate in_words-word to lower case.
translate in_words-word+0(1) to upper case.
concatenate 'Rupees' in_words-word 'only' into in_words-word separated
by space.

endif.

plz help!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,852

Hi ,

Declare



data : amount type P DECIMALS 2.

Hope this resolves your issue.

hi frends, in our import PO the PO amount is nt converted correctly to the words. For e.g : $ 4340.91

it is reading as "US DOLLAR four thousnad three hundered forty and nine thousand one hundered cents only "

the code in the smartforms is ok :

clear : W_T685T.

*data :l_effective like komv-kwert.
clear : l_effective.


loop at IT_T685T into W_T685T.
l_effective = l_effective + W_T685T-kwert.
endloop.

data : amount type P DECIMALS 4.
amount = l_effective.

if ZXEKKO-waers = 'INR'.


    CALL FUNCTION 'HR_IN_CHG_INR_WRDS'
      EXPORTING
        AMT_IN_NUM         = amount
      IMPORTING
        AMT_IN_WORDS       = in_words-word
      EXCEPTIONS
        DATA_TYPE_MISMATCH = 1
        OTHERS             = 2.

*increased length from 9 to 10


CALL FUNCTION 'ZMMF_HR_IN_CHG_INR_WRDS'
EXPORTING
AMT_IN_NUM         = amount
IMPORTING
AMT_IN_WORDS       = in_words-word
EXCEPTIONS
DATA_TYPE_MISMATCH = 1
OTHERS             = 2.
*end


else.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT    = amount
CURRENCY  = ZXEKKO-waers
LANGUAGE  = SY-LANGU
IMPORTING
IN_WORDS  = in_words
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
OTHERS    = 3.
endif.

select single * from TCURT into wa_tcurt where spras = sy-langu and WAERS =
ZXEKKO-waers.
condense in_words-word.
condense in_words-decword.

if ZXEKKO-waers <> 'INR'.
translate in_words-word to lower case.
translate in_words-decword to lower case.
translate in_words-word(1) to upper case.
concatenate wa_tcurt-ktext in_words-word 'and' in_words-decword 'only'
into in_words-word
separated by space.
find substring 'cents' in in_words-word.
if sy-subrc = 0.
replace substring 'cents' in in_words-word with space.
endif.

find substring 'only' in in_words-word.
if sy-subrc = 0.
replace substring 'only' in in_words-word with space.
endif.

concatenate in_words-word 'cents' 'only'
into in_words-word
separated by space.


else.
find substring 'Paise' in in_words-word.
if sy-subrc = 0.
replace substring 'Rupees' in in_words-word with 'and'.
else.
replace substring 'Rupees' in in_words-word with space.
endif.
translate in_words-word to lower case.
translate in_words-word+0(1) to upper case.
concatenate 'Rupees' in_words-word 'only' into in_words-word separated
by space.

endif.

plz help!!

28 REPLIES 28
Read only

Former Member
0 Likes
4,852

Hi,

The problem is with your definition of the variable amount. You've defined it as


data : amount type P DECIMALS 4.

which means what you're actually passing to SPELL_AMOUNT is $ 4340.9100

Regards,

Nick

Read only

Former Member
0 Likes
4,853

Hi ,

Declare



data : amount type P DECIMALS 2.

Hope this resolves your issue.

Read only

0 Likes
4,852

Hi harsh thnx for help dear.But frend i hav already tried it. when i changed decimal 4 to 2 then the output for the same amount became :

*"US DOLLAR Forty three and four thousand ninety one cents only"*

Read only

0 Likes
4,852

Hi,

Having changed your code to define the amount variable as DEC 2 you need to debug the call of the function module SPELL_AMOUNT. If you are getting 'Forty three and four thousand ninety one cents' back then you are now most likely passing 43.4091 to the FM.

The problem is with the definition of the variables l_effective, W_T685T-kwert and amount. Debug the code that adds W_T685T-kwert to l_effective then moves it to amount, check the values to determine where the decimal places are being moved and change the definition of the variables to make this work.

Regards,

Nick

Read only

Former Member
0 Likes
4,852

HI,

USe this HR_IN_CHG_INR_WRDS replace rupees with dollars and Paise with cents.

Regards

Read only

0 Likes
4,852
where to replace rupee with dollars and paise with cents....

Plz elaborate ur answer I am just a beginner for ABAP

Read only

JL23
Active Contributor
0 Likes
4,852

have a look into the code of ABAP report RF_SPELL

you can execute it, it is a test program.

the write statements give you exact what you want, of course with 2 decimals

so you only need to add your Dollar and Cent words

Read only

Former Member
0 Likes
4,852

thnx frend , i have tried it but that report is reading it as :

FOUR THOUSAND THREE HUNDRED FORTY

NINE THOUSAND ONE HUNDRED

Read only

JL23
Active Contributor
0 Likes
4,852

>

> thnx frend , i have tried it but that report is reading it as :

>

>

>

FOUR THOUSAND THREE HUNDRED FORTY
> 
> NINE THOUSAND ONE HUNDRED

you get this nonsense because you submitted this: 4340.9100

I said you have to use 2 decimals: 4340.91

Read only

Former Member
0 Likes
4,852
Hi harsh thnx for help dear.But frend i hav already tried it. when i changed decimal 4 to 2 then the output for the same amount became :


*"US DOLLAR Forty three and four thousand ninety one cents only"*

i have already tried the case......but its nt working...also i have already specified that i have tried for 2 instad of 4 but it is not working.

Read only

JL23
Active Contributor
0 Likes
4,852

if that is the case, then this sample program from SAP must be wrong in your system. In that case you should open an incident at SAP.

But try it again.

I'll gibe you what I enter and what I receive

i enter:

keep your attention to the decimal notation, because we in Germany use the comma to seperate the decimals. (maybe this is causing your problem)


Langugae                         EN
Currency                         USD
Amount                                               4.340,91
Filler

I get:


              4.340,91  USD


ZERO   ZERO   ZERO   ZERO   ZERO   ZERO   ZERO   ZERO
ZERO   ZERO   ZERO   FOUR   THREE  FOUR   ZERO


FOUR THOUSAND THREE HUNDRED FORTY

NINETY-ONE


000000000004340 910

And here you just need to concatenate the field that holds "FOUR THOUSAND THREE HUNDRED FORTY " with dollar and the field that has "NINETY-ONE " with cent.

to get it into the form you want.

Read only

Former Member
0 Likes
4,852

thnx frend, it may be the problem.but when i tried the hard core value the i t is giving runtime error.

what i had one is that passed the value as you specified that is with comma.Then obvious runtime error occured

" Unable to interpret "4.340,91" as a number."

what should i do.

Read only

JL23
Active Contributor
0 Likes
4,852

just to be able to try it with 4.340,91 you can exchange the decimal format in your user setting in SU3 transaction.

However, if you keep your user setting as is, then you have to enter 4,340.91

and you should get the same result as I got, otherwise it is really an error in the program

Read only

Former Member
0 Likes
4,852

HI

use FM HR_IN_CHG_INR_WRDS if u give input 4340.91

u will get FOUR THOUSAND THREE HUNDRED FORTY Rupees NINETY ONE Paise

in this

replace all occurances of 'Rupees' with dollars.

replace all occurances of 'paise' with cents.

Read only

Former Member
0 Likes
4,852

hey man....thois would be true for amount in thousands only.....when i will increase the amount then it would convert it in indian format not in the format for reading US Dollars

Read only

Former Member
0 Likes
4,852

HI

use spell_amount FM in this following way.

try this

data lv_words(100)

CALL FUNCTION 'SPELL_AMOUNT'

EXPORTING\

AMOUNT = '4340.91'

CURRENCY = ' USD'

LANGUAGE = SY-LANGU

IMPORTING

IN_WORDS =wa_amt.

EXCEPTIONS

NOT_FOUND = 1

TOO_LARGE = 2

OTHERS = 3

CONCATENATE wa_amt-words 'DOLLARS' wa_amt-decword 'Cents' INto lv_words seprated by space.

Regards

Read only

Former Member
0 Likes
4,852

Hi,

see ZXEKKO-waers data in debugging mode. It should have value if the value is blank then u will get the problem you said .is shd not be blank at any time.

This is working fine for me

Regards

R

Read only

Former Member
0 Likes
4,852

friend how to use the debug mode.I am just a beginner.I have tried using smartform_trace but getting nothing usefull.Plz help me if i wanna check the value of ZXEKKO-waers in debug mode.

Read only

Former Member
0 Likes
4,852

Hi,

The problem is not with WAERS it is with variables l_effective, W_T685T-kwert and amount, but you still need to debug to find where it is setting the incorrect number of decimals in the value. This simplest way to start the debug (if this code is called from a smartform) is to set a break point.

If you need to know generally how to debug ask an experienced colleague or search this forum and the internet in general for beginners guides.

Regards,

Nick

Read only

Former Member
0 Likes
4,852

hey frend i got the value in debugging mode :

what i have done is.I placed "break-point" after FM of SPELL _AMOUNT and then press f8 to execute when i gt into the debugg mode i double clicked on the ZXEKKO-waers and the value showed in the window right of it is :

"00200020002000200020"

abve value was shown for ZXEKKO-waers under hexadecimal value and value for amount is

"000000000000000C"

this time i am using definition as

amount type p decimals 4

i hav also checked the value for "l-effective" :

000000000000000C

but one thing i noticed is that the technical type for the L-effective is

" P(7) DECIMALS 2 "

the value for "W_T685T-KWERT" is laos same and the technical type of it is also same as that of L-effective

Edited by: achalmehra on Jan 7, 2010 11:30 AM

Read only

Former Member
0 Likes
4,852

the technical type for p is :

P(8) DECIMALS 4

Read only

Former Member
0 Likes
4,852

the value for the ZXEKKO-waers is not sidpalyed in the debugging mode only the hexadecimal value is being displayed

Read only

JL23
Active Contributor
0 Likes
4,852

a purchase order cannot be without currency.

Check in ME23N if your document is really a PO (maybe it is just a request for quotation), and if there is a currency at header level in tab delivery/invoice.

This currency is either coming from vendor master or from your own company code customizing.

Read only

Former Member
0 Likes
4,852

yes friend i have checked that.It is a import PO and there is also currency key in the heder as expected but i dont know why in print preview we are facing this problem

Read only

JL23
Active Contributor
0 Likes
4,852

I personally do not trust the print preview in SAP. Print it to be certain.

debug your program to see when ZXEKKO-waers is updated and why it is different to EKKO-WAERS

you might call the function module to early or missed to update the ZXEKKO-waers

Read only

Former Member
0 Likes
4,852

hi jurgen,

i have passed hard core value to spell_amount like :

CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT    = '4310551.70'          "changed amount to var
CURRENCY  = ZXEKKO-waers
LANGUAGE  = SY-LANGU
IMPORTING
IN_WORDS  = in_words
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
OTHERS    = 3.
endif.

select single * from TCURT into wa_tcurt where spras = sy-langu and WAERS =
ZXEKKO-waers.
condense in_words-word.
condense in_words-decword.

if ZXEKKO-waers <> 'INR'.
translate in_words-word to lower case.
translate in_words-decword to lower case.
translate in_words-word(1) to upper case.
 concatenate wa_tcurt-ktext in_words-word 'and' in_words-decword 'only'
 into in_words-word
separated by space.
find substring 'cents' in in_words-word.
if sy-subrc = 0.
replace substring 'cents' in in_words-word with space.
endif.

find substring 'only' in in_words-word.
if sy-subrc = 0.
replace substring 'only' in in_words-word with space.
endif.

concatenate in_words-word 'cents' 'only'
into in_words-word
separated by space.



*  translate in_words-word to upper case.
*    translate in_words-word to lower case.
*    translate in_words-word(1) to upper case.
else.
find substring 'Paise' in in_words-word.
if sy-subrc = 0.
replace substring 'Rupees' in in_words-word with 'and'.
else.
replace substring 'Rupees' in in_words-word with space.
endif.
translate in_words-word to lower case.
translate in_words-word+0(1) to upper case.
concatenate 'Rupees' in_words-word 'only' into in_words-word separated
by space.

*    translate in_words-word to lower case.
*    translate in_words-word(1) to upper case.
endif.

still the o/p is : US DOLAR FORTY THRE THOUSAND ONE HUNDERED AND FIVE THOUSAND ONE HUNDERED SEVENTY CENTS ONY

Read only

Former Member
0 Likes
4,852

Hi

You can just use FM SPELL_AMOUNT, pass the amount and use the output WORD and DECWORD of IN_WORDS structure to build your amount in words.

IF you pass your amount of $4340.91, you will get

WORD - FOUR THOUSAND THREE HUNDRED FORTY

DECWORD- NINETY-ONE

Use: concatenate 'US Dollars' WORD 'Cents' DECWORD separated by space into lf_str.

Regards

Raj

Read only

Former Member
0 Likes
4,852

marked wrngly