You are on page 1of 10

Display ALV list easily in

ABAP using CL_SALV_TABLE

As an ABAP Developer, we often have to develop ABAP


reports that displays some data from the database. These
programs usually consists of the following three parts:

Selecti
on
Screen

Databa
se
query

ALV list

Fortunately, 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 class
(se24)

SAP Flight Model


I

will use the standardSAP Flight Model


to demonstrate the usage of
theCL_SALV_TABLEclass, within this
model I will use theSPFLIdatabase table
that contains a complete flight schedule
As you know me, I like the transparent and
clean code. In order to achieve this, we
are going to organize the different
responsibilities into small subroutines, like
theget_flight_schedule,
theinitialize_alv, and thedisplay_alv.

So first, we are going to query the


actual flight schedule from the
database, then initialize an ALV
object, and finally display the ALV on
the screen.

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 avoid any error, we need to declareflight_scheduleas an


internal table. Now, I am going to declare it in the global
declaration area for the sake of the simplicity.

INITIALIZE THE ALV OBJECT


To use the OOCL_SALV_TABLEclass, we need to create an
instance of it. We caninstantiate it by calling itsfactory()
method(Factory Design Pattern) that requiresan ALV
parameter(we get back the reference in this parameter),
andan internal tablefilled with business data that we want to
display. To avoid any error, SAP recommends to wrap
theinstantiation into a try-catch block.

As we declared earlier the internal table,flight_schedule, we


need to declare thealvvariable also. We are going to define it
as reference variable to the class,CL_SALV_TABLE.

Display the ALV list


We finally got over the hump, so from now on our task is very
easy. We need to display the ALV list on the screen simply by
calling the instance method,display(). It was easy, right? That's
what I like in this approach. Effective, transparent, and easy-touse.

You might also like