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

Confusion on using USING/CHANGING in PERFORMS and FORMS

Former Member
0 Likes
4,313

I got a little confused with PERFORM statements.

As far as I understood, the FORM definition is the one that ultimately defines which variable is going to be handled by value and which by reference (Using either USING, USING VALUE(...) or CHANGING (which is a particularity to deal with recursive functions). Thus, why does the PERFORM statement also accepts the CHANGING option ?

Should I worry with the way the PERFORM statement is written or can I simply imply from it the values of the parameters passed, in a given moment of execution ?

Thanks

Avraham

1 ACCEPTED SOLUTION
Read only

former_member194797
Active Contributor
0 Likes
2,864

The answer is the documentation of perform keyword. Just put the cursor on the "PERFORM" keyword and press F1... :

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.

9 REPLIES 9
Read only

Former Member
Read only

Former Member
0 Likes
2,864

I think the name itself clears that by add on CHANGING u r actually changing the variable value for further processing,

Whereas the USING add on ll not do any changes in the value of variable.

Same applied to internal table too........

thanks & regrads

vinsee

Read only

Former Member
0 Likes
2,864

to understand this thing just open one function module in se37

say EXIT_SAPLMGMU_001

import ie equal to your using

changing is equal to changing

means the field that are in using, u can perform some operation on it.

whereas for changing u can only be able to assign the value to that fields

Read only

bpawanchand
Active Contributor
0 Likes
2,864

Hi

The USING and CHANGING additions in the FORM statement define the formal parameters of a subroutine. The sequence of the additions is fixed. Each addition can be followed by a list of any number of formal parameters. When you call a subroutine, you must fill all formal parameters with the values from the actual parameters. At the end of the subroutine, the formal parameters are passed back to the corresponding actual parameters.

Within a subroutine, formal parameters behave like dynamic local data. You can use them in the same way as normal local data objects that you would declare with the DATA statement. They mask global data objects with the same name. The value of the parameters at the start of the subroutine is the value passed from the corresponding actual parameter.

Parameters Passed by Reference

You list these parameters after USING or CHANGING without the VALUE addition:

FORM <subr> USING ... <pi> [TYPE <t>|LIKE <f>] ...

CHANGING ... <pi> [TYPE <t>|LIKE <f>] ...

The formal parameter occupies no memory of its own. During a subroutine call, only the address of the actual parameter is transferred to the formal parameter. The subroutine works with the field from the calling program. If the value of the formal parameter changes, the contents of the actual parameter in the calling program also change.

For calling by reference, USING and CHANGING are equivalent. For documentation purposes, you should use USING for input parameters which are not changed in the subroutine, and CHANGING for output parameters which are changed in the subroutine.

To avoid the value of an actual parameter being changed automatically, you must pass it by value.

Input Parameters That Pass Values

You list these parameters after USING with the VALUE addition:

FORM <subr> USING ... VALUE(<pi>) [TYPE <t>|LIKE <f>] ...

The formal parameter occupies its own memory space. When you call the subroutine, the value of the actual parameter is passed to the formal parameter. If the value of the formal parameter changes, this has no effect on the actual parameter.

Output Parameters That Pass Values

You list these parameters after CHANGING with the VALUE addition:

FORM <subr> CHANGING ... VALUE(<pi>) [TYPE <t>|LIKE <f>] ...

The formal parameter occupies its own memory space. When you call the subroutine, the value of the actual parameter is passed to the formal parameter. If the subroutine concludes successfully, that is, when the ENDFORM statement occurs, or when the subroutine is terminated through a CHECK or EXIT statement, the current value of the formal parameter is copied into the actual parameter.

If the subroutine terminates prematurely due to an error message, no value is passed. It only makes sense to terminate a subroutine through an error message in the PAI processing of a screen, that is, in a PAI module, in the AT SELECTION-SCREEN event, or after an interactive list event.

reward if useful

Regards

Pavan

Read only

0 Likes
2,864

I don't think people actually read my text, rather only the post subject.

Anyways, I'll try to ask less and test more...

Read only

0 Likes
2,864

Hi Avraham,

Check below.

It depends on what types of variables/work areas/tables u r passing in the PERFORm statement.

USING=> Refers to call by value.

CHANGING=>Refers to call by reference.

TABLES=> Call by reference.

eg: If u r passing a global variable in USING parameter and u changed the content inside the form, The changes will be reflected after the perform call. This is because what ever changes u made to global variable are valid through out the program.

CHANGING: whether u r passing local or global doen't matter. Changes will be reflected.

TABLES: Same thing applies for tables also.

Revert back if u still have confusion.

Thanks,

Vinod.

Read only

former_member435013
Active Participant
0 Likes
2,864

hi,

using and changing is only syntactic sugar. There is no difference in behaviour.

Regards

Walter Habich

Read only

former_member194797
Active Contributor
0 Likes
2,865

The answer is the documentation of perform keyword. Just put the cursor on the "PERFORM" keyword and press F1... :

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.

Read only

0 Likes
2,864

Thanks, Henri, this alludes more to the direction I was searching. Interesting I think I tried F1 on Perform before but I didn't get as much details.

Thanks also for Vinod.

Edited by: Avraham Kahana on Jul 1, 2008 2:03 PM