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: 

Difference between USING and CHANGING

Former Member
0 Kudos

Hi all,

What is the exact difference between USING and CHANGING, as in the below mentioned examples the functionality is same.

perform sub1 using p1.

perform sub2 changing p2.

form sub1 using x1.

endform.

form sub2 changing x2.

endform.

In both cases it is "By Reference". When we pass the values in any of the perform the result will be same. When both performs do the same job what is the difference between USING and CHANGING.

Please clarify my Doubt.

Thanks in Advance

1 ACCEPTED SOLUTION

Hi,

<b>There is a difference between USING and CHANGING.</b>

<b>Pass by reference for USING parameters</b>

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.

<b>Pass by reference for CHANGING parameters</b>

The formal parameters p1 p2 ... are handled exactly like those parameters defined for pass by reference using USING.

<b>Pass by value for USING parameters</b>

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.

<b>Pass by value for CHANGING parameters</b>

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.

Regards,

Sesh

6 REPLIES 6

Former Member
0 Kudos

If a subroutine contains TABLES parameters in its interface, you must specify them in a TABLES addition of the PERFORM statement before the USING and CHANGING parameters. TABLES parameters are only supported to ensure compatibility with earlier releases, and should no longer be used.

If a subroutine has a parameter interface, you must supply values to all of the formal parameters in its interface when you call it. You list the actual parameters after the USING or CHANGING addition in the PERFORM statement.

When you pass the values, the sequence of the actual parameters in the PERFORM statement is crucial. The value of the first actual parameter in the list is passed to the first formal parameter, the second to the second, and so on. The additions USING and CHANGING have exactly the same meaning. You only need to use one or the other. However, for documentary reasons, it is a good idea to divide the parameters in the same way in which they occur in the interface definition.

Actual parameters can be any data objects or field symbols of the calling program whose technical attributes are compatible with the type specified for the corresponding formal parameter. When you specify the actual parameters, note that any that you pass by reference to a formal parameter, and any that you pass by value to an output parameter, can be changed by the subroutine. You should therefore ensure that only data objects that you want to be changed appear in the corresponding position of the actual parameter list.

reward points if helpful........

Former Member
0 Kudos

Hi,

The additions USING and CHANGING have exactly the same meaning. You only need to use one or the other. However, for documentary reasons, it is a good idea to divide the parameters in the same way in which they occur in the interface definition.

Reward if useful!

Hi,

<b>There is a difference between USING and CHANGING.</b>

<b>Pass by reference for USING parameters</b>

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.

<b>Pass by reference for CHANGING parameters</b>

The formal parameters p1 p2 ... are handled exactly like those parameters defined for pass by reference using USING.

<b>Pass by value for USING parameters</b>

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.

<b>Pass by value for CHANGING parameters</b>

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.

Regards,

Sesh

Former Member
0 Kudos

hi,

USING and CHANGING is used for same purpose in subroutines. both pass values from calling area to procedure in 'CALL BY REFERENCE' METHOD ONLY. but there may some situations where the values passed should be effected in such cases we go for VALUE keyword in addition to CHANGING or USING.

in some situations the values that are changed in subroutines should again be passed to calling area with the help of RETURN keyword as

CHANGING VALUE AND RETURN -


here is the situtaion where USING may not be used.

and for all other cases both are used for same purpose.

if helpful reward some points.

with regards,

suresh babu

Former Member
0 Kudos

Hi,

The difference what I hav understud is Using is used as importing only and Changing as importing as well as exporting.

Suppose in the example that u mentioned:

p1 = 5 .and u r performing the subroutine.

Inside the routine if P1 is changed to 6,u will not be able to retrieve the changed value.

This is only possible if u r using Changing.

In cases where p1 doesnt changes in the routine ,use of Using or Changing will be syntatically correct.

reward if found helpful

regards,

Anju

Former Member
0 Kudos

HI

If you specify the additions USING and CHANGING, an actual parameter a1 a2 ... of the appropriate type must be assigned to each of the formal parameters u1 u2 ... and c1 c2 ... defined with the same additions to the FORM statement. The actual parameters specified after USING and CHANGING form one shared list. They are assigned to the formal parameters after the position in the shared list. The type of parameter transfer is defined with the additions USING and CHANGING to the FORM statement. The addition USING must be before CHANGING. Otherwise, the assignment of the actual parameters to the additions USING and CHANGING is irrelevant to the PERFORM statement. It is also irrelevant whether only one or both of the additions is specified.

For the sake of program documentation, we advise that you specify the additions USING and CHANGING in the FORM statement according to the definition of the parameter interface.

In non-Unicode programs, you can address memory area outside an actual parameter if an actual parameter a1 a2 ... is assigned offset or length specifications. In non-Unicode programs, the length is set to the length of the current parameter if an offset is specified without a length. Both of these lead to warnings in the syntax check and to syntax errors in Unicode programs. The rules for the ASSIGN statement apply to the addressable memory area in non-Unicode programs.

REWARD IF USEFUL