09-05-2008 9:25 AM
hi all,
what is actual and formal parameters?
what is the use of them in the program?
how to and where to use actural and formal parameters?
pls can i have the sample code which helps in understanding better?
thanks in advance,
jacob.
09-05-2008 9:27 AM
Hi,
both actual and formal parameters hold the value of a variable, but the difference lies in the visibility.
The format parameter is visible only in the local block , where it is define(e.g., inside a subroutine), but the actual parameter is visible globaly i.e. in the main prog and in the subroutine.
09-05-2008 9:33 AM
Hi ,
When you are working with routines, FM you will come across with actual & formal parameters.
Example.....
PERFOM select_data using lv_date, lv_matnr
here the lv_date and lv_matnr are actual parameters.
when write the Form routine
FORM select_data using p_date type lv_date
p_matnr type lv_matnr
here p_date and p_matnr is formal parameters.
hope your question is answered.
Thanks & Regards
Madhavi
09-05-2008 9:45 AM
>
> Hi,
> both actual and formal parameters hold the value of a variable, but the difference lies in the visibility.
> The format parameter is visible only in the local block , where it is define(e.g., inside a subroutine), but the actual parameter is visible globaly i.e. in the main prog and in the subroutine.
Incorrect or at least, misleading.
If you call form B from form A, the actual parameters may well be local to form A.
09-05-2008 9:32 AM
Hi,
Cinsider the following example
DATA: w_val TYPE I.
PERFORM f_increment USING w_val.
***
FORM f_increment USING us_val TYPE I.
us_val = us_val + 1.
ENDFORM.
In the above code, w_val is Actual paramener.
But us_val is the formal parameter,as its only visible inside a particular routine.
Data is copied from actual parameter to formal parameter, when we call a PERFORM,
09-05-2008 9:32 AM
Hi Jacob,
Please refer to this SAP HELP for better understanding..
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db984635c111d1829f0000e829fbfe/content.htm
And also check the Examples specified in the above link
For further help..check this thread...
Hope this would help you and put some light for you regarding this topic.
Good luck
Narin
09-05-2008 9:36 AM
hiii
Actual and formal parameters are used in modularization technique.it is used while calling a subroutine.
we use subroutines using PERFORM statement and the functionality of this subroutine is defined using FORM and ENDFORM statements.
Here variables used in perform statement are called ACTUAL PARAMETERS and the variables used in form, endform statements are called FORMAL parameters. when program execution is there, actual parameters are passed to the formal parameters.
EXAMPLE:
data:
wa_num type i.
parameters:
p_num2 type i,
p_num3 type i.
perform multiply using p_num2 p_num3 wa_num. " these are actual parameters.
write:/ p_num3.
form multiply using x y z. " x, y and z are formal parameters.
z = x + y.
endform.
regards
twinkal
09-05-2008 9:36 AM
Hi,
Example of Actual Parameters:
PERFORM INCREMENT_VALUE USING previous_val CHANGING new_val.
Here previous_val and new_val are the Actual parameters...
Example of FORMAL Parameters:
FORM INCREMENT_VALUE USING p_prev_val CHANGING p_new_val.
p_new_val = p_prev_val + 1.
ENDFORM.
Here p_prev_val and p_new_val are FORMAL parameters...
Formal parameters have visibility inside the FORM and ENDFORM statements only...
Regards,
Kunjal
09-05-2008 9:36 AM
HI
DATA :
w_i TYPE i VALUE 6.
PERFORM display USING w_i .. "<<-------Actual Parameter
FORM display USING value(p_w_i) TYPE i..
WRITE :
/ p_w_i. "<<----- Formal Parameter
ENDFORM. " display
regards
pavan
09-05-2008 9:41 AM
Hi,
The difference is parameters which are vissible inside the Function Module are called Formal Parameters.
The Parameters which are passed to the Function Module are called Actual Parameters.
REPORT Zexample_1 .
DATA: num1 TYPE i,
num2 TYPE i,
sum TYPE i.
num1 = 2. num2 = 4.
PERFORM addit USING num1 num2 CHANGING sum.
num1 = 7. num2 = 11.
PERFORM addit USING num1 num2 CHANGING sum.
FORM addit
USING add_num1 TYPE any
add_num2 TYPE any
CHANGING add_sum TYPE any.
add_sum = add_num1 + add_num2.
PERFORM out USING add_num1 add_num2 add_sum.
ENDFORM.
FORM out
USING out_num1 TYPE any
out_num2 TYPE any
out_sum TYPE any.
WRITE: / 'Sum of', out_num1, 'and', out_num2, 'is', out_sum.
ENDFORM.
Actual and Formal parameters both contain the values.
Here in the present Example.
num1 and num2----
> Actual Parameters and add_num1 and add_num2 -
> Formal Parameters.
09-05-2008 9:42 AM
hi Jacob,
continuing my above post, the sample code is
REPORT z_test.
PARAMETERS:
a_var1 TYPE i,
a_var2 TYPE i.
PERFORM test USING a_var1
a_var2.
WRITE:
/ 'In main prog:',
'Value of var1:',a_var1,
'Value of var2:',a_var2.
*&---------------------------------------------------------------------*
*& Form test
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_A_VAR1 text
* -->P_A_VAR2 text
*----------------------------------------------------------------------*
FORM test USING p_a_var1
p_a_var2.
DATA: f_var1 TYPE i,
f_var2 TYPE i,
temp TYPE i.
f_var1 = p_a_var1.
f_var2 = p_a_var2.
temp = f_var1.
f_var1 = f_var2.
f_var2 = temp.
WRITE:
/ 'In Subroutine:',
'Value of var1:',f_var1,
'Value of var2:',f_var2.
it is self explanetory with our old example of SWAPPING . where the value of formal parameters (f_var1 and f_var2) are swapped but the actuals (a_var1 and a_var2)remains same.
Regards,
Anirban