09-10-2007 10:28 AM
explain the concept of formal and acutal parameters... when we use changing
and when we use value with simple easy examples...
thanks
Message was edited by:
balaji velpuri
09-10-2007 11:38 AM
Hi balaji,
Pls check the below code.
Pass by value
============
x=5.
perform valuechange using x.
write / x.
form valuechange values x.
x=10.
endform.
Result=5
Pass by reference
=============
x=5.
perform valuechange changing x.
write / x.
form valuechange values x.
x=10.
endform.
Result=10
Regards,
Sheron
09-10-2007 10:31 AM
PROGRAM form_test.
DATA: a1 TYPE p DECIMALS 3,
a2 TYPE i,
a3 TYPE d,
a4 TYPE spfli-carrid,
a5(1) TYPE c.
...
PERFORM subr USING a1 a2 a3 a4 a5.
...
PERFORM subr CHANGING a1 a2 a3 a4 a5.
...
PERFORM subr USING a1 a2 a3
CHANGING a4 a5.
...
FORM subr USING
value(f1) TYPE p
value(f2) TYPE i
f3 LIKE a3
CHANGING
value(f4) TYPE spfli-carrid
f5.
...
ENDFORM.
This example defines a subroutine subr with a parameter interface consisting of five formal parameters, f1 to f5. The subroutine is called internally three times. The actual parameters are the data objects a1 to a5. The three subroutine calls are all equally valid. There are further PERFORM statements that are also equally valid, so long as the sequence of the actual parameters remains unchanged. In each call, a1 is passed to f1, a2 to f2, and so on. When the subroutine ends, a3, a4, and a5 receive the values of f3, f4, and f5 respectively. The third of the subroutine calls documents in the program what the parameter interface of the subroutine shows, namely that only a4 and a5 are changed. In the case of reference parameter f3, it depends on the programming of the subroutine whether a3 is changed all the same.
-
REPORT demo_mod_tech_describe.
DATA:
date1 TYPE d, date2 TYPE t,
string1(6) TYPE c, string2(8) TYPE c,
number1 TYPE p DECIMALS 2, number2 TYPE p DECIMALS 0,
count1 TYPE i, count2 TYPE i.
PERFORM typetest USING date1 string1 number1 count1.
SKIP.
PERFORM typetest USING date2 string2 number2 count2.
FORM typetest USING now
txt TYPE c
value(num) TYPE p
int TYPE i.
DATA: t(1) TYPE c.
DESCRIBE FIELD now TYPE t.
WRITE: / 'Type of NOW is', t.
DESCRIBE FIELD txt LENGTH t IN CHARACTER MODE.
WRITE: / 'Length of TXT is', t.
DESCRIBE FIELD num DECIMALS t.
WRITE: / 'Decimals of NUM are', t.
DESCRIBE FIELD int TYPE t.
WRITE: / 'Type of INT is', t.
ENDFORM.
This produces the following output:
Type of NOW is D
Length of TXT is 6
Decimals of NUM are 2
Type of INT is I
Type of NOW is T
Length of TXT is 8
Decimals of NUM are 0
Type of INT is I
Regards,
Pavan
09-10-2007 10:39 AM
09-10-2007 10:39 AM
added to pavan
Changing and Using has the same affect,
but you will get one warning in EXTENDED PROGRAM CHECK,
and good programming knowledge where to use using and changing.
regards,
Prabhu
reward if it is helpful
09-10-2007 10:43 AM
Hello,
Formal Parameters - are specified in the Subroutine Definition.
Actual Parameters - are specified in the Calling Statement
When the subroutine is called, formal parameters must be specialized by means of
corresponding global variables (actual parameters), in order to implement the
reference of the subroutine processing to real variables. This assignment of actual
parameters to formal parameters when calling a subroutine is called parameter
passing.
<b>Call by value</b>
You list each of the formal parameters that is supposed to have the pass type 'call by value' with the VALUE prefix in the <b>USING</b> section.
<b>Call by value and result</b>
You list each of the formal parameters that is supposed to have the pass type
'call by value and result' with the <b>VALUE</b> prefix in the <b>CHANGING</b>
section.
<b>Call by reference</b>
You list each of the formal parameters that is supposed to have the pass type 'call
by reference' without the VALUE prefix in the <b>CHANGING</b> section.
Regards,
LIJO
09-10-2007 11:23 AM
hi,
when ur using a subroutine in ur program then
while sometimes u need to pass some parameters to sub routine from main program such parameters are called as actual parameters and in subroutine while may some more parameters which are called as formal parameters.
for ex:
in main program.
perform addition(a,b). -
> these 2 parameters are called as actual parameters.
actual parameters -
parameters used in sub routine calling
form addition using values
c type i,
d type i. -
> these 2 parameters are called formal parameters
formal parameters -
> parameters used in sub routine definition.
when u r passing values we use VALUE keyword.
CHANGING is used for passing values from main function to a subroutine and changing those values in subroutine.
note: then can also be done using keyword USING.
if helpful reward some points.
with regards,
Suresh Aluri.
09-10-2007 11:38 AM
Hi balaji,
Pls check the below code.
Pass by value
============
x=5.
perform valuechange using x.
write / x.
form valuechange values x.
x=10.
endform.
Result=5
Pass by reference
=============
x=5.
perform valuechange changing x.
write / x.
form valuechange values x.
x=10.
endform.
Result=10
Regards,
Sheron