2007 Mar 23 5:16 AM
Hi all,
My query is
Code :
Data : v_rates(20) type c
v_n1(20) tye c.
v_rates = '23456,00000'.
v_n1 = v_rates / 100.
write : / v_n1.While Execution program goes to dump
error message <b>unable to interpret v_rates as numer</b>.
Plz help me with sample code how to convert text to packerd number
Award points if helpful answer
I look forward to your reply
Thanks & Regards
SEK
Hi all,
My query is
Code :
Data : v_rates(20) type c
v_n1(20) tye c.
v_rates = '23456,00000'.
v_n1 = v_rates / 100.
write : / v_n1.While Execution program goes to dump
error message <b>unable to interpret v_rates as numer</b>.
Plz help me with sample code how to convert text to packerd number
Award points if helpful answer
I look forward to your reply
Thanks & Regards
SEK
2007 Mar 23 5:19 AM
hi,
"pack" Converts type C variables to type P.
Syntax
PACK <f> TO <g>.
Packs the string <f> and places it in the field <g>. This can be reversed with the UNPACK statement.
unpack <g> to <f>.
regards,
veeresh
2007 Mar 23 5:21 AM
Hi Raja....
Try this code.
Data : v_rates(20) type c,
v_n1(20) type c.
v_rates = '2345600000'.
v_n1 = v_rates / 100.
write : / v_n1.
Reward points if useful......
Suresh......
2007 Mar 23 5:21 AM
Hi, Why are u taking the data as characters.
Why dont u take it as follows :
Data : v_rates type p
v_n1 type p.
v_rates = '23456,00000'.
v_n1 = v_rates / 100.
write : / v_n1.
Else, if taking in a character format is mandatory then u can take them as numc as follows :
Data : v_rates(20) type n
v_n1(20) tye n.
v_rates = '2345600000'.
v_n1 = v_rates / 100.
write : / v_n1.
It shud wrk.
Regards,
Himanshu
2007 Mar 23 5:45 AM
Hi All,
Thank you for your reply
Atuallt
Cuuency exchange rates took form excel file into internal table
we are uploading Currency rates in EUR format 55.605,00000
Data : v_rates(20) type c
v_n1(20) tye c.
v_rates = '55.605,00000'.
v_n1 = v_rates / 100.
write : / v_n1.
I look forward to your reply
anyone plz help on this its urgent
Thanks
SEK
2007 Mar 23 5:49 AM
Raja,
then u need to replace all the ',' s with space, then proceed with the required operations.
Hops this hint may help u out.
2007 Mar 23 5:53 AM
Hi Raja,
In the following case, u can use the numc data type as I hv defined in my code above.
Secondly what I can see in ur code is that the decimal is represented by ',' and the place where ',' should be there, is the decimal. Is this the way u require.
Otherwise u can change the settings and get the currency to be displayed in the format 55,000.989.
Hope it helps u.
Regards,
Himanshu
2007 Mar 23 5:54 AM
check if below code helps,
data: input type bapicurr-bapicurr .
data: c(20) type c.
data: output(15) type p decimals 2.
c = '215,654.54'.
clear sy-subrc.
while sy-subrc = 0.
replace ',' with space into c.
endwhile.
condense c no-gaps.
input = c.
or else check this,
REPORT z6.
DATA digit(11) VALUE ' 0123456789'.
PARAMETERS: text(16) DEFAULT '20,000.00'.
DATA c_text(16).
DATA amount TYPE p DECIMALS 2.
DATA n TYPE n.
DATA i TYPE i.
c_text = text.
CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.
MOVE c_text TO amount.
ENDCATCH.
IF sy-subrc EQ 1.
CALL FUNCTION 'PREPARE_STRING'
EXPORTING
i_valid_chars = digit
i_xvalid_check = 'X'
i_xchar_repl = 'X'
i_xtoupper = 'X'
CHANGING
c_string = c_text.
CONDENSE c_text NO-GAPS.
DESCRIBE FIELD amount DECIMALS n.
i = 10 ** n.
amount = c_text / i.
ENDIF.
WRITE:/ text, 50 amount.
reward if useful.
2007 Mar 23 5:22 AM
HI ,
You get dump , because you cannot perform operation '/' on char type data field .
Instead use :
Data : v_rates type p decimals 5 ,
v_n1(20) tye c.
then say v_rates = v_rates / 100 .
You can then pass this value to v_n1 and then perform necessary changes in the display for v_n1 .
Thanks .
2007 Mar 23 5:23 AM
',' (comma) is not considered as any numeric value, so remove the comma, and do the calculations,
if the purpose of puttin comma there is for display means, while u display the data to the list, it will diplay with commas based on user settings.
Regards,
Sujatha.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |