on 09-04-2007 10:40 AM
hi all,
I m having a requirement in which i need to put 'and' in between the converted string which i m getting as o/p from spell_amount FM.
e.g. if i give as 1234.00 its giving me as one thousend two hundred thirty four.
But i should print as one thousend two hundred AND thirty four. I can get it through finding string 'hundred' in the o/p and after that i can concatenate AND, but problem is if there are multiple occurences of ' Hundred' if m facing a problem.
Please help.
Points will be rewarded accordingly.
Hi hussain,
Try this logic,
i think it will work
CONSTANTS: c_100 TYPE c LENGTH 7 VALUE 'HUNDRED'.
DATA: gv_words TYPE spell,
lv_words TYPE spell,
lv_words1 TYPE string.
PARAMETER:lv_amnt TYPE dmbtr.
DATA:lv_amn TYPE string,
var1 TYPE string,
var2 TYPE string,
lv_last TYPE string,
am1 TYPE dmbtr,
am2 TYPE dmbtr.
IF lv_amnt > 1000.
lv_amn = lv_amnt / 1000.
SPLIT lv_amn AT '.' INTO var1 var2.
am1 = var1.
am1 = am1 * 1000.
am2 = lv_amnt MOD 1000.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
amount = am1
currency = 'INR'
FILLER = ' '
LANGUAGE = SY-LANGU
IMPORTING
in_words = gv_words
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
lv_words1 = gv_words-word.
IF am2 IS NOT INITIAL.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
amount = am2
currency = 'INR'
FILLER = ' '
LANGUAGE = SY-LANGU
IMPORTING
in_words = lv_words
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
if lv_words-word is not initial.
CONCATENATE lv_words1 'AND' lv_words-word INTO lv_last SEPARATED BY space.
else.
lv_last = lv_words1.
ENDIF.
ELSEIF lv_amnt > 100.
lv_amn = lv_amnt / 100.
SPLIT lv_amn AT '.' INTO var1 var2.
am1 = var1.
am1 = am1 * 100.
am2 = lv_amnt MOD 100.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
amount = am1
currency = 'INR'
FILLER = ' '
LANGUAGE = SY-LANGU
IMPORTING
in_words = gv_words
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
lv_words1 = gv_words-word.
IF am2 IS NOT INITIAL.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
amount = am2
currency = 'INR'
FILLER = ' '
LANGUAGE = SY-LANGU
IMPORTING
in_words = lv_words
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
if lv_words-word is not initial.
CONCATENATE lv_words1 'AND' lv_words-word INTO lv_last SEPARATED BY space.
else.
lv_last = lv_words1.
ENDIF.
ELSE.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
amount = lv_amnt
currency = 'INR'
FILLER = ' '
LANGUAGE = SY-LANGU
IMPORTING
in_words = lv_words
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
lv_last = lv_words-word.
ENDIF.
WRITE: lv_last.
Regards
Antony Thomas
reward points if it is helpfull for you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
will the function module spell_amount work for a case where we have a value
say 1234.56, I think it will not work, so how to solve this issue.
The function module spell_amount will work but there is
some limitation to it as well.
for e.g: if amount is '6000' it will read as six thousand.
if amount is '6078',it will read as six thousand
seventy-eight.
but for 6000.78,it will read as six hundred
thousand seventy-eight.
<b>So, how get out of this problem ??</b>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks all.
I got the solution using following code.
SEARCH lv_word FOR 'HUNDRED'.
IF sy-subrc = 0 AND sy-fdpos NE 0.
SPLIT lv_word AT 'HUNDRED' INTO lv_word1 lv_word2 lv_word3.
IF lv_word2 NE ' '.
CONCATENATE lv_word1 ' HUNDRED' lv_word2 ' HUNDRED AND' lv_word3 INTO lv_final.
ELSEIF lv_word1 NE ' '.
CONCATENATE lv_word1 ' HUNDRED AND' lv_word2 INTO lv_final.
ELSE.
lv_final = lv_word.
ENDIF.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There might me some other way but try like this... it will solve your problem(it suits your requirement)
Data : num1 type i.
Data: num2 type i.
DATA : T_SPELL LIKE SPELL OCCURS 0 WITH HEADER LINE.
Data:spell(255).
Data : dummy(50).
DATA: field(3) VALUE 'AND',
len TYPE I.
Num1 = '1234'.
num2 = num1 mod 100. "num1 = 34
write num2.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT = num1
IMPORTING
IN_WORDS = T_SPELL.
spell = t_spell-word.
clear t_spell.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT = num2
IMPORTING
IN_WORDS = T_SPELL.
LEN = STRLEN( t_spell-word ).
REPLACE t_spell-word LENGTH LEN WITH field
INTO SPELL.
Concatenate spell t_spell-word into spell separated by space.
Write : spell. " one thousend two hundred AND thirty four
Regards,
Sairam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
str = 1234.00
split string at '.' into str1 , str2.
str1 = 1234
str2 = 00
len = strlen (str1). =4
len1 = len - 2. = 2
str3 = str + len1(2). =34
str4 = str1 + 0(len1). =12
concatenate str4 '00' into str5. =1200
now u have 1200 in str5 and 34 in str3.
pass str5 and str3 to spell_amount FM.
Reward if it is helpful.
kiran.M
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Aafaq,
I know this is not the best result.But for what its worth
What you could do is search for the first hundred backwards (or simply the last).
That is from then end of the string.
You will not have the problem of multiple hundreds then.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
another thing hit me.
what if there is no hunded
what if it is 1024
one thousand and twenty four?.
So we cant search for hunderd (i dunno if there is a simple fm that addresses it)
the issue is, that u need to print 'and' whenever u have a tens and units place.
so lets devise a logic to find tat we insert an 'and' when have anything less than 100 in our tens and units place.
We first do a mod 100 to find whteher we have a remainder less that 100
set a flag saying 'and' needs to be printed.
Now we search for the tens or units place word in the string and insert the and there. Ill look thorugh the abap help for an approriate abap reverse command
User | Count |
---|---|
78 | |
10 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.