Академический Документы
Профессиональный Документы
Культура Документы
CONTENT
● MODULARIZATION TECHNIQUES
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.
● Subroutines.
● 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 does not contain parameter interface, that is no importing
and exporting parameters.
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.
In our next chapters we will learn how to create and use a function module
Creating Function Modules in SAP ABAP
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
We will learn Object Oriented ABAP in next course Using Classes in SAP
ABAP
Tables: These are internal tables which also acts as importing and exporting
parameters.
In this lesson we are going to 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.
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.
Provide a title, select Executable Program from drop-down and Save as local
object.
Source Code
Declare work area and an input field (parameter).
DATA : WA_MARA TYPE MARA . "work area to store material details
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.
ENDIF.
Input Screen
Output
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.
A popup will open, just click on 'Save' without giving any value.
Now you can see NO_MATNR exception.
REPORT ZSAPN_GET_MATERIAL.
START-OF-SELECTION.
Execute the program without giving any input, we will get an error message.
USING CHANGING AND TABLE PARAMETERS IN FUNCTION
MODULES IN SAP
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, instead using them, we can
create a table type in SE11, use it as exporting parameter.
A pop up will open, provide a function group (we have created already), a 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.
These are also sub programs, which contains set of re-usable statements for
doing some specific task.
These are mainly used for re-usability within the same program, however, we
can re-use these Subroutines in other programs too.
**<V1> <V2> (VARIABLES), <CV1> <CV2> (CHANGING VARIABLES) AND <IT1> <IT2>
(IMPORTING TABLES) ARE ACTUAL PARAMETERS
Local Subroutines
These are Subroutines in which definition (perform) and implementation (from)
are available in the same program.
External Subroutines
Subroutines which contains definition and implementation are available in
different programs are called as external Subroutines. The implemented
program must be of type sub-routine pool.
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.
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.
The key word CHANGING( ) will identify that it is pass by value else it is pass
by reference.
By value and result Similar to pass by value, but the contents of Allows changes and
the new memory is copied back into the allows a rollback
original memory before returning.
HOW TO REUSE SUBROUTINES IN SAP ABAP ?
In the below lesson you will be able to learn using tables in performs and re-
usability of performs in different ABAP programs.
Example program 1:
REPORT ZSAPN_SUBROTINE_REUSE1.
DATA : IT_MARA TYPE TABLE OF MARA.
DATA : WA_MARA TYPE MARA.
CONSTANTS: C_MTART TYPE MARA-MTART VALUE 'FERT'. "Constant declaration
Example program 2:
REPORT ZSAPN_SUBROTINE_REUSE2.
Change parameter can be used for one Tables can only be used for multiple
record(work area) as well as multiple records(internal tables).
records(internal tables).
Can be used for input and output. Can be used for input and output.
Same instance will be changed ex: If Instance will be copied and make any
you pass 30 as parameter, if you changes to that, original will not change
change that inside function, the
original variable will be changed
DEBUGGING IN SAP ABAP PROGRAMMING
Dynamic Breakpoints: These breakpoints are user specific, these will trigger
for specific user only. These breakpoints will be deleted automatically when
you log-off from SAP. These can be set in ABAP editor. Dynamic breakpoints
can be set in active (activated) source code only.
Session break-point: This break-point will be activated for call only within
SAP system and its active till the User session is on.
E.g. SE38
When we put break-point in some ABAP code, control will stop at the specific
place when executing the ABAP program, then it is debugging mode. We can
control debugging using function keys F5, F6, F7 and F8 or using toolbar
buttons in debugging screen.
REPORT ZSAPN_DEBUGGING.
SKIP.
REPORT ZSAPN_DEBUG.
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), breakpoint
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.
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.
F8 - When you press F8 in debugging, control will go to next break point if any
or completes the program execution.