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

Function Module

S0023931147
Participant
0 Likes
397

what is the diffrence between changing and using in function module.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
376

Hi naresh,

Changing & using are generally used in passing parameters by reference

You list these parameters after USING or CHANGING without the VALUEaddition:

FORM subr USING    p1 [{TYPE type}|{LIKE field}] 

                   p2 [{TYPE type}|{LIKE field}]

                   ...
          CHANGING p1 [{TYPE type}|{LIKE field}] 

                   p2 [{TYPE type}|{LIKE field}]

                   ...

The formal parameter has 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.

Check this link for more info;-

http://help.sap.com/saphelp_nw70/helpdata/en/9f/db984635c111d1829f0000e829fbfe/content.htm

Regards,

Bhumika

4 REPLIES 4
Read only

Former Member
0 Likes
377

Hi naresh,

Changing & using are generally used in passing parameters by reference

You list these parameters after USING or CHANGING without the VALUEaddition:

FORM subr USING    p1 [{TYPE type}|{LIKE field}] 

                   p2 [{TYPE type}|{LIKE field}]

                   ...
          CHANGING p1 [{TYPE type}|{LIKE field}] 

                   p2 [{TYPE type}|{LIKE field}]

                   ...

The formal parameter has 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.

Check this link for more info;-

http://help.sap.com/saphelp_nw70/helpdata/en/9f/db984635c111d1829f0000e829fbfe/content.htm

Regards,

Bhumika

Read only

Former Member
0 Likes
376

Hi Narendra,

The Changing parameters in the Function Module must be supplied with data when you call the function module, unless they are flagged as optional. They can be changed in the function module.

The changed values are then returned to the calling program.

And Using is used in the Subroutines and not in the Function Modules.

In Function Modules You have Export and Import parameters.

Regards,

Swapna.

Read only

Former Member
0 Likes
376

hi Please check this thread.may be use ful to u

http://help.sap.com/saphelp_46c/helpdata/EN/d1/801ece454211d189710000e8322d00/frameset.htm

The additions using and changing both pass by reference-they are identical in function. The reason they both exist is that-used properly-they can document whether the subroutine will change a parameter or not.

Code changing with parameters, the subroutine changes. You should code using with parameters that are not changed by the subroutine. the following program illustrates this point.

1 report zexam.

2 data: f1 value 'A',

3 f2 value 'B'.

4

5 write: / f1, f2.

6 perform s1 using f1

7 changing f2.

8 write: / f1, f2.

9

10 form s1 using p1

11 changing p2.

12 p1 = p2 = 'X'.

13 endform.

-


The code in Listing produces the following output:

A B

X X

f1 and f2 are both passed by reference to s1. Therefore, p1 and p2 are pointers to f1 and f2. Changes to p1 and p2 are immediately reflected in f1 and f2. This example only illustrates that it is possible to change any parameter that is passed by reference. You should code your parameters so that using and changing properly document your usage of those parameters.

reward points if useful,

Thanks,

usha

Edited by: Usha Rani Rachamalla on Jul 11, 2008 9:57 AM

Read only

Former Member
0 Likes
376

HI,

Using & Changing will acts same as Pass by Value (with value addition) and Pass by Reference.