Guidelines for structural modularizations - onshore and offshore
2016 KBR Modularization Brochure
techniques de couverture contre les risques de changeDescription complète
ASTROLOGY
Kusari Fundo Techniques with Kamae (stances) and Waza.. The Kusari Fundo came in many different shapes and sizes. This is part of a curriculum given to students of the Fudoshin Ninjutsu Dojo…Descripción completa
Kusari Fundo Techniques with Kamae (stances) and Waza.. The Kusari Fundo came in many different shapes and sizes. This is part of a curriculum given to students of the Fudoshin Ninjutsu Dojo Minmi ...
Description complète
Descrição: Reharmonization, Reharmonizacion, Piano, Technique, Keyboard, Jazz
Modularization techniques in SAP ABAP using Function Modules, sub-routines, includes and classes.
Modularization Techniques The concept of modularization is dividing the main program into sub-programs for better readability and re-usability. Modularization can be implemented in the following ways.
Include Programs. Function Modules.
Sub-routines.
Classes.
MACRO`s ( Use in HR ABAP only ).
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 .
Example of using include programs : TYPES : BEGIN OF TY_MARA, MATNR TYPE MARA-MATNR, MTART TYPE MARA-MTART, MEINS TYPE MARA-MEINS, MBRSH TYPE MARA-MBRSH, 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.
To make the above program with includes, follow below steps. INCLUDE ZDATA_DECLERATIONS . "DOUBLE CLICK ON ZDATA_DECLERATIONS AND CREATE A INCLUDE AND ADD DATA DECLERATIONS AND ACTIVATE INCLUDE ZMAIN_LOGIC. " DOUBLE CLICK ON ZMAIN_LOGIC , CREATE A INCLUDE AND ADD THE REMAINING LOGIC (FROM SELECT....TO ....ENDLOOP).
Function Modules
These are also sub-programs which contains set of reusable statements for better readability and re-usability .
Function modules contains parameter interface, that is importing and exporting parameters.
These Function Modules can be executed independently .
Function modules contains exceptions to catch certain type of errors.
Examples for Function Modules are : GUI_DOWNLOAD, GUI_UPLOAD. T-code for Function Module explorer is SE37 . In our next chapters we will learn how to create and use a function module Creating Function Modules in SAP ABAP
Sub-routines in SAP ABAP.
Sub-routines are also sub-programs in SAP ABAP which contains certain re-usable
statements. Most of the times we use sub-routines for re-usability inside the program.
We may use sub-routines for external re-usability.
These sub-routines contains importing and exporting parameters .
Syntax : **DEFINING SUBROUTINE PERFORM USING CHANGING TABLES .
**IMPLEMENTING SUBROUTINE FORM USING CHANGING TABLES .
ENDFORM.
**IN THE ABOVE SYNTAX AND ARE ACTUAL PARAMETERS AND ARE FORMAL PARAMETERS
Using Classes in SAP ABAP
Classes are Object Oriented implementations of SAP ABAP.
Classes are used for better re-usability.
Creating and using of Function Modules in SAP ABAP calling function modules in SAP ABAP programs 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 .
Function Group in SAP ABAP Function group is a container of Function modules, every Function Module must be saved in a Function group. T-codes for Function Modules and Function groups are SE37 OR SE80. We can save N number of Function Modules in a Function Group.
Components of Function Module : Import: These are input parameters of a Function Module. Export: These are output parameters of a Function Module. 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. Select 'Function Group' from drop-down list. Provide a Function Group name ex: ZTFUNCTIONGROUP and press enter.
A Popup will open Click on 'Yes' and provide short text, click on save .
Select Local Object .
Right-Click on Function Group name (ZTFUNCTIONGROUP ) and activate .
Creating Function Module: Here we take a small requirement and create a Function Module. Requirement: Develop a Function Module which displays Material details for a material no. Go to SE37, provide a Function Module name ZSAPN_GET_MATERIAL, click on create.
A pop up will open, provide a Function Group name ZTEST_SAPNUTS and short text, Save .
An information message will come saying that Function Module name is reserved for SAP , just click on continue icon
Add below parameters . Import: Select Import tab and enter IM_MATNR under Parameter name, TYPE under typing and MARA-MATNR under Associated Type, enter. see below image
Export: Select Export tab and enter EX_MARA under Parameter name, TYPE under typing and MARA under Associated Type, enter. see below image
Source Code . Select Source Code tab and write below code to get material details, save as local object and activate.
SELECT SINGLE * FROM MARA INTO EX_MARA WHERE MATNR = IM_MATNR.
Test Function Module .
Click on Execute icon (F8), and give a material no, execute (F8).
It will get material details
Using Function Modules in ABAP Programs CALL FUNCTION is a keyword which is used to call a Function Module in ABAP Programs, now
we use the above created Function Module in our ABAP program. Go to SE38 and Provide name as ZSAPN_GET_MATERIAL and click on Create.
Provide title, select Executable Program from drop-down and Save as local object.
Source Code Declare work area and a input field (parameter) .
DATA : WA_MARA TYPE MARA . "work area to store material details
PARAMETERS : P_MATNR TYPE MARA-MATNR . "Material no input
START-OF-SELECTION. "Default event
To Call a Function Module, click on Pattern
A pop up will open, select CALL FUNCTION radio, provide Function Module name and click on continue icon (tick mark at the bottom).
The below code will be generated. CALL FUNCTION 'ZSAPN_GET_MATERIAL' EXPORTING IM_MATNR
=
IMPORTING EX_MARA
=
IF SY-SUBRC <> 0. * Implement suitable error handling here ENDIF.
Now pass material no parameter and receive material data into a work area, full program code is below. REPORT ZSAPN_GET_MATERIAL. DATA : WA_MARA TYPE MARA .
PARAMETERS : P_MATNR TYPE MARA-MATNR .
START-OF-SELECTION.
CALL FUNCTION 'ZSAPN_GET_MATERIAL' EXPORTING IM_MATNR
= P_MATNR
IMPORTING EX_MARA
= WA_MARA .
IF SY-SUBRC <> 0. * Implement suitable error handling here
ENDIF.
WRITE : WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MEINS, WA_MARA-MBRSH . "Display result
Execute (F8) and test the program. Input Screen
Output
Using exceptions in Function Modules in SAP Exceptions: Exceptions are used to catch certain type of errors in Function Modules. When ever an exception is raised, it will be caught in system variable SY-SUBRC . Continuation to the previous lesson Creating and using of Function Modules in SAP ABAP , we add an exception for no input. In the previous example we are getting material details for a material input, now we add an exception to check whether the input is provided or not. Go to Exceptions tab and add NO_MATNR under Exception and short text .
Write below code under Source Code .
Save, Activate and execute
A popup will open, just click on save without giving any value.
Now you can see NO_MATNR exception.
Using Function module exceptions in SE38 program. When ever an exception is raised, it will be stored in system variable SY-SUBRC .
REPORT ZSAPN_GET_MATERIAL.
DATA : WA_MARA TYPE MARA . PARAMETERS : P_MATNR TYPE MARA-MATNR .
START-OF-SELECTION.
CALL FUNCTION 'ZSAPN_GET_MATERIAL' EXPORTING IM_MATNR
= P_MATNR
IMPORTING EX_MARA
= WA_MARA
EXCEPTIONS NO_MATNR OTHERS
=1 = 2.
IF SY-SUBRC = 1. * Implement suitable error handling here
MESSAGE 'Please enter a material no' TYPE 'E'. ENDIF.
WRITE : WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MEINS, WA_MARA-MBRSH . "Display result
Excute the program without giving any input, we will get an error message.
Using changing and table parameters in Function Modules Requirement: Develop a Function Module to get list of materials for a material type. Analysis: As per business a material type can have 'n' number of materials(we have to use internal tables), so we need to get materials from MARA for a material type input, we have to use function module tables. As per SAP, tables in function modules obsolete, insted using them we can create a table type in SE11, use it as exporting parameter. Changing and Tables are parameters of Function Modules. Changing: Changing parameters acts as both exporting and importing parameters . Tables : These are internal tables which can import and export .
Using Tables in SAP Function Modules Go to SE37,provide name as ZSAPN_FM_TABLES, click on create.
A pop up will open, provide a function group(we have created already), short text and enter.
Go to import tab, provide parameter name as IM_MTART -> TYPE -> MARA-MTART, enter.
Go to tables tab, provide parameter name as T_MARA -> LIKE -> MARA, enter.You will get a warning message saying tables are obsolete just ignore it, hit enter.
Go to source code tab, add below logic to material details.
Execute the Function Module(F8), provide a material type ex: FERT, execute(F8), you will get list of materials for that material type.
Sub-routines in SAP ABAP What are sub-routines in SAP ABAP ? Using sub-routines in SAP ABAP, differences between sub-routines and Function Modules These are also sub programs, which contains set of re-usable statements for doing some specific task. These are mainly used for re-usability with in the same program, how ever we can re-use these sub-routines in other programs too. Sub-routines contains importing and exporting parameters.
Function Modules V/S Sub-routines The main difference between Function Modules and sub-routines is sub-routines dosen`t contain any exceptions and sub-routines are mainly used for local modularization where as function modules contains exceptions and used for global modularization. sub-routines have definition and implementation parts. Syntax:DEFINITION PART: PERFORM USING "DOUBLE CLICK ON SUBROUTINE NAME TO CREATE CHANGING TABLES .
** (VARIABLES), (CHANGING VARIABLES) AND (IMPORTING TABLES) ARE ACTUAL PARAMETERS
Syntax IMPLEMENTATION PART FORM USING CHANGING TABLES .
ENDFORM. **, AND ARE FORMAL PARAMETERS
Sub-routine types and passing values to sub-routines in SAP ABAP Basically there are two types of sub-routines in SAP ABAP programming. 1. Local sub-routines. 2. External sub-routines.
Local sub-routines These are sub-routines in which definition (perform) and implementation (from) are available in the same program.
External sub-routines Sub-routines which contains definition and implementation are available in different programs are called as external sub-routines. The implemented program must be of type sub-routine pool.
Passing values with sub-routines There are three ways to pass the values with sub-routines. 1. Pass by reference. 2. Pass by value. 3. Pass by value and return. 1.Pass by reference In this type, the actual and formal parameters are referred to the same memory. If the formal parameter is changed, the actual parameter is also changed. PERFORM USING . "A IS ACTUAL PARAMETER FORM USING . " F IS FORMAL PARAMETER