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

data type conversion in subroutine in script

Former Member
0 Likes
419

Please answer my quest

in subroutine inside script all the variables are in char format.

Suppose passed values are of amount.

I want to make total of it in (se38) program, so i need to convert it from character to numeric or integer.

Explain me how datatype can be converted from char to I or P.

Thanking you

Gargi.

Edited by: GARGI PARIKH on Mar 12, 2008 11:51 AM

3 REPLIES 3
Read only

Former Member
0 Likes
391

Hi,

try it

1. To remove all camms(,)

REPLACE ALL OCCURRENCES OF ',' IN <variable1> WITH ''.

2. Conver to number(internal convertion)

<number _variable> = <variable1>

L.Velu

Read only

0 Likes
391

hi,

thank you for answering.

which comma are you talkng about and what '< --- >' stands for?

Edited by: GARGI PARIKH on Mar 18, 2008 7:12 PM

Edited by: GARGI PARIKH on Mar 18, 2008 7:14 PM

Read only

Former Member
0 Likes
391

I think you'll just need something like this (not syntax checked):


form do_count
  tables 
    it_data structure itcsy
    ot_data structure itcsy.

data:
  ls_itcsy         like itcsy,
  l_total          type i,
  l_count          type i.

read table it_data into ls_data 
  with key name = 'MY_COUNT'.   "or whatever

if sy-subrc is initial.
  l_count = ls_data-value.  "will convert Char to I 
  add l_count to l_total.
endif.
"etc
endform.

but to make it more robust (i.e. in case the SAPScript calls it with a non-numeric) you might like to wrap a "try" or "catch" around the assignment from the character to the number as in:

http://help.sap.com/saphelp_nw70/helpdata/en/a9/b8eef8fe9411d4b2ee0050dadfb92b/frameset.htm

Jonathan