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

Perform statement

Former Member
0 Likes
869

Hello Experts,

Please explain me abt the difference between

Using & changing in Perform statement.

Thanx in Advance.

6 REPLIES 6
Read only

Former Member
0 Likes
829

This is what the sap documentation says:

Addition 2

... USING u1 u2 u3 ...

Addition 3

... CHANGING c1 c2 c3 ...

Effect

These additions must be followed by type-related actual parameters for all USING and CHANGING parameters of the called subroutine. The two additions are equivalent. Only the order of the parameters is important. The first USING or CHANGING parameter of the PERFORM call is transferred to the first USING or CHANGING parameter of the subroutine, the second to the second, and so on. For documentation reasons you should, when calling, use the same addition as with the subroutine definition.

REgards,

Ravi

Read only

dani_mn
Active Contributor
0 Likes
829

HI,

USING parameters: a local copy of the parameter is created in the subroutine and the original parameter value will not changed if changes are made within subroutine.

CHANGING parameters: address of the original parameter is passed to subroutine changes in the parameter value in subroutine will change the original parameter too.

Regards,

Read only

Former Member
0 Likes
829

Hi johnn,

1. we want to pass some input parameters

the form routine (as an input)

so we use USING

2. Inside the FORM,

if we want to MODIFY

some parameters, (passed with PERFORM statement)

then we should use CHANGING.

3. HOWEVER,

4. we can modify both type of parameters,

(provided they are not passed by value)

5. But the USING / CHANGING

is provided for CLARIFICATION/SIMPLICITY

purpose.

regards,

amit m.

Read only

Former Member
0 Likes
829

<b>USING</b> parameters: a local copy of the parameter is created in the subroutine and the original parameter value will not changed if changes are made within subroutine. Basically, can also be said to be PASS by value.

<b>CHANGING</b> parameters: address of the original parameter is passed to subroutine changes in the parameter value in subroutine will change the original parameter too. Basically, can also be said to be PASSing by reference.

Check the below link

http://www.cs.princeton.edu/~lworthin/126/precepts/pass_val_ref.html

Read only

anversha_s
Active Contributor
0 Likes
829

hi,

chk this.

data : num1 type i ,

num2 type i.

num1 = 7.

num2 = 10.

perform find_sum using num1 num2.

form find_sum using num1 type i num2 type i.

num1 = num1 + num2.

endform.

write num1. "out put will be 7 itself.

*********changing**********

perform find_sum changing num1 num2.

form find_sum changing num1 num2.

num1 = num1 + num2.

endform.

write num1. "out put will be 17.

so

USING -> a local copy of the parameter is created in the subroutine and the original parameter value will not changed if changes are made within subroutine.

CHANGING - > address of the original parameter is passed to subroutine changes in the parameter value in subroutine will change the original parameter too.

Regards,

anver

if hlped rwrd points

Read only

Former Member
0 Likes
829

Hi,

If the form header declares that the parameter is passed by reference, i.e. the parameters in the FORM statemtent are written as P1 P2 ... and not as VALUE(P1) VALUE P(2) ..., then USING and CHANGING behave in the same way and it is just a matter of good coding practice to specify USING for parameters that do not get changed inside the subroutine, and CHANGING for parameters that do.

If the parameters in the FORM line are declared with the VALUE() clause, then the behaviour is different. With USING the actul variable passed by the caller does not change, with CHANGING it does change unless the subroutine is exited with an exception (e.g. a MESSAGE E).

A few simple examples to clarify:

#1:

DATA MYVAR TYPE I VALUE 5.

PERFORM DOUBLE USING MYVAR.

WRITE MYVAR.

FORM DOUBLE USING ARG.

ARG = ARG * 2.

ENDFORM.

--> In this case MYVAR becomes 10. Since ARG is changed in the soubroutine, "CHANGING" would be better coding than "USING" but the effect is the same.

#2:

PERFORM DOUBLE CHANGING MYVAR.

FORM DOUBLE USING ARG.

--> MYVAR still becomes 10. This is not good coding however: your PERFORM statement should match the declaration in the FORM. If you have USING in the PERFORM and CHANGING in the FORM -> same thing: result is 10, but sloppy coding.

#3:

PERFORM DOUBLE USING MYVAR. (or CHANGING)

FORM DOUBLE USING VALUE(ARG).

--> Now MYVAR will remain 5. Combination of USING and VALUE() in the FORM header means that for this parameter a local copy is created and its final value is not returned back to the caller.

#4:

PERFORM DOUBLE USING MYVAR. (or CHANGING)

FORM DOUBLE CHANGING VALUE(ARG).

--> MYVAR becomes 10 if the subroutine is exited normally (e.g. via ENDFORM). If it exits with an exception, MYVAR remains 5. Personally this is not something I'd ever code this way.

I hope this didn't look too confusing.

regards,

Mark