on 12-11-2006 5:40 AM
hi, all
how can i use subroutine in sap script?
thanks
Give me ur mail id, I will send u how to decalre the routines in a script
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
We know that some scripts will have driver program as SAP standard programs.Where we do not have much flexibility to modify a/c to our needs.So by using subroutines we can do the needful madifications. Let's say u need to display some value which is not coming from that driver program.But you can't w rite select like command statements in script....So to get the needed values for you u need to write a subrotuine..It is same as any se38 prograM.Just u have to mention that the type of program is subroutine..let say u have written z_sub_rou_test as subrouitne program and z_sub_rou as form in that.. ...where it will take values from script....and send back the needed vales to the script...between which u can do coding according to your requirtements..likew riting select statements using fm's..etc....get the needed value from that and send back that to script...sothat u can sue that in u r output.
In script u just have to write
/: perform 'z_sub_rou' in program in program z_sub_rou_test using &var1& &var2& changing &var3&...these var 1 and var 2 u alerday have in u r hand..coming from actual driving program....send these to u r subrotuinepool and do the needed coding using them..get the values into var3.
In the below i am sending a sample code....the case is we are egtting date format in one way let's say dd/mm/yyyy but we need in dd/mmm/yy...for that we need to find the date mode coming from actual driver program and we ahve to change that mode to the needed way.
===========================================================
================ In SCRIPT ===================================
===========================================================
Code added to print date format on output **************************
PERFORM DATE_FORMAT IN PROGRAM ZGLSTPPUSX_PO_FORMS
USING &EKKO-EBELN&
USING &EKKO-SPRAS&
CHANGING &DATE_FORMAT&
ENDPERFORM
<Z>(&DATE_FORMAT&)</>
===========================================================
================ In SCRIPT ===================================
===========================================================
===========================================================
================ In SUBROUTINE POOL ========================
===========================================================
this DATE_FORMAT form is in ZGLSTPPUSX_PO_FORMS program.
-
*&----
**& Form DATE_FORMAT
*&----
text
*----
-->IN_TAB text
-->OUT_TAB text
*----
*FORM date_format
TABLES in_tab STRUCTURE itcsy
out_tab STRUCTURE itcsy.
*
TYPES: BEGIN OF ty_datfm,
domname TYPE char30,
valpos TYPE numc4,
ddlanguage TYPE SPRAS,
domvalue_l TYPE char10,
domvalue_h TYPE char10,
dontext(60) TYPE c,
domval_ld TYPE char10,
domval_hd TYPE char10,
END OF ty_datfm.
DATA: i_datfm TYPE STANDARD TABLE OF DD07V
INITIAL SIZE 0. " Internal table for datfm
DATA: r_datfm TYPE DD07V. " Work area for datfm
*
*
DATA: l_v_ebeln LIKE ekko-ebeln.
DATA: l_v_spras TYPE spras.
DATA: l_v_land1 TYPE land1_gp.
DATA: l_v_oa_vendor LIKE ekpa-lifn2.
DATA: l_v_datfm TYPE datfm.
DATA: l_k_datfm TYPE char30 VALUE 'DATFM'.
DATA: l_k_text(60) TYPE c.
*
*
*
READ TABLE in_tab INDEX 1.
l_v_ebeln = in_tab-value.
*
READ TABLE in_tab INDEX 2.
l_v_spras = in_tab-value.
*
*
SELECT SINGLE lifn2
INTO l_v_oa_vendor
FROM ekpa
WHERE ebeln = l_v_ebeln AND
parvw = 'BA'. " OA partner function
CHECK sy-subrc = 0.
*
SELECT SINGLE land1
INTO l_v_land1
FROM lfa1
WHERE lifnr = l_v_oa_vendor.
CHECK sy-subrc = 0.
*
SELECT SINGLE datfm
INTO l_v_datfm
FROM t005x
WHERE land = l_v_land1.
*
CALL FUNCTION 'DDIF_DOMA_GET'
EXPORTING
name = l_k_datfm
state = 'A'
langu = l_v_spras
IMPORTING
GOTSTATE =
DD01V_WA =
TABLES
dd07v_tab = i_datfm
EXCEPTIONS
illegal_input = 1
OTHERS = 2.
*
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*
READ TABLE i_datfm INTO r_datfm
WITH key domvalue_l = l_v_datfm
ddlanguage = l_v_spras.
IF sy-subrc = 0.
l_K_text = r_datfm-ddtext.
ENDIF.
*
*
*
*
READ TABLE out_tab INDEX 1.
WRITE l_k_text TO out_tab-value .
MODIFY out_tab INDEX 1.
*ENDFORM. "date_format
===========================================================
================ In SUBROUTINE POOL ========================
===========================================================
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Pei,
You can write a subroutine program in SE38.
Subroutine is like
FORM <SUbroutine name>
TABLES intab structure ITCSY
outtab structure ITCSY.
........
.........
ENDFORM.
Then from your script you can call the subroutine using syntax as follows:
PERFORM <SUbroutine name> in program <Sub program name>
USING ....
CHANGING .....
ENDPERFORM.
Regards,
Vivek Kute.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You go to text editor.
start with command field /:
use nomal perform statement.
Regards,
pankaj singh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.