Documente Academic
Documente Profesional
Documente Cultură
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.
Include Programs :
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>.
Function Modules
These are also sub-programs which contains set of reusable statements for better
readability and re-usability .
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.
Syntax :
**DEFINING SUBROUTINE
PERFORM <SUBROUTINE NAME> USING <AV1> <AV2>
CHANGING <CHANGING1> <CHANGING2>
TABLES <TABLE1> <TABLE2>.
**IMPLEMENTING SUBROUTINE
FORM <SUBROUTINE NAME> USING <FV1> <FV2>
CHANGING <CHANGING1> <CHANGING2>
TABLES <TABLE1> <TABLE2>.
ENDFORM.
**IN THE ABOVE SYNTAX <AV1> AND <AV2> ARE ACTUAL PARAMETERS AND <FV1>
<FV2> ARE FORMAL PARAMETERS
A Popup will open Click on 'Yes' and provide short text, click on save .
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
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.
Click on Execute icon (F8), and give a material no, execute (F8).
Provide title, select Executable Program from drop-down and Save as local object.
Source Code
Declare work area and a input field (parameter) .
A pop up will open, select CALL FUNCTION radio, provide Function Module name and click on
continue icon (tick mark at the bottom).
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 .
START-OF-SELECTION.
= P_MATNR
IMPORTING
EX_MARA
= WA_MARA .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
Output
A popup will open, just click on save without giving any value.
REPORT ZSAPN_GET_MATERIAL.
START-OF-SELECTION.
= P_MATNR
IMPORTING
EX_MARA
= WA_MARA
EXCEPTIONS
NO_MATNR
OTHERS
=1
= 2.
IF SY-SUBRC = 1.
* Implement suitable error handling here
Excute the program without giving any input, we will get an error message.
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.
Execute the Function Module(F8), provide a material type ex: FERT, execute(F8), you will get list
of materials for that material type.
**<V1> <V2> (VARIABLES), <CV1> <CV2> (CHANGING VARIABLES) AND <IT1> <IT2>
(IMPORTING TABLES) ARE ACTUAL PARAMETERS
ENDFORM.
**<FV1> <FV2>, <FCV1> <FCV2> AND <FIT1> <FIT2> ARE FORMAL PARAMETERS
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.
2.Pass by Value
In this type, the actual and formal parameters will be referring to separate memory. The formal
parameter is changed, the actual parameter will not be changed.
The key word VALUE( ) will identify that it is pass by value else it is pass by reference.
PERFORM GET_MATDATA TABLES IT_MARA USING C_MTART. "perform to get material data
by passing material type
P_C_MTART.
" GET_MATDATA
Example program2:
REPORT ZSAPN_SUBROTINE_REUSE2.
Table Parameters
Change parameter can be used for one record(work area) Tables can only be used for multiple
as well as multiple records(internal tables).
records(internal tables).
Can be used for input and output.
SKIP.
Go to program source code, put cursor where you wants to set break-point and click on set/delete
external break-point icon (see image below).
Now execute the program, provide input ex: FERT and execute (F8), break-point will trigger.
Now go to 'Desktop 3', which is friendly to see run-time variables and data, double click on any
variable to see respected value and data in right pane.
Techniques of debugging
Now, we will learn and understand the real techniques of debugging.
What are uses of F5, F6, F7 and F8 in debugging ?
These are function keys, which are used to control debugging ex: go to next break-point, execute
perform/function module which out going into it etc.
<p.F5 - When you press F5 in debugging, you will go to next step means you program control
goes to next line.
F6 - When you press F6 in debugging, it will execute the module without going into it.F6 works for
performs (subroutines), Function modules, Class methods etc.
Ex for F6: we have a program, we have some function modules in the program, when we click F5
in debugging control will go into function module source code, we don`t want to go into function
module, in that case we use F6, it will not go into function module instead it will execute it in one
step.
<p.F7 - When you press F7 in debugging, it will completes the current module/program in a
single step.
Ex for F7: We have a program, we have a function module in the program, we have put break
point, when we press F7 it will completes the program if the control is in program, when we press
F7 it will complete the module( FM) when the control is in function module.
F8 - When you press F8 in debugging, control will go to next break point if any or completes the
program execution.