SlideShare a Scribd company logo
By Noman Hanif
Object Oriented ALV
Introduction
 The SAP List Viewer is a generic tool that outputs data in a table form (rows and
columns), with integrated functions to manipulate output (sort, totals, filter,
column order, hide, etc.) and export it (Excel, Crystal report, CSV files, etc.) It is
also possible to make ALV editable via ALV control.
 ALV name comes from "ABAP List Viewer", as named initially because it was
only available in ABAP. It is now a more general concept, which is available in
java too (since version 7.1).
 ALV tool proposes 3 display types (schemes are taken from the SAP Library -
An Overview of ALV Tools) and in several technologies:
 Display types:
o Simple List
o Hierarchical Sequential List
o Tree
 Technologies
o List
o Control Framework : A control is made available for ALV’s , known as ALV Grid. It
can be used in 3 ways:
 Function module wrapper. It may be used in Full screen mode, which means
that the buttons are displayed in the application toolbar, and also in popup
mode (REUSE_ALV_GRID_DISPLAY).
 Object oriented wrapper (CL_GUI_ALV_GRID)
Display in full screen using FM: REUSE_ALV_GRID_DISPLAY
The New Object Model
New object oriented API
 Simplifies programming
 Error robustness
o Data-type information about internal table is determined by the ALV
o Wrong parameterization raises exceptions
o Constants for correct parameterization provided
 Unified object model for all ALV flavors (Grid, Tree, etc.)
o Single class for handling tabular data
o Unified constants definition
o Common meta data model for all ALV flavors
Object oriented approach to ALV Lists in ABAP
Object oriented approach to ALV Lists in ABAP
Main Principle prior to the New Object
Model
Main Principle of the New Object Model
(Simplest Call)
In case of object oriented concept the control framework is required as it provides global
classes for various functionalities:
CL_GUI_ALV_GRID
It is the wrapper class implemented to encapsulate ALV grid functionality for list
display. ALV Grid control is a flexible tool which provides following capabilities:
• For building and displaying interactive, non-hierarchical and modern-design lists.
• Provides typical list functions such as sorting, filtering, summing etc.
• Provides common list operations and can be enhanced by user-defined options.
Basic components required for ALV Grid Control are:
1. List Data: Data to be listed is populated in an internal table. This table can be of
any flat type.
2. Field Catalog: This is an internal table which contains the list of fields as per
specification. It comprises of some additional information about display options for
each column to be displayed.
• It must be referenced to the dictionary type “LVC_T_FCAT” while the work-area
should be of type “LVC_S_FCAT”. Function “LVC_FIELDCATALOG_MERGE” can
also be used to get field catalog by passing structure name.
3. Container: Container is a storage area where the list will be displayed. It should
be of type ”CL_GUI_CUSTOM_CONTAINER”.
Other Container classes are:
• CL_GUI_DOCKING_CONTAINER:
For displaying multiple ALV’s by using methods such as dock_at_left,
dock_at_right, dock_at_top, dock_at_bottom. Internal tables can be displayed
in these containers.
 CL_GUI_EASY_SPLITTER_CONTAINER:
For displaying two ALV Grids on single screen, container is splitted into two
containers by using this class.
4. Layout Structure: It is a structure to specify general layout options for the
grid. With this structure we can set general display options, grid customizing,
totals options, color adjustments etc. The layout structure must be of type
“LVC_S_LAYO”.
4. Event Handler: For handling events, we need to define and implement an
event handler class triggered by the ALV Grid instance. After creating ALV Grid
instance, we must register an instance of this event handler class to handle
ALV Grid events.
Layout Structure
Events List
General Declarations and Steps to Create Object-oriented
ALV:
 Create object of class CL_GUI_CUSTOM_CONTAINER for container.
 Create object of class CL_GUI_ALV_GRID for putting Grid in above container.
 Populate the internal table that you want to display on the Grid.
General Declarations and Steps to Create Object-oriented
ALV:
 Call the screen that contains Custom Container which is done at PBO of screen.
 METHOD SET_TABLE_FOR_FIRST_DISPLAY of class CL_GUI_ALV_GRID is
used to display the output
 In SAP Netweaver 2004, SAP introduced a new Object Oriented ALV list family
class, called CL_SALV. It consists of different ALVs such as table, hierarchy,
and tree.
 CL_SALV_TABLE in SE24 transaction.
Object oriented approach to ALV Lists in ABAP
Development
 In this subroutine we use get_flight_schedule, the initialize_alv, and
the display_alv.
 Get the list of flight schedule
 In this subroutine, we are going to query the top 100 rows from the database
table,SPFLI and save the received records into an internal table, flight_schedule.
 To use the OO CL_SALV_TABLE class, we need to create an instance of it. We can
instantiate it by calling its factory() method
 We are going to define it as reference variable to the class,CL_SALV_TABLE.
 Display the ALV List
 The Result
Enable Layout Settings
 The subroutine,INITIALIZE_ALV in the following order: first we call
the FACTORY() method of the CL_SALV_TABLE to get an instance of it, then
call the subroutines that responsible for different settings.
 We are going to get and save an instance of the CL_SALV_LAYOUT in the variable,
called LAYOUT_SETTINGS by calling the instance method of the CL_SALV_TABLE
class, called GET_LAYOUT().
 We usually set a unique key to make the different ALV layout settings unique between
each other, and set a restriction for saving the layouts.
 To set a unique key we use the SET_KEY() method of the CL_SALV_LAYOUT class
that requires a SALV_S_LAYOUT_KEY structure as an import parameter.
 If we check the SET_SAVE_RESTRICTION() method, we find that it requires a
parameter with the type SALV_DE_LAYOUT_RESTRICTION. To provide a value with
this type, we are going to use the IF_SALV_C_LAYOUT interface that contains three
different attributes:
 The attributes mean the following:
 The Result
Optimize Column Width
 We are going to place the call of our next setting (OPTIMIZE_COLUMN_WIDTH) in
the subroutine, called INITIALIZE_ALV.
 To customize the columns of an ALV, we need an instance of the
class, CL_SALV_COLUMNS_TABLE that we are going to get by calling the
CL_SALV_TABLE method, called GET_COLUMNS(), and save the received instance
reference in a reference variable, named COLUMNS (it refers to the class,
CL_SALV_COLUMNS_TABLE ).
 We want to optimize the width of the columns, so that we call the
method, SET_OPTIMIZE(). It has an optional importing bool parameter,
named VALUE that is true by default.
 Before optmizing the columns width.
 After optimizing the columns width.
Individual Column Settings
 OPTIMIZE_COLUMN_WIDTH subroutine into the INITIALIZE_ALV subroutine, since
we want to initialize only once, and reuse it several times, so I think it belongs to this
place.
 In the OPTIMIZE_COLUMN_WIDTH subroutine
 Get the reference of the MANDT column by calling the method, GET_COLUMN() on
the columns object (columns contains all of the columns from the table, SPFLI), and
then let's call its method, named SET_VISIBLE() with false. At last, let's wrap these
method calls into a TRY-CATCH block to handle exceptions (now we have to handle
the case when doesn't exist any field in the structure with the name, MANDT).
 Place its declaration in the global area for the sake of the simplicity with the
type CL_SALV_COLUMN.
 Set text for column
THANK YOU!!

More Related Content

What's hot (20)

PPT
Module pool programming
Subhojit- Opekkhay
 
PDF
Abap object-oriented-programming-tutorials
cesarmendez78
 
PPTX
Reports
Jugul Crasta
 
PDF
Table maintenance generator and its modifications
scribid.download
 
PPT
ABAP Advanced List
sapdocs. info
 
PPTX
Sap abap
Jugul Crasta
 
PPT
Alv theory
Phani Kumar
 
PDF
Abap reports
Milind Patil
 
DOC
Badi document
hamisha_malik
 
PPT
BATCH DATA COMMUNICATION
Kranthi Kumar
 
PDF
SAP ABAP data dictionary
Revanth Nagaraju
 
PPTX
Core Data Service
Sujoy Saha
 
PPTX
SAP Smart forms
Jugul Crasta
 
PDF
Introducing enhancement framework.doc
Kranthi Kumar
 
PDF
Enhancement framework the new way to enhance your abap systems
Kranthi Kumar
 
DOC
Basic Debugging
Sathish Kumar G
 
PPTX
CDS Views.pptx
Suman817957
 
PPTX
Oops abap fundamental
biswajit2015
 
PPTX
Smart form
Tarek Yehia
 
PPTX
SAP ALE Idoc
Jugul Crasta
 
Module pool programming
Subhojit- Opekkhay
 
Abap object-oriented-programming-tutorials
cesarmendez78
 
Reports
Jugul Crasta
 
Table maintenance generator and its modifications
scribid.download
 
ABAP Advanced List
sapdocs. info
 
Sap abap
Jugul Crasta
 
Alv theory
Phani Kumar
 
Abap reports
Milind Patil
 
Badi document
hamisha_malik
 
BATCH DATA COMMUNICATION
Kranthi Kumar
 
SAP ABAP data dictionary
Revanth Nagaraju
 
Core Data Service
Sujoy Saha
 
SAP Smart forms
Jugul Crasta
 
Introducing enhancement framework.doc
Kranthi Kumar
 
Enhancement framework the new way to enhance your abap systems
Kranthi Kumar
 
Basic Debugging
Sathish Kumar G
 
CDS Views.pptx
Suman817957
 
Oops abap fundamental
biswajit2015
 
Smart form
Tarek Yehia
 
SAP ALE Idoc
Jugul Crasta
 

Similar to Object oriented approach to ALV Lists in ABAP (20)

PDF
Alv object model simple 2 d table - the basics
Faina Fridman
 
PPT
Lecture15 abap on line
Milind Patil
 
PDF
An easy reference for alv grid control (1)
Faina Fridman
 
TXT
Sample1
aramprasanth86
 
PDF
Learning & using new technology
Michelle Crapo
 
PDF
Learning & using new technology
Michelle Crapo
 
DOCX
Grid view control
Paneliya Prince
 
PDF
Sap abap
Sri Nivas
 
TXT
Alvedit programs
mcclintick
 
PDF
812395816
2009nikola
 
PPTX
1606802425-dba-w7 database management.pptx
ubaidullah75790
 
PDF
ABAP for Beginners - www.sapdocs.info
sapdocs. info
 
PDF
Beginner's Guide: Programming with ABAP on HANA
Ashish Saxena
 
DOC
Alv Grids
Michelle Crapo
 
PPSX
SAP ABAP online training
Imagine life
 
PDF
Step by Step Asp.Net GridView Tutorials
Nilesh kumar Jadav
 
PPTX
SAP ABAP Online Course Training | Imaginelife
Imagine life
 
PPTX
Pl sql best practices document
Ashwani Pandey
 
PPT
Writing Maintainable Code
Donald Bales
 
PPT
Writing maintainable Oracle PL/SQL code
Donald Bales
 
Alv object model simple 2 d table - the basics
Faina Fridman
 
Lecture15 abap on line
Milind Patil
 
An easy reference for alv grid control (1)
Faina Fridman
 
Learning & using new technology
Michelle Crapo
 
Learning & using new technology
Michelle Crapo
 
Grid view control
Paneliya Prince
 
Sap abap
Sri Nivas
 
Alvedit programs
mcclintick
 
812395816
2009nikola
 
1606802425-dba-w7 database management.pptx
ubaidullah75790
 
ABAP for Beginners - www.sapdocs.info
sapdocs. info
 
Beginner's Guide: Programming with ABAP on HANA
Ashish Saxena
 
Alv Grids
Michelle Crapo
 
SAP ABAP online training
Imagine life
 
Step by Step Asp.Net GridView Tutorials
Nilesh kumar Jadav
 
SAP ABAP Online Course Training | Imaginelife
Imagine life
 
Pl sql best practices document
Ashwani Pandey
 
Writing Maintainable Code
Donald Bales
 
Writing maintainable Oracle PL/SQL code
Donald Bales
 
Ad

Recently uploaded (20)

PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Ad

Object oriented approach to ALV Lists in ABAP

  • 1. By Noman Hanif Object Oriented ALV
  • 2. Introduction  The SAP List Viewer is a generic tool that outputs data in a table form (rows and columns), with integrated functions to manipulate output (sort, totals, filter, column order, hide, etc.) and export it (Excel, Crystal report, CSV files, etc.) It is also possible to make ALV editable via ALV control.  ALV name comes from "ABAP List Viewer", as named initially because it was only available in ABAP. It is now a more general concept, which is available in java too (since version 7.1).  ALV tool proposes 3 display types (schemes are taken from the SAP Library - An Overview of ALV Tools) and in several technologies:  Display types: o Simple List
  • 4.  Technologies o List o Control Framework : A control is made available for ALV’s , known as ALV Grid. It can be used in 3 ways:  Function module wrapper. It may be used in Full screen mode, which means that the buttons are displayed in the application toolbar, and also in popup mode (REUSE_ALV_GRID_DISPLAY).  Object oriented wrapper (CL_GUI_ALV_GRID) Display in full screen using FM: REUSE_ALV_GRID_DISPLAY
  • 5. The New Object Model New object oriented API  Simplifies programming  Error robustness o Data-type information about internal table is determined by the ALV o Wrong parameterization raises exceptions o Constants for correct parameterization provided  Unified object model for all ALV flavors (Grid, Tree, etc.) o Single class for handling tabular data o Unified constants definition o Common meta data model for all ALV flavors
  • 8. Main Principle prior to the New Object Model
  • 9. Main Principle of the New Object Model (Simplest Call)
  • 10. In case of object oriented concept the control framework is required as it provides global classes for various functionalities: CL_GUI_ALV_GRID It is the wrapper class implemented to encapsulate ALV grid functionality for list display. ALV Grid control is a flexible tool which provides following capabilities: • For building and displaying interactive, non-hierarchical and modern-design lists. • Provides typical list functions such as sorting, filtering, summing etc. • Provides common list operations and can be enhanced by user-defined options.
  • 11. Basic components required for ALV Grid Control are: 1. List Data: Data to be listed is populated in an internal table. This table can be of any flat type. 2. Field Catalog: This is an internal table which contains the list of fields as per specification. It comprises of some additional information about display options for each column to be displayed. • It must be referenced to the dictionary type “LVC_T_FCAT” while the work-area should be of type “LVC_S_FCAT”. Function “LVC_FIELDCATALOG_MERGE” can also be used to get field catalog by passing structure name. 3. Container: Container is a storage area where the list will be displayed. It should be of type ”CL_GUI_CUSTOM_CONTAINER”. Other Container classes are: • CL_GUI_DOCKING_CONTAINER: For displaying multiple ALV’s by using methods such as dock_at_left, dock_at_right, dock_at_top, dock_at_bottom. Internal tables can be displayed in these containers.
  • 12.  CL_GUI_EASY_SPLITTER_CONTAINER: For displaying two ALV Grids on single screen, container is splitted into two containers by using this class. 4. Layout Structure: It is a structure to specify general layout options for the grid. With this structure we can set general display options, grid customizing, totals options, color adjustments etc. The layout structure must be of type “LVC_S_LAYO”. 4. Event Handler: For handling events, we need to define and implement an event handler class triggered by the ALV Grid instance. After creating ALV Grid instance, we must register an instance of this event handler class to handle ALV Grid events.
  • 15. General Declarations and Steps to Create Object-oriented ALV:  Create object of class CL_GUI_CUSTOM_CONTAINER for container.  Create object of class CL_GUI_ALV_GRID for putting Grid in above container.  Populate the internal table that you want to display on the Grid.
  • 16. General Declarations and Steps to Create Object-oriented ALV:  Call the screen that contains Custom Container which is done at PBO of screen.  METHOD SET_TABLE_FOR_FIRST_DISPLAY of class CL_GUI_ALV_GRID is used to display the output
  • 17.  In SAP Netweaver 2004, SAP introduced a new Object Oriented ALV list family class, called CL_SALV. It consists of different ALVs such as table, hierarchy, and tree.  CL_SALV_TABLE in SE24 transaction.
  • 19. Development  In this subroutine we use get_flight_schedule, the initialize_alv, and the display_alv.  Get the list of flight schedule
  • 20.  In this subroutine, we are going to query the top 100 rows from the database table,SPFLI and save the received records into an internal table, flight_schedule.  To use the OO CL_SALV_TABLE class, we need to create an instance of it. We can instantiate it by calling its factory() method
  • 21.  We are going to define it as reference variable to the class,CL_SALV_TABLE.  Display the ALV List
  • 23. Enable Layout Settings  The subroutine,INITIALIZE_ALV in the following order: first we call the FACTORY() method of the CL_SALV_TABLE to get an instance of it, then call the subroutines that responsible for different settings.
  • 24.  We are going to get and save an instance of the CL_SALV_LAYOUT in the variable, called LAYOUT_SETTINGS by calling the instance method of the CL_SALV_TABLE class, called GET_LAYOUT().  We usually set a unique key to make the different ALV layout settings unique between each other, and set a restriction for saving the layouts.  To set a unique key we use the SET_KEY() method of the CL_SALV_LAYOUT class that requires a SALV_S_LAYOUT_KEY structure as an import parameter.
  • 25.  If we check the SET_SAVE_RESTRICTION() method, we find that it requires a parameter with the type SALV_DE_LAYOUT_RESTRICTION. To provide a value with this type, we are going to use the IF_SALV_C_LAYOUT interface that contains three different attributes:  The attributes mean the following:
  • 27. Optimize Column Width  We are going to place the call of our next setting (OPTIMIZE_COLUMN_WIDTH) in the subroutine, called INITIALIZE_ALV.
  • 28.  To customize the columns of an ALV, we need an instance of the class, CL_SALV_COLUMNS_TABLE that we are going to get by calling the CL_SALV_TABLE method, called GET_COLUMNS(), and save the received instance reference in a reference variable, named COLUMNS (it refers to the class, CL_SALV_COLUMNS_TABLE ).  We want to optimize the width of the columns, so that we call the method, SET_OPTIMIZE(). It has an optional importing bool parameter, named VALUE that is true by default.
  • 29.  Before optmizing the columns width.  After optimizing the columns width.
  • 30. Individual Column Settings  OPTIMIZE_COLUMN_WIDTH subroutine into the INITIALIZE_ALV subroutine, since we want to initialize only once, and reuse it several times, so I think it belongs to this place.
  • 31.  In the OPTIMIZE_COLUMN_WIDTH subroutine  Get the reference of the MANDT column by calling the method, GET_COLUMN() on the columns object (columns contains all of the columns from the table, SPFLI), and then let's call its method, named SET_VISIBLE() with false. At last, let's wrap these method calls into a TRY-CATCH block to handle exceptions (now we have to handle the case when doesn't exist any field in the structure with the name, MANDT).
  • 32.  Place its declaration in the global area for the sake of the simplicity with the type CL_SALV_COLUMN.  Set text for column