0% found this document useful (0 votes)
352 views33 pages

Object Oriented Approach For ALV Lists in ABAP

As an ABAP Developer, we often have to develop ABAP reports that displays some data from the database. SAP provides a set of ALV (ABAP List Viewer) function modules which can be put into use to embellish the output of a report.Object oriented ALV is more robust and is more advanced when compared to Traditional ALV.

Uploaded by

Noaman Hanif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
352 views33 pages

Object Oriented Approach For ALV Lists in ABAP

As an ABAP Developer, we often have to develop ABAP reports that displays some data from the database. SAP provides a set of ALV (ABAP List Viewer) function modules which can be put into use to embellish the output of a report.Object oriented ALV is more robust and is more advanced when compared to Traditional ALV.

Uploaded by

Noaman Hanif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

Object Oriented ALV

By Noman Hanif

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 theSAP

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 ALVs , 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

Main Principle prior to the New


Object Model

Main Principle of the New Object


Model (Simplest Call)

In caseof object oriented concept thecontrol framework is required as


itprovides global classes for various functionalities:
CL_GUI_ALV_GRID
It is thewrapper 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 canbe enhanced by user-defined

options.

Basic components required for ALV Grid Control are:


1. List Data: Datatobelistedispopulatedinaninternal
table.Thistablecan be of any flat type.
2. Field Catalog: Thisisaninternal
tablewhichcontainsthelistoffieldsasper specification. It comprises
of someadditional information about display options for each column to
be displayed.
. It must bereferenced 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: Containerisa storage areawhere thelist will be

displayed. It should beof typeCL_GUI_CUSTOM_CONTAINER.


Other Container classes are:
. CL_GUI_DOCKING_CONTAINER:

For displaying multiple ALVs 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.

LayoutStructure: Itis a structure to specify general layout


optionsfor the grid. With this structure we can set generaldisplay
options, grid customizing, totals options, color adjustments etc.
The layout structure must be of type LVC_S_LAYO.

5.

Event Handler: For


handlingevents,weneedtodefineandimplementan event handler
class triggered by the ALV Grid instance. After creating ALV Grid
instance, we must register an instance of thisevent handler class to
handle ALV Grid events.

Layout Structure

Events List

General Declarations and Steps to Create Objectoriented ALV:


Create object of class CL_GUI_CUSTOM_CONTAINER for container.

Create object of classCL_GUI_ALV_GRID for puttingGrid inabove

container.

Populate the internal table that you want to display on the Grid.

General Declarations and Steps to Create Objectoriented ALV:


Call the screen that contains Custom Container which is done at PBO

ofscreen.
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, calledCL_SALV. It consists of different ALVs such


astable,hierarchy, andtree.
CL_SALV_TABLE in SE24 transaction.

Development
In this subroutine we use get_flight_schedule, theinitialize_alv, and

thedisplay_alv.

Get the list of flight schedule

In this subroutine, we are going to query thetop 100rows from the

database table,SPFLIand save the received records into an internal


table,flight_schedule.

To use the OOCL_SALV_TABLEclass, we need to create an instance of it.

We can instantiate it by calling itsfactory() 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_ALVin the following order: first we call

theFACTORY()method ofthe CL_SALV_TABLEto get an instance of


it, then call thesubroutinesthat responsible for different settings.

We are going to get and save an instance of theCL_SALV_LAYOUTin the

variable, calledLAYOUT_SETTINGSby calling the instance method of


theCL_SALV_TABLE class, calledGET_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 theSET_KEY()method of

theCL_SALV_LAYOUTclass that requires


aSALV_S_LAYOUT_KEYstructure as an import parameter.

If we check theSET_SAVE_RESTRICTION()method, we find that it

requires a parameter with the typeSALV_DE_LAYOUT_RESTRICTION. To


provide a value with this type, we are going to use
theIF_SALV_C_LAYOUTinterface 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, calledINITIALIZE_ALV.

To customize the columns of an ALV, we need an instance of the

class,CL_SALV_COLUMNS_TABLEthat we are going to get by calling the


CL_SALV_TABLEmethod, called GET_COLUMNS(), and save the received
instance reference in a reference variable, namedCOLUMNS(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 boolparameter,


namedVALUEthat istrueby default.

Before optmizing the columns width.

After optimizing the columns width.

Individual Column Settings

OPTIMIZE_COLUMN_WIDTHsubroutine into

theINITIALIZE_ALVsubroutine, since we want to initialize only once, and


reuse it several times, so I think it belongs to this place.

In theOPTIMIZE_COLUMN_WIDTHsubroutine

Get the reference of theMANDTcolumn by calling the

method,GET_COLUMN()on thecolumnsobject (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 aTRYCATCH 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

typeCL_SALV_COLUMN.

Set text for column

THANK YOU!!

You might also like