Académique Documents
Professionnel Documents
Culture Documents
-------------------------code reusabily
reduce redundancy
3 techniques:
--------------1.includes (not executable)
2.subroutines (not executable)
3.Function module(executable)
Include Programs :
------------------These are sub-programs which contains a set of re-usable statements .
These programs can not be executed directly.
These include programs must be embedded inside a main program for execution.
These programs dosen`t contain parameter interface, that is no importing and exporting parameters.
Syntax : INCLUDE <include name>.
Example of using include programs :
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA.
DATA : WA_MARA TYPE TY_MARA.
SELECT MATNR, MTART, MEINS, MBRSH FROM MARA INTO TABLE IT_MATA.
LOOP AT IT_MARA INTO WA_MARA .
SUBROUTINES
---------------> Subroutines are used to avoid the repetation of same kind of code in program.
--> Local to the program , not stored in database.
--> PERFORM is the keywork to create subroutiens.
Syntax:
-------
1.INTERNAL SUBROUTINE : WHEN PERFORM AND FORM---- ENDFORM ARE IN SAME PROGRAM THAT IS
INTERNAL SUBROUTINE.
2.EXTERNAL SUBROUTINE :WHEN PERFORM AND FORM---- ENDFORM ARE IN DIFFERENT PROGRAM
THAT IS INTERNAL SUBROUTINE.
example:
----------tables: vbak.
TYPES: BEGIN OF t_vbap,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
netwr TYPE vbap-netwr,
END OF t_vbap.
WRITE:/ wa_vbap-vbeln,
wa_vbap-posnr,
wa_vbap-matnr,
wa_vbap-netwr.
ENDLOOP.
ENDIF.
*&---------------------------------------------------------------------*
*&
Form fr_get_sales_data
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_PA_VBELN text
<--P_I_VBAP text
*----------------------------------------------------------------------*
FORM fr_get_sales_data USING c_VBELN
CHANGING c_VBAP like i_vbap.
select vbeln
posnr
matnr
netwr
from vbap
into table c_vbap
where vbeln = c_vbeln.
ENDFORM.
" fr_get_sales_data
report ztx1801.
data: f1 value 'A',
f2 value 'B',
f3 value 'C'.
OUTPUT:
ABC
ABC
EX:
data f1 value 'A'.
OUTPUT
X
f4 value 'D',
f5 value 'E',
f6 value 'F'.
perform s1 using f1 f2
changing f3 f4.
perform s2 using f1 f2 f3 f4
changing f5 f6.
endform.
OUTPUT:
ABCD
ABCDEF
ABC
Function Modules(SE37)
----------------
Function Modules are sub-programs which contains set of re-usable statements with importing,
exporting parameters, exceptions. Unlike include programs Function Modules can be executed
independently .
Changing: These are parameters which acts as importing and exporting parameters to a Function
Module .
Tables: These are internal tables which also acts as importing and exporting parameters.
Exceptions: Exceptions in Function Modules are used to catch certain type of errors .
In this lesson we are going learn how to create Function Group and Function Module, in order to create
a Function Module we need a Function Group ( We can save in existing one also), follow the below steps
to create a Function Group.
Go to SE80.
TABLES
I_VBAK = I_VBAK.
************************************************************************
FUNCTION ZFUNCMOD_99.
*"---------------------------------------------------------------------*"*"Local Interface:
*" IMPORTING
*"
*" TABLES
*"
*"----------------------------------------------------------------------
ENDFUNCTION.