2006 Oct 16 12:13 PM
Hi all
Iam still confused..ican understand theory wise..when iam trying to implement iam getting lot of doubts..esepcially when passing parameters using USING and CHANGING.i understood the perform part...when we r defining the perfrom using Form iam getting stuck...please is there any other way which can explain me better..the examples given by u's r very good..but i need more clear and easy ones...please.
Thanks and regards
vijaya
2006 Oct 16 12:17 PM
Hi,
When you call a subroutine with USING <param>
inside the subroutine you will be using the value of param to make some other processing for other variables, not to change the param itself.
where as when you call a subroutine with CHANGING <param>,
you will be making some changes to the value param and sending it back to the main program.
Rgds,
HR
2006 Oct 16 12:17 PM
Hi,
When you call a subroutine with USING <param>
inside the subroutine you will be using the value of param to make some other processing for other variables, not to change the param itself.
where as when you call a subroutine with CHANGING <param>,
you will be making some changes to the value param and sending it back to the main program.
Rgds,
HR
2006 Oct 16 12:23 PM
Hi Vijaya,
Check the sample code for subroutine:
data: date type sy-datum value '20061010'.
perform get_data using date
changing date1.
write: date1.
form get_data using p_date type sy-datum
p_date1 type sy-datum.
p_date1 = p_date + 1.
endform.
Reward points if it helps.
Manish
2006 Oct 16 12:24 PM
Hi Vijaya,
It is a very simple concept that explains the modularization of coding.
The parameters using and changing is almost the same.
eg:- perform display using p1 changing p2.
you can pass values inside the subroutines in both the cases, but the u can change the value of P2 only. Outside the routine p1 has the same value at the time of passing.
If still have confusion , go through the link
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db979d35c111d1829f0000e829fbfe/content.htm
Reward if it helps.
Thanks,
Anoop
2006 Oct 16 12:31 PM
Hi Vijaya
Will try to keep it simple for you. Please copy below code into a temporary program, execute and check the results.
data: l_num1 type i value 1,
l_num2 type i value 2.
data: begin of itab occurs 0,
fld1(10) type c,
end of itab.
itab-fld1 = 'Initial'.
append itab.
*** here l_num1 has value 1, l_num2 has value 2 &
*** itab-fld1 has value Initial.
write:/ 'Before Subroutine'.
write:/ 'l_num1:', l_num1.
write:/ 'l_num2:', l_num2.
loop at itab.
write:/ 'itab-fld1:', itab-fld1.
endlloop.
skip 2.
*** now perform
perform change tables itab
using l_num1
changing l_num2.
skip 2.
write:/ 'After Subroutine:'.
write:/ 'l_num1:', l_num1.
write:/ 'l_num2:', l_num2.
loop at itab.
write:/ 'itab-fld1:', itab-fld1.
endlloop.
*** form
form change table itab
using l_num1
chaning l_num2.
write:/ 'Within subroutine'.
*** supposingly we change all values in the subroutine
l_num1 = 5.
l_num2 = 10.
itab-fld1 = 'routine'.
append itab.
write:/ 'l_num1:', l_num1.
write:/ 'l_num2:', l_num2.
loop at itab.
write:/ 'itab-fld1:', itab-fld1.
endlloop.
endform.
You will find value of l_num1 is same before and after subroutine as we have used USING declaration for l_num1.
Also you can observer that values for declaring as CHANGING and TABLES get changed by the subroutine call.
Hope i have tried to keep it simple.
As i am not on SAP now, please bear with syntax errors.
Kind Regards
Eswar
2006 Oct 16 1:08 PM
Hi,
Go thru this Docu.
PERFORM - parameter_list
Syntax
... [TABLES itab1 itab2 ...]
[USING a1 a2 ...]
[CHANGING a1 a2 ...].
Extras:
1. ... TABLES itab1 itab2 ...
2. ... USING a1 a2 ...
3. ... CHANGING a1 a2 ...
Effect
These additions assign actual parameters to the formal parameters from the parameter interface for the subroutine subr. You can specify all data objects whose data type matches the typing of the corresponding formal parameter (see Check Typing) as actual parameters. Each formal parameter assumes all the properties of the actual parameter assigned to it when it is called.
Addition 1
... TABLES itab1 itab2 ...
Effect
If you specify the addition TABLES, each table parameter t1 t2 ... for the subroutine called that is defined with the addition TABLES to the FORM statement must be assigned an internal table itab as the actual parameter. The assignment of the actual parameters to the formal parameters takes place using their positions in the lists t1 t2 ... and itab1 itab2 ... .
You can only specify standard tables for itab. Transfer takes place by means of a reference. If a specified table itab has a header line, this is also transferred; otherwise, the header line in the corresponding table parameter t is blank when it is called.
Note
Use of table parameters in the interface for subroutines is obsolete but a large number of subroutines have not yet been converted to appropriately typed USING or CHANGING parameters, so that they must still be supplied with data by the TABLES addition to the PERFORM statement.
Example
Static call of the internal subroutine select_sflight transferring a table parameter.
PARAMETERS: p_carr TYPE sflight-carrid,
p_conn TYPE sflight-connid.
DATA sflight_tab TYPE STANDARD TABLE OF sflight.
...
PERFORM select_sflight TABLES sflight_tab
USING p_carr p_conn.
...
FORM select_sflight TABLES flight_tab LIKE sflight_tab
USING f_carr TYPE sflight-carrid
f_conn TYPE sflight-connid.
SELECT *
FROM sflight
INTO TABLE flight_tab
WHERE carrid = f_carr AND
connid = f_conn.
ENDFORM.
Addition 2
... USING a1 a2 ...
Addition 3
... CHANGING a1 a2 ...
Effect
If you specify the additions USING and CHANGING, an actual parameter a1 a2 ... of the appropriate type must be assigned to each of the formal parameters u1 u2 ... and c1 c2 ... defined with the same additions to the FORM statement. The actual parameters specified after USING and CHANGING form one shared list. They are assigned to the formal parameters after the position in the shared list. The type of parameter transfer is defined with the additions USING and CHANGING to the FORM statement. The addition USING must be before CHANGING. Otherwise, the assignment of the actual parameters to the additions USING and CHANGING is irrelevant to the PERFORM statement. It is also irrelevant whether only one or both of the additions is specified.
Notes
For the sake of program documentation, we advise that you specify the additions USING and CHANGING in the FORM statement according to the definition of the parameter interface.
In non-Unicode programs, you can address memory area outside an actual parameter if an actual parameter a1 a2 ... is assigned offset or length specifications. In non-Unicode programs, the length is set to the length of the current parameter if an offset is specified without a length. Both of these lead to warnings in the syntax check and to syntax errors in Unicode programs. The rules for the ASSIGN statement apply to the addressable memory area in non-Unicode programs.
Example
The following five PERFORM statements mean the same but only the fourth is recommended, since it is the only one that documents the interface of the subroutine called.
DATA: a1 TYPE string,
a2 TYPE string,
a3 TYPE string,
a4 TYPE string.
PERFORM test USING a1 a2 a3 a4.
PERFORM test CHANGING a1 a2 a3 a4.
PERFORM test USING a1 CHANGING a2 a3 a4.
PERFORM test USING a1 a2 CHANGING a3 a4.
PERFORM test USING a1 a2 a3 CHANGING a4.
...
FORM test USING p1 TYPE string
p2 TYPE string
CHANGING value(p3) TYPE string
value(p4) TYPE string.
...
ENDFORM.
Thanks
Sunil
2006 Oct 16 1:22 PM
Have a look at below link of sap help. It wil give you conceptual details with examples.
http://help.sap.com/saphelp_ehs27b/helpdata/en/9f/db977635c111d1829f0000e829fbfe/content.htm
Best Regards,
Vibha
*Please mark all the helpful answers