Skip to Content
avatar image
Former Member

"Changing" parameter and "Tables" parameter defintions in function module

If one defines "Changing" or "tables" parameters, they are treated as reference parameters.

It becomes obvious for "tables" parameters where one does not have option to check box for "Pass by Value". But for "Changing" parameters, they provide the checkbox for "Pass by Value". Even when you select this option, the function module seems to handle the parameter as a reference parameter (whatever changes you make to it in the function module are retained when you return back to a calling program).

My question is why then SAP has provided the checkbox of "Pass by Value" for "Changing" parameter?

Thanks.

Jitendra Mehta

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Nov 20, 2009 at 10:02 PM

    If you want a return parameter as a reference you use changing

    If you want a return parameter as a value copy you use exports

    A changing parameter that is passed as value acts the same way as a export parameter, just confusing things more

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 20, 2009 at 08:04 PM

    Hi Jitendra,

    that's what I also wondered until a wise guy told me: If the function call is terminated by raising an exception, the changes are not applied because the vakues are not copied back.

    Regards,

    Clemens

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      I don't understand Chaiphon fully, because a perform in program is nothing diferent from any other call. The thing is: Call by value means that the parameter is copied to a local variable of the same type and structure. Normally you do this with input parameters you want to change inside the function. CHANGING by value means that it is copied to a loacal variable, then it may be changed and then the changed value is copied back to the parameter.

      That led me to the question if it ever would make any sense to use changing by value. But then: If the contents have been changed and then an exception occurs, the calling program can process the exception and the values are not changed.

      Regards,

      Clemens

  • Nov 20, 2009 at 08:19 PM

    I think you need to understand the concept of 'Pass by Value' and 'Pass by reference'.

    pass by value - the value will be copy to new variable and work on that until end of function and copy it back to the program.

    pass by reference - the value will be referenced to the original variable in the program.

    If you use changing parameter with pass by value in function module, and in function module you call

     perform call_in_program(program_name). 

    the value of variable that pass to changing parameter in the program is still the same.

    If you use changing parameter without pass by value, the value of variable that pass to changing parameter in the program will be the new value as in function module.

    Hope it help,

    Chaiphon

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 20, 2009 at 10:14 PM

    Hi Clemen,

    osrry for not state it clearly. when I mention program_name, I mean calling program name. In function module we can call back to the original program for any reason.

    One scenario that pass by value will become a must is when we create RFC function modules. There will be no communication between RFC and a calling program until RFC is done.

    Chaiphon

    Add comment
    10|10000 characters needed characters exceeded