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

what is the difference between using and changing?

Former Member
0 Likes
2,968

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

8 REPLIES 8
Read only

Former Member
0 Likes
2,126

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

Read only

0 Likes
2,126

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.

Read only

0 Likes
2,126

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

Read only

0 Likes
2,126

Hello mohd,

There is actually no difference between two options.......both are call by reference....... means same memory address......

Reg

Sabyasachi

Read only

0 Likes
2,126

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.

Read only

former_member183073
Active Participant
0 Likes
2,126

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.

Read only

Former Member
0 Likes
2,126

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

Read only

Former Member
0 Likes
2,126

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