11-05-2007 5:22 AM
How do we define a sub-routine in a subroutine pool and how do we call the same in an executable program
11-05-2007 5:32 AM
Hi
Go to SE38.Create a program and in the program type select Subroutine pool.Inside this u can code for teh various subroutines or forms.
For calling these forms these forms in ur main program refer below link:
<u>http://help.sap.com/saphelp_nw04/helpdata/en/9f/db999535c111d1829f0000e829fbfe/content.htm</u>
Sample code:
Below is the subroutine pool used in the creation of the SAP Script:
*----
Program Name : Z689_SUBROUTINE
Date : 03/28/2007
Author : Sayee Manojnah Kasala
Description : This is the subroutine used for SAP Script,
Z689_SAPSCRIPT.It fetches customer details like
customer name & place
*----
PROGRAM Z689_SUBROUTINE.
Form GET_LAND1
Fetches the country key
&----
*& Form get_land1
&----
text
----
-->INTABLE text
-->OUTTABLE text
----
FORM get_land1 TABLES intable STRUCTURE itcsy
outtable STRUCTURE itcsy.
DATA: v_kunnr LIKE kna1-kunnr,
v_land1 LIKE kna1-land1,
v_name1 LIKE kna1-name1.
READ TABLE intable INDEX 1.
v_kunnr = intable-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = v_kunnr
IMPORTING
output = v_kunnr.
IF sy-subrc = 0.
SELECT SINGLE land1
FROM kna1
INTO v_land1
WHERE kunnr = v_kunnr.
IF sy-subrc = 0.
READ TABLE outtable INDEX 1.
outtable-value = v_land1.
MODIFY outtable INDEX 1.
ENDIF.
SELECT SINGLE name1
FROM kna1
INTO v_name1
WHERE kunnr = v_kunnr.
IF sy-subrc = 0.
READ TABLE outtable INDEX 2.
outtable-value = v_name1.
MODIFY outtable INDEX 2.
ENDIF.
ENDIF.
CLEAR: intable,outtable.
ENDFORM. "get_land1
Form GET_LANDX
Fetches the Country Name
&----
*& Form get_landx
&----
text
----
-->INTABLE text
-->OUTTABLE text
----
FORM get_landx TABLES intable STRUCTURE itcsy
outtable STRUCTURE itcsy.
DATA: v_land1 LIKE kna1-land1,
v_landx LIKE t005t-landx.
READ TABLE intable INDEX 1.
v_land1 = intable-value.
IF sy-subrc = 0.
SELECT SINGLE landx
FROM t005t
INTO v_landx
WHERE land1 = v_land1 AND spras = 'E'.
IF sy-subrc = 0.
READ TABLE outtable INDEX 1.
outtable-value = v_landx.
MODIFY outtable INDEX 1.
ENDIF.
ENDIF.
CLEAR: intable,outtable.
ENDFORM. "get_landx
It can be called as follows:
PERFORM GET_LANDX IN PROGRAM Z689_SUBROUTINE
USING &V_LAND1&
CHANGING&V_LANDX&
ENDPERFORM.
Reward points if found useful.
Thanks
Vasudha
Message was edited by:
Vasudha L
11-05-2007 5:45 AM
Hi
Please check
<a href="/people/ravishankar.rajan/blog/2007/03/27/using-subroutine-pools-for-dynamic-programming:///people/ravishankar.rajan/blog/2007/03/27/using-subroutine-pools-for-dynamic-programming
<a href="http://help.sap.com/saphelp_nw04/helpdata/en/9f/db999535c111d1829f0000e829fbfe/frameset.htm">http://help.sap.com/saphelp_nw04/helpdata/en/9f/db999535c111d1829f0000e829fbfe/frameset.htm</a>
Regards
Arun