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

Urgent

Former Member
0 Likes
1,133

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

9 REPLIES 9
Read only

former_member673464
Active Contributor
0 Likes
1,103

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

Read only

Former Member
0 Likes
1,103

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......

Read only

Former Member
0 Likes
1,103

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

Read only

0 Likes
1,103

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

Read only

0 Likes
1,103

Raja,

then u need to replace all the ',' s with space, then proceed with the required operations.

Hops this hint may help u out.

Read only

0 Likes
1,103

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

Read only

0 Likes
1,103

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.

Read only

Former Member
0 Likes
1,103

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 .

Read only

Former Member
0 Likes
1,103

',' (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.