0% found this document useful (0 votes)
20 views

ClassBook-Lessons-ABAP Part II Lesson2 - ALV

The document provides an overview of ABAP List Viewer (ALV) functionality. It discusses: 1) The ALV grid control displays lists consistently with modern features like sorting and filtering without extensive coding. 2) There are three types of ALV reports - simple, block, and hierarchical sequential. Simple reports use function modules to generate output. 3) Key components of ALV include the list data, field catalog, container, and layout structure. The field catalog defines column properties. 4) Object-oriented ALV uses the CL_GUI_ALV_GRID class. Setting the table for display and handling events are important steps.

Uploaded by

aashish guptha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

ClassBook-Lessons-ABAP Part II Lesson2 - ALV

The document provides an overview of ABAP List Viewer (ALV) functionality. It discusses: 1) The ALV grid control displays lists consistently with modern features like sorting and filtering without extensive coding. 2) There are three types of ALV reports - simple, block, and hierarchical sequential. Simple reports use function modules to generate output. 3) Key components of ALV include the list data, field catalog, container, and layout structure. The field catalog defines column properties. 4) Object-oriented ALV uses the CL_GUI_ALV_GRID class. Setting the table for display and handling events are important steps.

Uploaded by

aashish guptha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

ABAP Part II

Lesson 02: ABAP List Viewer


Lesson Objectives

After completing this lesson, participants will be able to


understand the following -
▪ Control Framework
▪ ALV Grid
▪ Non Event Based Functionality
▪ Event Based Functionality

© 2018 Capgemini. All rights reserved. 2


Introduction

The common features of report are column alignment, sorting, filtering,


subtotals, totals etc.
To implement these, a lot of coding and logic is to be put.
To avoid that we can use a concept called ABAP List Viewer (ALV).
ALV (ABAP List Viewer) is a grid control, used for displaying lists.
The tool provides common list operations as generic functions and enhanced
by user-defined options.
The grid control itself consists of a toolbar, a title and the output table
displayed in a grid control. The user has control over the look of the grid (to
certain degree) by the use of layout variants

© 2018 Capgemini. All rights reserved. 3


Functions Provided by ALV Grid Control

Display non-hierarchical lists consistently with a modern design


Use typical list functions -such as sorting and filtering without extra
programming effort
Adapt predefined list functions and their enhancements
Program responses to user actions (such as double-clicking a line)
individually

© 2018 Capgemini. All rights reserved. 4


Features

Navigating Within the List


Sorting in Ascending/Descending Order
Selecting and Deselecting Rows
Defining Exceptions
Setting and Deleting Filters
Displaying and Deleting Sums
Creating Subtotals
Optimizing the Column Width

© 2018 Capgemini. All rights reserved. 5


Types of ALV Reports

Using ALV, we can have three types of reports:


▪ Simple Report
▪ Block Report
▪ Hierarchical Sequential Report

© 2018 Capgemini. All rights reserved. 6


Simple Report

There are some function modules which will enable to produce the above
reports without much effort.
All the definitions of internal tables, structures and constants are declared
in a type-pool called SLIS.
The important function modules are:
▪ Reuse_alv_fieldcatalog_merge
▪ Reuse_alv_list_display
▪ Reuse_alv_grid_display

© 2018 Capgemini. All rights reserved. 7


Simple Report

Reuse_ALV_fieldcatalog_merge:
▪ This function module is used to populate a fieldcatalog which is essential to display
the data in ALV.
▪ If the output data is from a single dictionary table and all the columns are
selected, then we need not exclusively create the field catalog.
▪ Its enough to mention the table name as a parameter(I_structure_name) in the
REUSE_ALV_LIST_DISPLAY.
▪ In other cases, it has to be created.

© 2018 Capgemini. All rights reserved. 8


Simple Report

REUSE_ALV_LIST_DISPLAY: This is the function module which prints the


data.

© 2018 Capgemini. All rights reserved. 9


Simple Report

REUSE_ALV_GRID_DISPLAY: To display the results in grid rather than


as a list.
▪ Parameters : same as reuse_alv_list_display

© 2018 Capgemini. All rights reserved. 10


Display Output Internal Table

RESUSE_ALV_LIST_DISPLAY REUSE_ALV_GRID_DISPLAY

© 2018 Capgemini. All rights reserved. 11


Demo

ALV List Display and ALV Grid Display

© 2018 Capgemini. All rights reserved. 12


Field Catalog

A field catalog is prepared using the internal table (I_FIELDCAT) of type


SLIS_T_FIELDCAT_ALV
Field catalog containing descriptions of the list output fields (usually a
subset of the internal output table fields)
A field catalog is required for every ALV list output to add desired
functionality (i.e. Key, Hotspot, Specific headings, Justify, Col. position
etc) to certain fields of the output.
If not mentioned specifically, then the defaults are taken

© 2018 Capgemini. All rights reserved. 13


No of ways to build Field Catalog

Preparing the data dictionary structure


Build field catalog using function module
▪ Reuse_alv_fieldcatlog_merge
Prepare the field Catalog manually

© 2018 Capgemini. All rights reserved. 14


Demo

Create a Field Catalog Manually and use it in list display

© 2018 Capgemini. All rights reserved. 15


OO ALV

The Control Framework is required for OO ALV as it provides global classes


for various functionalities.

CL_GUI_ALV_GRID

▪ The wrapper class implemented to encapsulate ALV Grid functionality for list
display.

© 2018 Capgemini. All rights reserved. 16


Basic Components

While preparing a list to be displayed via an ALV grid control, we have some
basic components to prepare. These are:
List data :
▪ Data in an internal table to be listed
Field Catalog :
▪ Define specifications on how the fields of our list will be displayed
▪ Has technical and additional information about display options for each column to
be displayed.
▪ The internal table for the field catalog must be referenced to the dictionary type
LVC_T_FCAT.
Container
▪ Storage area where the list will be displayed.
▪ It should be of type CL_GUI_CUSTOM_CONTAINER

© 2018 Capgemini. All rights reserved. 17


Basic Components

Layout Structure :
▪ Fill a structure to specify general layout options for the grid
▪ To set
• general display options
• grid customizing
• totals options
• color adjustments etc...
▪ The layout structure must be of type LVC_S_LAYO.

© 2018 Capgemini. All rights reserved. 18


Basic Components

Event Handler
▪ To handle events triggered by the ALV Grid instance.
▪ Upon creating ALV Grid instance, register an instance of this event handler class to
handle ALV Grid events
▪ Various Events are as follows
• Print_Top_Of_Page:
‒ Used for Headers. Handler is ‘SET HANDLER’.
• Print_End_Of_Page
‒ Used for Footers. Handler is ‘SET HANDLER’.
• OnDropComplete
‒ Event to change the state after a successful drag and drop operation.
• OnDrag
‒ To ‘fetch’ information from the drag source.
• OnDrop
‒ Used to use the dragged information in combination with drop source. Here, it should be checked
whether the operation is successful

© 2018 Capgemini. All rights reserved. 19


Grid Control – Inheritance Hierarchy

CL_GUI_ALV_GRID’ class encapsulates communication with the instance on


the presentation server, along with many other functions. For this reason,
you should instantiate this class, not its super class.

© 2018 Capgemini. All rights reserved. 20


Steps to work with OO ALV

Create an object of class CL_GUI_CUSTOM_CONTAINER.

Create an object of class CL_GUI_ALV_GRID.

Populate the internal table to display on the GRID.

Call the screen that contains the CUSTOM CONTAINER, in which the list has
to be displayed.

Call the screen.

Call the method SET_TABLE_FOR_FIRST_DISPLAY of class


CL_GUI_ALV_GRID and pass the required parameters

© 2018 Capgemini. All rights reserved. 21


CL_GUI_ALV_GRID

‘CL_GUI_ALV_GRID’ class provides various methods and Events

© 2018 Capgemini. All rights reserved. 22


Building Field Catalog

There are 3 methods for doing this:


▪ Automatic generation
▪ Semi-automatic generation
▪ Manual generation

© 2018 Capgemini. All rights reserved. 23


Structure of Field Catalog (LVC_T_FCAT)

© 2018 Capgemini. All rights reserved. 24


Building Field Catalog (Manually)

The work in this procedure is just filling the internal table for the field
catalog. We have already seen the structure of a field catalog. To achieve
filling the field catalog correctly, one must at least fill the above fields of the
field catalog structure for each column of the list.

© 2018 Capgemini. All rights reserved. 25


Building Field Catalog (Manually)
DATA LS_FCAT TYPE LVC_S_FCAT .
LS_FCAT-FIELDNAME = 'CARRID‘.

LS_FCAT-INTTYPE = 'C'.

LS_FCAT-OUTPUTLEN = '3'.

LS_FCAT-COLTEXT = 'CARRIER ID'.

LS_FCAT-SELTEXT = 'CARRIER ID'.

APPEND LS_FCAT TO PT_FIELDCAT.

CLEAR LS_FCAT.

LS_FCAT-FIELDNAME = 'CONNID'.

LS_FCAT-REF_TABLE = 'SFLIGHT'.
LS_FCAT-REF_TABLE = 'CONNID'.

LS_FCAT-OUTPUTLEN = '3'.

LS_FCAT-COLTEXT = 'CONNECTION ID'.

LS_FCAT-SELTEXT = 'CONNECTION ID'.

APPEND LS_FCAT TO PT_FIELDCAT .

…. AND SO ON FOR ALL THE FIELDS TO BE DISPLAYED IN THE List


© 2018 Capgemini. All rights reserved. 26
Demo

Create a Field Catalog Manually and use it in list display

© 2018 Capgemini. All rights reserved. 27


Building Field Catalog (Semi-automatically)

© 2018 Capgemini. All rights reserved. 28


Layout Adjustment

It comes now painting our ALV Grid in a general aspect. To define general
appearance of our ALV Grid we fill a structure of type “LVC_S_LAYO”. This
table contains fields and functionalities serviced by this adjustment. Some
of the generally used options are as below:

© 2018 Capgemini. All rights reserved. 29


ALV Display

Data transfer to the ALV control takes place during the call of method
“SET_TABLE_FOR_FIRST_DISPLAY” of class “CL_GUI_ALV_GRID”. The
method call must be programmed at the PBO event of the screen with the
SAP Grid Control container.
Remember to use Pattern > ABAP Objects > Method of a Class

© 2018 Capgemini. All rights reserved. 30


ALV Display

If the ALV_GRID is initial (First Call) the method


“SET_TABLE_FOR_FIRST_DISPLAY” is called as described in the previous
slide. Else on subsequent calls; “REFRESH_TABLE_DISPLAY” is called.
Reason being; there is no need to instantiate the Custom Container, Grid
every time in the PBO of the Screen.
The parameters of this method:
▪ IS_STABLE: If the row or column field of this structure is set, the position of the
scroll bar for the rows or columns remains stable.
▪ I_SOFT_REFRESH: If set, any totals created, any sort order defined and any filter
set for the data displayed remain unchanged when the grid control is refreshed.

© 2018 Capgemini. All rights reserved. 31


Setting Sort Condition

It is possible to set sort conditions for the table data. This is achieved by
filling an internal table of structure “LVC_T_SORT” which consists of the sort
criteria. To have an initial sorting, pass it to the parameter “IT_SORT” of the
method “SET_TABLE_FOR_FIRST_DISPLAY”.

© 2018 Capgemini. All rights reserved. 32


Setting Filter Condition

The procedure is like the one in sorting. Here, the type of the table you
must fill is “LVC_T_FILT”.
Filling this table is similar to filling a RANGES variable.

© 2018 Capgemini. All rights reserved. 33


Event Based Functionality

Additional Event based Functionalities that the ALV Grid can handle:-
▪ GENERAL SCHEME FOR THE EVENT HANDLER CLASS
▪ HOTSPOT CLICKING
▪ DOUBLE CLICKING
▪ PUSHBUTTONS ON THE LIST
▪ ADDING YOUR OWN FUNCTIONS
▪ OVERRIDING STANDARD FUNCTIONS
▪ MAKING ALV GRID EDITABLE
▪ CONTROLLING DATA CHANGES
▪ LINKING F1 HELP TO FIELDS
▪ LINKING F4 HELP TO FIELDS

© 2018 Capgemini. All rights reserved. 34


Summary

In this lesson, you have learnt:


▪ Control Framework
▪ ALV Grid
▪ Non Event Based Functionality
▪ Event Based Functionality

© 2018 Capgemini. All rights reserved. 35


Review Question

Question 1: _______ is used to find the length of the


string.

Question 2: Condense and Concatenate


command perform the same function.
▪ True/False

© 2018 Capgemini. All rights reserved. 36

You might also like