09-28-2006 4:46 PM
Hi all
Can anybody explain me clearly with a small example abt subroutines.
Thanks and regards
vijaya
09-28-2006 4:49 PM
Check the Sample code:
PERFORM upload_profile_data USING i_profile-profrole
i_profile-profile
i_profile-logikzw
wa_eanl-anlage
wa_dates-date.
FORM upload_profile_data USING p_profrole
p_profile
p_logikzw
p_anlage
p_date.
ENDFORM. " upload_profile_data
or
PERFORM get_no_of_days_next_month USING ws_start_date
CHANGING lws_no_days.
&----
*& Form get_no_of_days_next_month
&----
Get the number of days in next month
----
FORM get_no_of_days_next_month USING p_date TYPE sy-datum
CHANGING p_days TYPE i.
DATA: lws_next_month TYPE sy-datum,
lws_year LIKE mardh-lfgja,
lws_month LIKE mardh-lfmon.
CALL FUNCTION 'FKK_DTE_ADD_MONTH'
EXPORTING
i_datum = p_date
i_nr_of_months_to_add = 1
i_workday_indicator = '+'
IMPORTING
e_result = lws_next_month
EXCEPTIONS
no_date = 1
OTHERS = 2.
IF sy-subrc <> 0.
ELSE.
lws_year = lws_next_month+0(4).
lws_month = lws_next_month+4(2).
PERFORM find_no_of_days USING lws_year lws_month
CHANGING p_days.
ENDIF.
CLEAR: lws_year, lws_month, lws_next_month.
ENDFORM. " get_no_of_days_next_month
09-28-2006 4:48 PM
hi,
START-OF-SELECTION.
PERFORM get_data using v_matnr like mara-matnr
changing v_matnr.
FORM get_data using v_matnr like mara-matnr
changing v_matnr.
ENDFORM.
Regads,
Santosh
09-28-2006 4:49 PM
Check the Sample code:
PERFORM upload_profile_data USING i_profile-profrole
i_profile-profile
i_profile-logikzw
wa_eanl-anlage
wa_dates-date.
FORM upload_profile_data USING p_profrole
p_profile
p_logikzw
p_anlage
p_date.
ENDFORM. " upload_profile_data
or
PERFORM get_no_of_days_next_month USING ws_start_date
CHANGING lws_no_days.
&----
*& Form get_no_of_days_next_month
&----
Get the number of days in next month
----
FORM get_no_of_days_next_month USING p_date TYPE sy-datum
CHANGING p_days TYPE i.
DATA: lws_next_month TYPE sy-datum,
lws_year LIKE mardh-lfgja,
lws_month LIKE mardh-lfmon.
CALL FUNCTION 'FKK_DTE_ADD_MONTH'
EXPORTING
i_datum = p_date
i_nr_of_months_to_add = 1
i_workday_indicator = '+'
IMPORTING
e_result = lws_next_month
EXCEPTIONS
no_date = 1
OTHERS = 2.
IF sy-subrc <> 0.
ELSE.
lws_year = lws_next_month+0(4).
lws_month = lws_next_month+4(2).
PERFORM find_no_of_days USING lws_year lws_month
CHANGING p_days.
ENDIF.
CLEAR: lws_year, lws_month, lws_next_month.
ENDFORM. " get_no_of_days_next_month
09-28-2006 4:52 PM
09-28-2006 5:04 PM
Vijaya,
Check the below link:
Subroutines are procedures that you can define in any ABAP program and also call from any program. Subroutines are normally called internally, that is, they contain sections of code or algorithms that are used frequently locally.
http://help.sap.com/saphelp_470/helpdata/en/9f/db975c35c111d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_470/helpdata/en/9f/db976935c111d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_470/helpdata/en/9f/db977635c111d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_470/helpdata/en/9f/db978335c111d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_470/helpdata/en/9f/db979d35c111d1829f0000e829fbfe/content.htm
Prakash.
09-28-2006 5:04 PM
Hi Durga,
PERFORM ... [USING p1 p2 ... ]
[CHANGING p1 p2 ... ].
Subroutines can call other subroutines (nested calls) and may also call themselves (recursive calls). Once a subroutine has finished running, the calling program carries on processing after the PERFORM statement. You can use the USING and CHANGING additions to supply values to the parameter interface of the subroutine.
<b>Internal Subroutine Calls</b>
To call a subroutine defined in the same program, you need only specify its name in the PERFORM statement:
PERFORM subr [USING p1 p2... ]
[CHANGING p1 p2... ].
<b>External Subroutine Calls</b>
The principal function of subroutines is for modularizing and structuring local programs. However, subroutines can also be called externally from other ABAP programs. In an extreme case, you might have an ABAP program that contained nothing but subroutines. These programs cannot run on their own, but are used by other ABAP programs as pools of external subroutines.
However, if you want to make a function available throughout the system, you should use function modules instead of external subroutines. You create function modules in the ABAP Workbench using the Function Builder. They are stored in a central library, and have a defined release procedure.
You can encapsulate functions and data in the attributes and methods of classes in ABAP Objects. For any requirements that exceed pure functions, you can use global classes instead of external subroutines.
When you call a subroutine externally, you must know the name of the program in which it is defined:
PERFORM subr(prog) [USING p1 p2... ]
[CHANGING p1 p2... ].
for examples,click the below link:
http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db979035c111d1829f0000e829fbfe/content.htm
Thanks
Eswar
09-28-2006 5:35 PM
hi,
Check this example to know how to send parameters pass by reference and pass by value
data: v_one type i value 10,
v_two type i value 10,
v_frst type i value 10,
v_scnd type i value 10.
start-of-selection.
WRITE 😕 'Before calling subroutine'.
write 😕 'V_ONE: ', V_ONE, "10
/ 'V_TWO: ', V_TWO, "10
/ 'V_FRST:', V_FRST, "10
/ 'V_SCND:', V_SCND. "10
perform chng_val using v_one
v_two
changing v_frst
v_scnd.
WRITE 😕 'After coming from subroutine'.
write 😕 'V_ONE: ', V_ONE, "10
/ 'V_TWO: ', V_TWO, "10
/ 'V_FRST:', V_FRST, "20
/ 'V_SCND:', V_SCND. "20
FORM chng_val USING P_V_ONE
value(P_V_TWO)
CHANGING P_V_FRST
value(P_V_SCND).
*Can not be changed as it is passed by reference using USING
* p_v_one = 20.
p_v_two = 20.
p_v_frst = 20.
p_v_scnd = 20.
WRITE 😕 'In subroutine'.
write 😕 'V_ONE: ', V_ONE, "10
/ 'V_TWO: ', V_TWO, "10
/ 'V_FRST:', V_FRST, "20
/ 'V_SCND:', V_SCND. "10
write 😕 'P_V_ONE: ', P_V_ONE, "10
/ 'P_V_TWO: ', P_V_TWO, "20
/ 'P_V_FRST:', P_V_FRST, "20
/ 'P_V_SCND:', P_V_SCND. "20
ENDFORM. " chng_val
Regards,
Sailaja.