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

char to numeric conversion

Former Member
0 Likes
1,185

Hello,

I am calling a subrouting from SAP SCRIPT.

But in the subroutine I am not able to change the currecy value to integer.

FORM cal_Tot tables ntwr structure itcsy

tot structure itcsy.

DATA value type vbap-netwr.

value = ntwr-value.

ENDFORM.

If the value of ntwr-value is 300.0 its working but

if the value of ntwr-value is 1,345.0 this is giving runtime error.

How can store 1,345 into variable value

10 REPLIES 10
Read only

Former Member
0 Likes
1,075

MOVE_CHAR_TO_NUM

use this FM to convert char to num.... this works

data : xyz type itcsy-value,
      value type vbap-netwr.

xyz = '1,345.0'.
CALL FUNCTION 'MOVE_CHAR_TO_NUM'
  EXPORTING
    chr                   = xyz
 IMPORTING
   NUM                   = value
 EXCEPTIONS
   CONVT_NO_NUMBER       = 1
   CONVT_OVERFLOW        = 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.

WRITE : xyz , ' = ' , value.

Edited by: soumya prakash mishra on Jun 8, 2009 11:10 AM

Read only

0 Likes
1,075

Hi soumya,

I tried your code but the variable value is remaining 0. I mean there is no change in the output variable and in import i m passing xyz-value not xyz.

Read only

0 Likes
1,075

check what type i have declared for xyz.... xyz type itcsy-value

so u change as u need..

Read only

0 Likes
1,075

Sorry soumya,

This is my code can please tell why i m not getting the value in the variable value

FORM CAL_TOT TABLES NTWR STRUCTURE ITCSY

TOT STRUCTURE ITCSY.

DATA: value type VBAP-NETWR value '0'.

statics value1 type VBAP-NETWR.

Read table ntwr index 1.

CALL FUNCTION 'MOVE_CHAR_TO_NUM'

EXPORTING

chr = NTWR-VALUE

IMPORTING

NUM = value.

value1 = value1 + value.

Read table tot index 1.

tot-value = value.

modify tot index 1.

ENDFORM.

Read only

former_member209217
Active Contributor
0 Likes
1,075

Hi ,

Chk this one

report zcurr.

data: input type bapicurr-bapicurr .

data: c(20) type c.

data: output(15) type p decimals 2.

c = '12,345.78'.

clear sy-subrc.

while sy-subrc = 0.

replace ',' with space into c.

endwhile.

condense c no-gaps.

input = c.

call function 'BAPI_CURRENCY_CONV_TO_INTERNAL'

exporting

currency = 'INR'

amount_external = input

max_number_of_digits = 25

importing

amount_internal = output

  • RETURN =

Read only

Former Member
0 Likes
1,075

Hi Shah,

Try this way,

replace ',' WITH ' ' INTO v_menge.

CONDENSE V_MENGE NO-GAPS.

Read only

0 Likes
1,075

code seems ok.. can u please debug and check what values are u fetching in what point...!!!

Read only

0 Likes
1,075

Thanks Suresh,

Now I am able to add the values but how to again convert into the earlier format as I have to return the value so I have to store in the variable tot-value

Read only

0 Likes
1,075

Hi Shah,

if you want the original value just keep that in some other variable so that the value don't change you can use it for later purpose.

generally the value with , will store in the database tables you can also fetch from there.

Read only

Former Member
0 Likes
1,075

Use this class to change from any type to char

CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_C

use this class to pass type c to any type

CL_ABAP_CONTAINER_UTILITIES=>READ_CONTAINER_C