Introduction To OOALV
Introduction To OOALV
1 Introduction to OOALV
Introduction to OOALV
Last Updated: February 6th 2014 by Ashok Kumar Reddy
+ -
We all know how to develop ALV reports using standard SAP Function Modules, now we are going
to learn developing ALV reports using Object Oriented approach.
CL_GUI_ALV_GRID.
CL_GUI_CUSTOM_CONTAINER.
CL_DD_DOCUMENT.
CL_GUI_ALV_TREE_SIMPLE.
CL_GUI_CONTAINER.
CL_GUI_SPLITTER_CONTAINER.
We have 'n' number of events available in the classes when compared to ALV with function
modules which is flexible for programmer to develop ALV`s for various scenarios.
We can display more than one ALV grid in single screen.
By using Object Oriented approach we can control the size of ALV grid by using custom
container.
We can place other UI elements like input field, check box etc on the screen.
Steps need to follow to create OOALV
1. Create Screen
2. Insert Custom Container UI element.
3. Create Module.
4. Create instance for Custom Container and add instance to ALV.
5. Get data from tables
6. Set data to ALV
Learner Questions
No Questions by learners, be first one to ask ..!!
+ -
Requirement: Display list of materials in grid format using Object Oriented techniques.
Step1:Data decelerations for ALV, custom container and internal table for MARA.
Step2:Create Screen.
Step3:Insert Custom container UI element into the screen.
Step4:Create Modules PBO and PAO, add logic.
Step5:Display ALV.
Step1: Data decelerations for ALV, Custom Container and MARA.
Add data decelerations for ALV grid, custom container UI element and for MARA internal table.
DATA : LO_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER. "Custom Container
DATA : LO_ALV TYPE REF TO CL_GUI_ALV_GRID. "ALV Grid
DATA : IT_MARA TYPE TABLE OF MARA. "MARA internal table
Learner Questions
+ -
Requirement: Display material no, material type, industry sector, material group and base unit of
mesure of list of materials in grid format using Object Oriented techniques.
Step1:Data decelerations for ALV, custom container and internal table for
MARA(User defined types).
Step2:Create Screen.
Step3:Insert Custom container UI element into the screen.
Step4:Create Modules PBO and PAO, add logic.
Step5:Build field catalogue.
Step6:Display ALV.
Step1: Data decelerations for ALV, Custom Container and user defined types of MARA.
Add data decelerations for ALV grid, custom container UI element and for MARA internal table.Add
select-options for material number.
DATA : LO_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER. "Custom Container
DATA : LO_ALV TYPE REF TO CL_GUI_ALV_GRID. "ALV Grid
TYPES: BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MATKL TYPE MARA-MATKL,
MEINS TYPE MARA-MEINS,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA,
WA_MARA TYPE TY_MARA.
TABLES: MARA.
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.
Provide short description, click on layout, layout designer will open(If you use it first it will take some
time, wait till it comes, if you face any issue while opening contact BASIS, there might be
configuration missing. ).
Step3: Insert Custom Container UI element
Drag and drop custom container UI element, double click and provide a name and save, activate
and close layout designer.
Step4:Create Modules
Click on flow logic, un comment MODULES, double click on each one(one at one time), click yes
and select main program.
Step5,6: Build Field Catalogue.
Field Catalogue: It is a structure which is used to specify out put structre with field names, field
positions, descriptions and additional properties.To see the list of properties of OOALV field
catalogue, go to se11 and check the structure LVC_S_FCAT.
Building of field catalogue is give below.
REPORT ZSAN_OOALV_FCAT.
TABLES: MARA.
TYPES: BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MATKL TYPE MARA-MATKL,
MEINS TYPE MARA-MEINS,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA,
WA_MARA TYPE TY_MARA.
DATA : LO_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER. "custom container
DATA : LO_ALV TYPE REF TO CL_GUI_ALV_GRID. "alv grid
DATA : IT_FIELDCATALOG TYPE LVC_T_FCAT,
WA_FIELDCATALOG TYPE LVC_S_FCAT.
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.
CALL SCREEN 100. "double click to create
MODULE STATUS_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
CREATE OBJECT LO_CONT
EXPORTING
* PARENT =
CONTAINER_NAME = 'CC_ALV'.
CREATE OBJECT LO_ALV
EXPORTING
I_PARENT = LO_CONT.
***Build Field Catalogue
WA_FIELDCATALOG-COL_POS = '1'. "Set column1
WA_FIELDCATALOG-FIELDNAME = 'MATNR'.
WA_FIELDCATALOG-TABNAME = 'MARA'.
WA_FIELDCATALOG-SCRTEXT_M = 'Material No'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR : WA_FIELDCATALOG.
WA_FIELDCATALOG-COL_POS = '2'. "set column2
WA_FIELDCATALOG-FIELDNAME = 'MTART'.
WA_FIELDCATALOG-TABNAME = 'MARA'.
WA_FIELDCATALOG-SCRTEXT_M = 'Material Type'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR : WA_FIELDCATALOG.
WA_FIELDCATALOG-COL_POS = '3'. "set column 3
WA_FIELDCATALOG-FIELDNAME = 'MBRSH'.
WA_FIELDCATALOG-TABNAME = 'MARA'.
WA_FIELDCATALOG-SCRTEXT_M = 'Industry Sector'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR : WA_FIELDCATALOG.
WA_FIELDCATALOG-COL_POS = '4'. "set column 4
WA_FIELDCATALOG-FIELDNAME = 'MATKL'.
WA_FIELDCATALOG-TABNAME = 'MARA'.
WA_FIELDCATALOG-SCRTEXT_M = 'Material Group'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR : WA_FIELDCATALOG.
WA_FIELDCATALOG-COL_POS = '5'. "set column 5
WA_FIELDCATALOG-FIELDNAME = 'MEINS'.
WA_FIELDCATALOG-TABNAME = 'MARA'.
WA_FIELDCATALOG-SELTEXT = 'Unit Of Measure'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR : WA_FIELDCATALOG.
**End field catalogue
SELECT MATNR MTART MBRSH MATKL MEINS FROM MARA
INTO TABLE IT_MARA WHERE MATNR IN S_MATNR.
Learner Questions