ā2013 Feb 25 7:02 AM
Hi,
I have a confusion in using and changing, both works same.
then what is the difference in it .
please explain in simple way.
<Reward offer removed by moderator>
Regards
Arif
Moderator message : Search for available information, discussion locked.
Message was edited by: Vinod Kumar
ā2013 Feb 25 7:06 AM
Hello,
This is very basic question......do some research before posting at SCN.
using means -> call by reference.
changing means -> call by reference.
using value( ) means -> call by value...
changing value( ) means -> call by value and result..
Reg
Sabyasachi
ā2013 Feb 25 7:25 AM
Hi,
I know call by reference and call by value,
But question is differece between using and changing.
at the time of perfom.
perform xyz using p.
form using p1.
endform.
perform xyz changing p.
form changin p1.
endform.
both works same than what is difference in it.
ā2013 Feb 25 7:32 AM
As written in the documentation (Press F1 or read PERFORM - parameter_list) there is no difference between the two options, the CHANGING is only useful for maintenability of the program as it documents the interface - Read the Rules of Engagement before posting.
Regards,
Raymond
ā2013 Feb 25 7:43 AM
Hello mohd,
There is actually no difference between two options.......both are call by reference....... means same memory address......
Reg
Sabyasachi
ā2013 Feb 25 7:51 AM
Hi Mohd,
Taking your example as below, when we define a variable as using, we can only use this to do operations within the sub-routine but can't actually change the value of this using parameter (its not advisable). When we define a variable as changing, we can actually change the value of that parameter. So that is actually the difference. Hope this helps or let me know if you have any doubts.
perform xyz using p.
form using p1.
endform.
perform xyz changing p.
form changin p1.
endform.
ā2013 Feb 25 7:48 AM
Hi,
Major difference can be seen when you are using the addition using value(a) or changing value(a).
using value(a)--> it will pass the values in actual parameter to formal parameter and if you chang the value of 'a' in subroutine the value of actual parameter remains same as before passing.
Changing value(a)--> it will pass the values in actual parameter to formal parameter and if you change the value of a in subroutine the value of actual parameter changes as in formal parameter.
ā2013 Feb 25 8:14 AM
Hi,
There is a very basic difference between using and changing.
If we use using keyword with a subroutine then we can simply pass the value/reference to subroutine for processing but it will not reply back the changes done to the variable to the main program
If we have used changing keyword with subroutine then we can get back the changed value of the variable from the subroutine to the main program means whatever value changes occurred in subroutine will be reflected in main program
For Example.
data x TYPE i VALUE 10.
DATA y TYPE i VALUE 10.
PERFORM zsubusing1 USING x y .
WRITE: /' Value of X In Using = ',
x.
PERFORM zsubchanging1 USING y CHANGING x .
WRITE: / ' Value of X after Changing = ',
x.
*&---------------------------------------------------------------------*
*& Form ZSUBUSING1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_X text
* -->P_Y text
*----------------------------------------------------------------------*
FORM ZSUBUSING1 USING P_X
P_Y.
p_y = p_x + p_y.
ENDFORM. " ZSUBUSING1
*&---------------------------------------------------------------------*
*& Form ZSUBCHANGING1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_Y text
* <--P_X text
*----------------------------------------------------------------------*
FORM ZSUBCHANGING1 USING P_Y
CHANGING P_X.
p_x = p_x + p_y.
ENDFORM. " ZSUBCHANGING1
ā2013 Feb 25 8:59 AM
Hello,
Pass by reference for USING parameters
For the formal parameters p1 p2 ..., no local data object is created in the subroutine. Instead, when it is called, a reference is passed to the specified actual parameter. A change to the formal parameter in the subroutine also changes the value of the actual parameter.
Pass by reference for CHANGING parameters
The formal parameters p1 p2 ... are handled exactly like those parameters defined for pass by reference using USING.
Pass by value for USING parameters
For each formal parameter p1 p2 ..., a local object with the same data type as the corresponding actual parameter is created in the subroutine and filled with its values. A change to the formal parameter in the subroutine does not change the value of the actual parameter. The actual parameter also retains its original value even after the subroutine has ended.
Pass by value for CHANGING parameters
For each formal parameter p1 p2 ..., a local data object with the same data type as the corresponding actual parameter is created in the subroutine and filled with its values. A change to the formal parameter in the subroutine does not directly change the value of the actual parameter. If the subroutine is ended using <b>ENDFORM, RETURN, CHECK or EXIT</b> however, the content of the formal parameter is assigned to the actual parameter. If the subroutine is ended by a message or an exception, the actual parameter remains unchanged.
Thanks
Katrice