Application Development 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: 

Issue with change and using in perform statment

Former Member
0 Kudos
122

Hi,

data : num1 type i ,

num2 type i.

num1 = 7.

num2 = 10.

perform find_sum using num1 num2.

write / : num1 , 'out put will be 7 itself'.

*********changing**********

perform find_sum1 changing num1 num2.

write / : num1 , 'out put will be 17 '.

&----


*& Form find_sum1

&----


  • text

----


  • <--P_NUM1 text

  • <--P_NUM2 text

----


form find_sum1 changing p_num1 type i

p_num2 type i.

num1 = num1 + num2.

endform. " find_sum1

&----


*& Form find_sum

&----


  • text

----


  • -->P_NUM1 text

  • -->P_NUM2 text

----


form find_sum using p_num1 type i

p_num2 type i.

num1 = num1 + num2.

endform. " find_sum

This is what i see an output,

17 out put will be 7 itself

27 out put will be 17

ACTUAL IT SHOULD BE LIKE THIS RIGHT

7 out put will be 7 itself

17 out put will be 17

lET ME KNOW WHERE IAM GOING WRONG

1 ACCEPTED SOLUTION

former_member491305
Active Contributor
0 Kudos
81

Hi,

You have to use local variable only to do operation inside the subroutine.

data : num1 type i ,

num2 type i.

num1 = 7.

num2 = 10.

perform find_sum using num1 num2.

write / : num1 , 'out put will be 7 itself'.

*********changing**********

perform find_sum1 changing num1 num2.

write / : num1 , 'out put will be 17 '.

form find_sum using p_num1 type i

p_num2 type i.

p_num1 = p_num1 + p_num2.

endform. " find_sum

form find_sum1 changing p_num1 type i

p_num2 type i.

p_num1 = p_num1 + p_num2.

endform. " find_sum

then it will give u the value u want.<i></i>

Message was edited by:

Vigneswaran S

5 REPLIES 5

Former Member
0 Kudos
81

Change the code like this.

num1 = 7.

num2 = 10.

<b>write / : num1 , 'out put will be 7 itself'.</b>

perform find_sum using num1 num2.

<b>write / : num1 , 'out put will be 17 '.</b>

*********changing**********

perform find_sum1 changing num1 num2.

Reward if helpful.

former_member491305
Active Contributor
0 Kudos
82

Hi,

You have to use local variable only to do operation inside the subroutine.

data : num1 type i ,

num2 type i.

num1 = 7.

num2 = 10.

perform find_sum using num1 num2.

write / : num1 , 'out put will be 7 itself'.

*********changing**********

perform find_sum1 changing num1 num2.

write / : num1 , 'out put will be 17 '.

form find_sum using p_num1 type i

p_num2 type i.

p_num1 = p_num1 + p_num2.

endform. " find_sum

form find_sum1 changing p_num1 type i

p_num2 type i.

p_num1 = p_num1 + p_num2.

endform. " find_sum

then it will give u the value u want.<i></i>

Message was edited by:

Vigneswaran S

Pawan_Kesari
Active Contributor
0 Kudos
81

Even though you are specifying the parameters as USING, you are passing them by reference, so the original value will get change. You need to use USING .. VALUE(p).

USING ... p ...

The parameters are passed by reference. The field passed can be changed within the subroutine. The changes are kept beyond the subroutine.

USING ... VALUE(p) ...

The VALUE(...) addition passes the parameter by copying the field contents to a corresponding local field. VALUE parameters behave in the same way as local fields.

Former Member
0 Kudos
81

Hi Kajol,

I have corrected ur code check it out.

REPORT ztestprg.

DATA : num1 TYPE i ,

num2 TYPE i.

num1 = 7.

num2 = 10.

PERFORM find_sum USING num1 num2 .

WRITE / : num1 , 'out put will be 7 itself'.

*********changing**********

PERFORM find_sum1 CHANGING num1 num2.

WRITE / : num1 , 'out put will be 17 '.

&----


*& Form find_sum1

&----


  • text

----


  • <--P_NUM1 text

  • <--P_NUM2 text

----


FORM find_sum1 CHANGING p_num1 TYPE i

p_num2 TYPE i.

p_num1 = p_num1 + p_num2.

ENDFORM. " find_sum1

<b>&----


*& Form find_sum

&----


  • text

----


  • -->P_NUM1 text

  • -->P_NUM2 text

----


FORM find_sum using value(p_num1) p_num2 .

p_num1 = p_num1 + p_num2.

ENDFORM. " find_sum</b>

Thanks

mahesh

Former Member
0 Kudos
81

Hi all,

Thanks all.