‎2007 Dec 05 11:38 AM
Hi in subroutine Form how 'changing, varying,using' used to pass parameters?Give simple example to understand.
‎2007 Dec 05 11:41 AM
hi
check this perform
PERFORM f_report_display TABLES t_ekko
t_ekpo
t_fieldcat
t_events
t_alv_sort
USING x_print.
FORM f_report_display TABLES p_t_header LIKE t_ekko
p_t_item LIKE t_ekpo
p_t_fieldcat LIKE t_fieldcat
USING p_x_print TYPE slis_print_alv.
DATA: l_repid TYPE sy-repid.
l_repid = sy-repid.
t_keyinfo-header01 = 'EBELN'.
t_keyinfo-item01 = 'EBELN'.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_callback_program = l_repid
i_callback_user_command = c_user_command
it_fieldcat = p_t_fieldcat[]
i_default = 'X'
i_tabname_header = 'T_EKKO'
i_tabname_item = 'T_EKPO'
is_keyinfo = t_keyinfo
is_print = p_x_print
TABLES
t_outtab_header = p_t_header[]
t_outtab_item = p_t_item[].
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
regars
kk.
‎2007 Dec 05 11:41 AM
‎2007 Dec 05 11:42 AM
hi
call by reference
REPORT ZSUBREFERENCE.
data : num1 type i value 5,
num2 type i value 4,
sum type i.
perform addition using num1 num2 .
sum = num1 + num2.
write : sum.
&----
*& Form addition
&----
text
----
-->P_NUM1 text
-->P_NUM2 text
<--P_SUM text
----
form addition using p_num1
p_num2.
p_num1 = 8.
p_num2 = 9.
sum = p_num1 + p_num2.
write sum.
endform. " addition
call by value
REPORT ZSUBREFERENCE.
data : num1 type i value 5,
num2 type i value 4,
sum type i.
perform addition using num1 num2 .
sum = num1 + num2.
write : sum.
&----
*& Form addition
&----
text
----
-->P_NUM1 text
-->P_NUM2 text
<--P_SUM text
----
form addition using value(p_num1)
value( p_num2).
p_num1 = 8.
p_num2 = 9.
sum = p_num1 + p_num2.
write sum.
endform. " addition
Reward for use ful points
Regards
Nagesh.Paruchuri
‎2007 Dec 05 11:45 AM
Hi,
go thru this.
Defining Subroutines
A subroutine is block of code introduced by FORM and concluded by ENDFORM. Following syntax is used to define a form or subroutine:
FORM <name> <parameters>
. . ..
ENDFORM.
Here parameters is optional. You can have plain subroutine without the parameters for example.
FORM SUB1.
. .
.
ENDFORM.
Calling Subroutines
You can call subroutines from program by following statement:
PERFORM <subr> [<para>].
Parameters are optional. i.e., you can call subroutine without passing any parameter
Perform SUB1.
Passing Data to Subroutines
When you work with global data in subroutines, you can put a copy of the global data on a local data stack and use it to avoid accidental loss of data (In this way you protect global data.)
You can pass data between calling program and subroutines by using parameters.
Parameters, which are defined during definition of a subroutine with FORM statement are called formal parameter.
Parameters which are specified during the call of a subroutine with the PERFORM statement are called actual parameter.
Parameters are passed to the FORM either:
By value
By Reference
By value and return.
By Value
Data : a type I value 20.
Perform sub1 using a.
Write a.
FORM sub1 using value (p_a)
P a = 15
ENDORM.
In this case during subroutine call, the formal parameter are created as copies of actual parameter.
The formal parameters have the memory of their own. Changes made to formal parameter have no effect on the actual parameter.
Like in this case, though value of p_a is changed to 15, it has no effect on a which remains as 20.
By Reference
Data: a type I value 20.
Perform sub1 using a.
Write a.
FORM sub1 using value (p_a)
P a = 15.
ENDORM.
By default system calls all the forms by reference.
In this case, only the address of the actual parameter is transferred to the formal parameters. The formal parameter has no memory of its own. If you change the formal parameter, change is visible in actual parameter also.
By Value and Return
<b>Data : a type I value 20.
Perform sub1 changing a.
FORM sub1 changing value (p_a)
P a = 15.</b> ENDORM.
In this case if you change formal parameter, then the value of actual parameter is changed when the control is transferred back to the main program.
Assuming A is declared by DATA statement and has value 20 and subroutine SUB1 is called by passing A.
Regards
Srinu
‎2007 Dec 05 12:09 PM
what is the difference betwn 'by reference' and 'by value and result' ?