Breaking it Down: Exploring Modularization Techniques in ABAP Programming
Welcome back everyone, We have just finished our classical reports in our last blog, So let’s start with Modularization Techniques.
Modularization Techniques :-
- Modularization is a technique used to divide the application program into smaller units.
- This helps to maintain the code in an easy manner and reduce the code redundancy.
- The various modularization techniques are as follows :-
- Includes
- Function Modules
- Subroutines
- Class-Methods
1. Include Programs/Includes :-
- Include Program is a modularization technique. We use include programs to organize a program code in to smaller units.
- We can create include programs with the help of SE38(ABAP Editor).
- The type of include programs is ‘I’.
- We can not execute a include program.
- We can reuse the same include program multiple times in our executable reports.
- The most important use of include programs is for lengthy data declarations used in different programs.
The Syntax to use a Include Program in to another type of program :-
- INCLUDE <include program name>.
- Example :- include program name is ZDATA.
- The syntax to reuse include program ZDATA in to another types of programs is INCLUDE ZDATA.
Creating a Include Program :-
-
Step 1 :- Go to SE38 transaction code { ABAP EDITOR }
-
Step 2 :- Write a name → select Source code radio button and click on create button.
-
Step 3 :- Select include program and click on create.
-
Step 4 :- Now Suppose, I want to write all the data declarations of one of my report into this, include.
-
Step 5 :- Now, I can simply replace the data declaration part of my report with the name of this include program.
Note :-
- In the project, make sure to write all the data declarations part inside a include programs.
- We cannot execute a Include program, but we can include them inside a executable program.
Include Program Code :-
**************************************************************************
*start of Program
*Declaring the type structure
TYPES: BEGIN OF ty_header,
order_number TYPE zar_order_number,
order_date TYPE zar_order_date,
payment_mode TYPE zar_payment_mode,
total_amount TYPE zar_total_amount,
currency TYPE zar_curency,
END OF ty_header.
TYPES : BEGIN OF ty_item,
order_number TYPE zar_order_number,
order_item_number TYPE zar_order_item_number,
item_cost TYPE zar_total_amount,
END OF ty_item.
*Declaring the final type structure
TYPES: BEGIN OF ty_final,
order_number TYPE zar_order_number,
order_date TYPE zar_order_date,
payment_mode TYPE zar_payment_mode,
total_amount TYPE zar_total_amount,
currency TYPE zar_curency,
order_item_number TYPE zar_order_item_number,
item_cost TYPE zar_total_amount,
END OF ty_final.
*********************************************************
*Declaring the internal table and work area
DATA : lt_header TYPE TABLE OF ty_header,
ls_header TYPE ty_header,
lt_item TYPE TABLE OF ty_item,
ls_item TYPE ty_item,
lt_final TYPE TABLE OF ty_final,
ls_final TYPE ty_final.
DATA : lv_index TYPE i.
Report including the above include program :-
INCLUDE ZAR_INCLUDE_DATA_DECLARATION.
********************************************************
****************************************
*Defining Selection Screen
DATA : lv_order TYPE zar_order_number.
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : s_order FOR lv_order.
SELECTION-SCREEN : END OF BLOCK b1.
*end of Selection Screen
***************************************************************
****************************************
*Writing Select queries
SELECT * FROM zar_header INTO CORRESPONDING FIELDS OF
TABLE lt_header WHERE order_number IN s_order.
IF lt_header IS NOT INITIAL.
SELECT * FROM zar_item INTO CORRESPONDING FIELDS OF
TABLE lt_item FOR ALL ENTRIES IN lt_header
WHERE order_number = lt_header-order_number.
*****************************************************
*Looping to store data in final table
IF lt_item IS NOT INITIAL.
SORT lt_item BY order_number.
LOOP AT lt_header INTO ls_header.
*Performing Read operation
READ TABLE lt_item INTO ls_item WITH KEY
order_number = ls_header-order_number BINARY SEARCH.
IF sy-subrc EQ 0.
lv_index = sy-tabix.
ENDIF.
LOOP AT lt_item INTO ls_item FROM lv_index."WHERE order_number = ls_header-order_number.
IF ls_header-order_number <> ls_item-order_number.
EXIT.
ELSE.
ls_final-order_item_number = ls_item-order_item_number.
ls_final-item_cost = ls_item-item_cost.
ls_final-order_number = ls_header-order_number.
ls_final-order_date = ls_header-order_date.
ls_final-payment_mode = ls_header-payment_mode.
ls_final-total_amount = ls_header-total_amount.
ls_final-currency = ls_header-currency.
ENDIF.
ENDLOOP.
APPEND ls_final TO lt_final.
CLEAR : ls_final, ls_header, ls_item.
ENDLOOP.
***End of Loop
*************************************************
*Displaying the output.
LOOP AT lt_final INTO ls_final.
WRITE :/ ls_final-order_number,
ls_final-order_date,
ls_final-payment_mode,
ls_final-total_amount,
ls_final-currency,
ls_final-order_item_number,
ls_final-item_cost.
ENDLOOP.
ENDIF.
ENDIF.
*end of Program
****************************************************************************
Execute the Report :-
-
Press F8.
So, that’s enough for today, We will discuss function modules in the next blog.
Comments
Post a Comment