‎2008 May 02 7:59 AM
Dear Experts,
What is meant by checking check box optional or Pass by value or optional and Pass by value?
What is the reason for import, export, and changing parameters can be used either by value or by reference.
Table parameters are always transferred by reference ?
Please, calrrify for things in Function Modules, I have gone through many documents, but still I am confusing with those Optional and Pass by value for all those parameters ?
Thanks in Advance..
Sridhar
‎2008 May 02 9:50 AM
Hi SRIDHAR
Just saying in simple language
OPTIONAL in FM
In Importing parameters that meance the value we want for FM can be made optional .That meanse we dont have to give the value while calling that FM.
Pass by Value and pass by Reference ,
There are two ways to send or receive the importing or exporting parameters pass by value and pass by reference
In pass by value new copy of veriable is created on memory location of system and that is send .In pass by reference just only the memory location is send in parameters so duplications of values can be avoided. As we know the internal tables are big in size .so it always used pass by reference so only memory location can only send insteded of whole table .Its imp consept ,same asked for Certification.
Thanks and Regards
Avadhut
‎2008 May 02 9:12 AM
Hi,
Pass by value is not usually used for Normal Function modules, but for RFC enabled fuction modules.
RFC enabled FMs have slower performance when compared to Normal Fms since values are passed by value.
A parameter can be made Optional according to your requirement.
ie; it's not neccesary the calling program should supply a value for this paramter.
Import Parameter : Values transferred from the calling program to the function module.
You cannot overwrite the contents of import parameters at runtime.
A calling program will Export ie pass value to a Function module and the Function module will get the value by Import ing it to it.
Export Parameter : Values transferred from the function module back to the calling program.
If a calling program had to get the value passed by a Function module,
The Function module should first Export the data and the calling program will get the same as Import parameter.
Changing Parameter : Values that act as import and export parameters simultaneously.
The function module can alter the initial value and send it back to the calling program.
Tables Parameter : (Not recommended / Obsolete in ECC 6.0)
Internal tables that can be imported and exported. The function module can alter the contents. Tables are always passed by reference.
Refer : [Calling Function Modules|http://help.sap.com/saphelp_nw70/helpdata/en/9f/db98ef35c111d1829f0000e829fbfe/content.htm]
Cheers,
Remi
‎2008 May 02 9:36 AM
Pass by value : It means you pass the value of the vparameter to the FM from the main program ( from where you called the FM) . In this case, if the value get changed inside the FM , it will not be reflected in the main program ( as the value stored in the memory address do not changed). the memory address retain the old value. So the effect of the change will only be visable inside the FM.
Pass by referance :Here instead of passing the value of the parameter, you pass the memory address of the parameter. So if the value get changed inside the FM, the change happen in the memory address. So the effect get reflect in the main program also.
Refer the following example:
REPORT ytestab.
DATA: gc_flag TYPE c VALUE 'X'.
CALL FUNCTION 'ZTESTFM1'
EXPORTING
lp_flag = gc_flag.
write: gc_flag.
FUNCTION ZTESTFM1.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" CHANGING
*" REFERENCE(LP_FLAG1) TYPE C1
*"----------------------------------------------------------------------
field-symbols: <FC> type any.
data: lv_text(16) type c value '(YTESTAB)GC_FLAG'.
Assign (lv_text) to <FC>.
if sy-subrc EQ 0.
<FC> = 'M'.
endif.
It is pass by referance and the output will be 'M'.
REPORT ytestab.
DATA: gc_flag TYPE c VALUE 'X'.
CALL FUNCTION 'ZTESTFM1'
EXPORTING
lp_flag = gc_flag.
write: gc_flag.
FUNCTION ZTESTFM1.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" CHANGING
*" VALUE(LP_FLAG1) TYPE C1
*"----------------------------------------------------------------------
field-symbols: <FC> type any.
data: lv_text(16) type c value '(YTESTAB)GC_FLAG'.
Assign (lv_text) to <FC>.
if sy-subrc EQ 0.
<FC> = 'M'.
endif.
It is pass by value and the output will me 'X'.
‎2008 May 02 9:50 AM
Hi SRIDHAR
Just saying in simple language
OPTIONAL in FM
In Importing parameters that meance the value we want for FM can be made optional .That meanse we dont have to give the value while calling that FM.
Pass by Value and pass by Reference ,
There are two ways to send or receive the importing or exporting parameters pass by value and pass by reference
In pass by value new copy of veriable is created on memory location of system and that is send .In pass by reference just only the memory location is send in parameters so duplications of values can be avoided. As we know the internal tables are big in size .so it always used pass by reference so only memory location can only send insteded of whole table .Its imp consept ,same asked for Certification.
Thanks and Regards
Avadhut