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: 

in subroutines

Former Member
0 Kudos

what is the difference between USING and CHANGING in subroutines ,though both functioning in the same way

1 ACCEPTED SOLUTION

Former Member
0 Kudos

USING is used use the variable in the function and it will not be returned and it will be initial.

CHANGING is used to change the value in the function and it can be returned and use the variable in the program

5 REPLIES 5

Former Member
0 Kudos

USING p_x

in this case p_x is initial and does not have any value

CHANGING p_x

in this case p_x may or may not be initial,

Former Member
0 Kudos

Hi Ashok,

USING : As the literary meaning goes, what ever value you pass is used in the subroutine.Any changes are not reflected outside the subroutine.The parameters are passed by reference. The field passed can be changed within the subroutine. The changes are kept beyond the subroutine.

CHANGING : The value can be passed to a subroutine and any calculation on it will be reflected back, after the subroutine call. So you will get the result back from the subroutine.

I think this will help you.

Regards,

Kapil

Former Member
0 Kudos

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 reference 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 reference 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 ENDFORM, RETURN, CHECK or EXIT 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.

Former Member
0 Kudos

USING is used use the variable in the function and it will not be returned and it will be initial.

CHANGING is used to change the value in the function and it can be returned and use the variable in the program

abdul_hakim
Active Contributor
0 Kudos

Welcome to SDN.

Technically there is no difference.Usally USING is used to pass a value which doesn't change and CHANGING is used to pass a value which will change.If you change the value passed using USING then you will get a warning message in sytax check..

EG..

DATA SUM1 TYPE I VALUE 10.

DATA SUM2 TYPE I VALUE 20.

PERFORM SUB USING SUM1 CHANGING SUM2.

FORM SUB USING S1 CHANGING S2.

S1 = 100.

ENDFORM.

Abdul