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 in perform statement again

Former Member
0 Kudos
93

Hi all,

Please check the two codes and tell me what wrong in the first code.

This both codes are from SDN experts

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

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

but when i do this

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

&----


*& 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

it gives the result what iam looking for and it in accordance to definiation of the using and changing

Here the o/p his

7 out put will be 7 itself

17 out put will be 17

My question is what wrong with the first code

Thanks again

1 ACCEPTED SOLUTION

Former Member
0 Kudos
68

Hi Kajol,

The first one is working with pass by reference concept.. the content of the variable that is passed will get change..

<b> Num1 ur passing by reference and in the subroutine u say p_num1 = p_num1 + p_num2.. here the value is getting changed for the num1 because of reference.. when you say by reference it means same as a pointer concept in C or C++ language..</b>

the second one is working with pass by value concept.. thought ur chainge the num1 in the subroutine it will not be effected in the actual variable.

<b> Here i say only take the value into consideration the value is copied into the variable p_num1 .. and if i change the value p_num1 in the subroutine.. it is only effectinve within the subroutine and will not change the value of the actual variable num1</b>

Notice the difference in the two routines in <b>BOLD</b> letters

form find_sum <b>using p_num1</b> type i

p_num2 type i.

p_num1 = p_num1 + p_num2.

endform. " find_sum

&----


*& Form find_sum

&----


  • text

----


  • -->P_NUM1 text

  • -->P_NUM2 text

----


FORM find_sum <b>using</b> <b>value(p_num1)</b> p_num2 .

p_num1 = p_num1 + p_num2.

ENDFORM. " find_sum

Thanks

Mahesh

Message was edited by:

Mahesh Raganmoni

4 REPLIES 4

Former Member
0 Kudos
68

using Perform find_sum...

u are adding 10 + 7 and storing the result in p_num1 as 17.

and perform find-sum1

17 + 10 ==> 27

either u clear the variables or use local variales.

0 Kudos
68

Hi,

I thought that by using "USING" in perform statment won't chnge the values outsidde the form

while using" CHANGE" changes the values out the form as well

Let me know whether iam right?

Thats the reason i am thing the output should be 7 and 17

Thanks

Former Member
0 Kudos
69

Hi Kajol,

The first one is working with pass by reference concept.. the content of the variable that is passed will get change..

<b> Num1 ur passing by reference and in the subroutine u say p_num1 = p_num1 + p_num2.. here the value is getting changed for the num1 because of reference.. when you say by reference it means same as a pointer concept in C or C++ language..</b>

the second one is working with pass by value concept.. thought ur chainge the num1 in the subroutine it will not be effected in the actual variable.

<b> Here i say only take the value into consideration the value is copied into the variable p_num1 .. and if i change the value p_num1 in the subroutine.. it is only effectinve within the subroutine and will not change the value of the actual variable num1</b>

Notice the difference in the two routines in <b>BOLD</b> letters

form find_sum <b>using p_num1</b> type i

p_num2 type i.

p_num1 = p_num1 + p_num2.

endform. " find_sum

&----


*& Form find_sum

&----


  • text

----


  • -->P_NUM1 text

  • -->P_NUM2 text

----


FORM find_sum <b>using</b> <b>value(p_num1)</b> p_num2 .

p_num1 = p_num1 + p_num2.

ENDFORM. " find_sum

Thanks

Mahesh

Message was edited by:

Mahesh Raganmoni

former_member235056
Active Contributor
0 Kudos
68

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 <b>using</b> 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

This is what i see an output,

17 out put will be 7 itself

27 out put will be 17

The bold part is the correction.

pls reward points.

Regards,

Ameet