Online Tutorials & Training Materials | STechies.com
Register Login

ALV (ABAP List Viewer) Overview

|| || 0

ALV (ABAP List Viewer) Overview
Stechies

What is 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.

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

Example of Simple ALV

Example of Simple ALV

Sort Button in ALV

Sort Button in ALV

Filter Button in ALV

Filter Button in ALV

Filter Criteria

Filter Criteria

Types of ALV Reports

Using ALV, we can have three types of reports:

  1. Simple Report
  2. Block Report
  3. Hierarchical Sequential Report

Read Here: Billing Report in ALV Forrmat with Total

Two Types of Information for Displaying Data in ALV Grid

  • An internal table with the data.
  • A description of the structure of this data that is declared to the ALV grid control through the field catalog or through the corresponding structure of the Data Dictionary.

Two ways to list data in ALV grid:

  1. CALL METHOD: grid->set_table_for_first_display
  2. CALL FUNCTION REUSE_ALV_LIST_DISPLAY

SAP Custom Container, Field Catalog, Layout Structure

SAP custom container: The SAP custom container allows you to display controls in an area defined on a normal screen using the screen painter.

Field catalog: The field catalog is a table that contains information on the fields to be displayed. For example, the ALV uses this table to identify the type of a field.

Layout structure: The layout structure is of type LVC_S_LAYO . it contains fields for settinig graphical properties of the grid control, displaying exceptions, calculating totals and enabling specific interaction options.

Method 1: CALL METHODGrid -> Set_table_for_first_display

  • You can use method set_table_for_first_display to pass the list data, the field catalog, and any additional information to the ALV Grid Control instance.
  • To pass the list data to be displayed, you use parameter it_outtab.
  • You pass the name of the row structure of the data table using parameter i_structure_name. The proxy object then generates the field catalog automatically. If you want to pass a field catalog that was generated manually or semi-automatically, you must additionally use parameter it_fieldcatalog.
  • You use parameters is_variant and i_save to control the use of display variants. Using parameter i_default, you can determine that a display variants should be loaded as default variant. This is the default setting of the parameter.
  • Parameters is_layout, is_print, it_special_groups and it_toolbar_excluding allow you to pass your settings for the control layout and the print list, as well as the names of the field groups and the names of the functions to be disabled in the toolbar.
  • Using parameters it_filter and it_sort, you can pass initial filter and sort criteria to your proxy object.
  • The interface parameters use the following name conventions: i_ = single field, is_ = structure, it_ = internal table.
  • For details on the method and the interface parameters, see the online documentation.

1) Declare reference variables for the ALV grid control and the container.

DATA: grid TYPE REF TO cl_gui_alv_grid, G_custom_container TYPE REF TO cl_gui_custom_container, Gt_sflight TYPE TABLE OF sflight. (Output table)

2) The SAP custom container allows you to display controls in an area defined on a normal screen using the screen painter.

Class: CL_GUI_CUSTOM_CONTAINER

3) In the PBO module of the screen, you must now instantiate the container control and the ALV grid control. By doing this, you create a link between the container control and the screen, using the container created in the screen painter.

CREATE OBJECT g_custom_container Exporting Container_name = 'ccontainer'. (As declared on screen) Create object grid1 Exporting I_PARENT = g_custom_container.

4) Pass the output table and the structure data to the ALV grid control.

CALL METHOD grid->set_table_for_first_display Exporting i_structure_name = 'sflight' CHANGING IT_OUTTAB = gt_sflight.

In this case, the structure data is provided through the data dictionary. The ALV grid control gets the field information from table SFLIGHT and displays all fields of the table. GT_SFLIGHT is the output table.

Steps Required

Required Steps in ALV

More About Fieldcatalogs

How to generate field catalog?

Basically, we need a field catalog for each list that is displayed using the ALV grid control. We have several options of generating a field catalog:

  1. Automatically through a data dictionary structure
  2. Manually in your ABAP program
  3. Semi-automatically by combining the above two procedures.

1. Automatically Through a Data Dictionary Structure

Automatically Through a Data Dictionary Structure

Purpose : If the structure of our output table corresponds to a structure stored in the data dictionary (DDIC), the ALV grid control can use this information to generate the field catalog automatically.

Process : Pass the structure in method set_table_for_first_display with parameter I_STRUCTURE_NAME to the control created.

2. Manually in Your ABAP Program

Manually in Your ABAP Program

PURPOSE : it may be the case that the data you want to display is not at all or only partially represented by a structure in the data dictionary. Then you must use the fields of the field catalog to describe the structure of the output table.

PROCESS : the field catalog is defined in the data dictionary through table type LVC_T_FCAT . each row of the field catalog table explains a field in your output table.

Depending on whether a reference structure exists in the DDIC or not, you must at least fill the following fields of the field catalog structure for each field:

Output table fields with DDIC reference : FIELDNAME REF_TABNAME ref_TABNAMEOutput table fields without DDIC reference : FIELDNAME INTTYPE OUTPUTLEN COLTEXT

3. Semi-automatically by Combining the Two

When generating the field catalog semi-automatically, you combine structure information of the data dictionary with your own structure information.

Purpose : The output display can be manipulated in several ways for example -

  • To display a data dictionary table without displaying all possible columns initially (using field NO_OUT of the field catalog).
  • To display additional columns containing icons or other information.
  • To change the output length of a column.(Field OUTPUTLEN)

Process: Declare an internal table of type LVC_T_FCAT.

Call function module LVC_FIELDCATALOG_MERGE and pass the DDIC structure of the output table and the internal table for the field catalog. The function module generates the field catalog and fills the internal table accordingly. Loop the internal table remove unwanted types Pass the field catalog to the method grid->set_table_for_first_display.

Integration of ALV Grid Controls

Integration of ALV Grid Controls

METHOD 2 : CALL FUNCTIONREUSE_ALV_LIST_DISPLAY

  1. Using type group SLIS : create field catalog and other necessary internal tables.
  2. Explain field description to ALV through field Catalog.
  3. Set messages for header and insert into GT_TOP_OF_PAGE
  4. Call function 'reuse_ALV_list_display'. And pass field catalog and output internal table.

Simple Report

The important function modules are:

  • Reuse_alv_list_display
  • Reuse_alv_fieldcatalog_merge
  • Reuse_alv_events_get
  • Reuse_alv_commentary_write
  • Reuse_alv_grid_display

A. REUSE_ALV_LIST_DISPLAY: this is the function module which prints the data.

The important parameters are:

1. Export:

A. I_callback_program: report id
B. I_callback_pf_status_set: routine where a user can set his own pf status or change the functionality of the existing pf-status.
C. I_callback_user_command : routine where the function codes are handled.
D. I_structure name: name of the dictionary table
E. Is_layout: structure to set the layout of the report
F. It_fieldcat: internal table with the list of all fields and their Attributes which are to be printed (this table can be populated automatically by the function module REUSE_ALV_FIELDCATALOG_MERGE)
G. It_events: internal table with a list of all possible events of ALV and their corresponding routine names.

Related: Color a Column Value in ALV Report.

2. Tables:

A. T_outtab: internal table with the data to be output

B. 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. But in other cases we need to create it.

The important parameters are:

1. Export:

A. I_program_name: report id
B. I_internal_tabname: the internal output table
C. I_inclname: include or the report name where all the dynamic Forms are handled.

2. Changing

Ct_fieldcat: an internal table with the type SLIS_T_FIELDCAT_ALV Which is declared in the type pool SLIS.

C . reuse_ALV_events_get:

returns table of possible events for a a list type

Import:

Et_events : the event table is returned with all possible CALLBACK events for the specified list type (Column ‘NAME’). For events to be processed by The callback, their ‘FORM’ field must be filled. If The field is initialized, the event is ignored. The Entry can be read from the event table, the field ‘FORM’ filled and the entry modified using Constants from the type pool SLIS.

2. Export:

I_list_type:
0 = simple list
1 = hierarchical-sequential list
2 = simple block list
3 = hierarchical-sequential block list

D. REUSE_ALV_COMMENTARY_WRITE :

This is used in the top-of-page event to print the headings and other comments for the list.

1. It_list_commentary : internal table with the headings of the type slis_t_listheader.

This internal table has three fields:

Typ : ‘H’ -header, ‘S’ -selection, ‘A’ -action
Key : only when typ is ‘S’.
Info : the text to be printed

E. REUSE_ALV_GRID_DISPLAY:

A new function in 4.6 version, to display the results in grid rather than as a list.

Parameters : same as reuse_alv_list_display

The Example of a Simple List

Example of a Simple List

Hierarchical Reports

Hierarchical sequential list output. The function module is:

A. Reuse_ALV_HIERSEQ_list_display

1. Export:

A. I_callback_program
B. I_callback_pf_status_set
C. I_callback_user_command
D. Is_layout
E. It_FIELDCAT
F. It_events
G. I_TABNAME_HEADER : name of the internal table in the program containing the output data of the highest hierarchy level.
H. I_TABNAME_ITEM : name of the internal table in the program containing the output data of the lowest hierarchy level.
I. IS_KEYINFO : this structure contains the header and item table field names which link the two tables (shared key).

Related: How to Get Total and Sub Total in ALV Reports?

2. Tables

A. T_OUTTAB_HEADER : header table with data to be output
B. T_OUTTAB_ITEM : name of the internal table in the program containing the output data of the lowest hierarchy level.

Hierarchical Reports Example

Hierarchical Reports Example

Block Report

This is used to display multiple lists continuously.

The important functions used in this report are:

A. REUSE_ALV_BLOCK_LIST_INIT
B. REUSE_ALV_BLOCK_LIST_APPEND
C. REUSE_ALV_BLOCK_HS_LIST_APPEND
D. REUSE_ALV_BLOCK_LIST_DISPLAY

A. REUSE_ALV_BLOCK_LIST_INIT

Parameters:

a. I_CALLBACK_PROGRAM
b. I_CALLBACK_PF_STATUS_SET
c. I_CALLBACK_USER_COMMAND

This function module is used to set the default GUI status etc.

B. REUSE_ALV_BLOCK_LIST_APPEND

Export :

a. IS_LAYOUT : layout settings for block
b. IT_FIELDCAT : field catalog
c. I_TABNAME : Internal table name of the output data
d. IT_EVENTS : internal table name with all possible events

Tables :

a. T_OUTTAB : internal table with output data.

This function module adds the data to the block.

Reuse_ALV_list_HS_append : - Is used to append the hierarchical sequential blocks.

C. Reuse_ALV_block_list_display

Parameters : all the parameters are optional. This function module display the list with data appended by the above function.

Block Report Example

Here the functions REUSE_ALV_FIELDCATALOG_MERGE, REUSE_ALV_EVENTS_GET, REUSE_ALV_COMMENTARY_WRITE can be used.

Block Report Example

Internal Tables In SLIS

1. Slis_t_fieldcat_alv

This internal table contains the field attributes. This internal table can be populated automatically by using ‘REUSE_ALV_FIELDCATALOG_MERGE’.

Important attributes:

A. Col_pos: position of the column
B. Fieldname: internal fieldname
C. tabname: internal table name
D. Ref_fieldname: fieldname (dictionary)
E. Ref_tabname: table (dictionary)
F. Key(1): column with key-color
G. Icon(1): icon
H. Hotspot(1): hotspot
I. Symbol(1):symbol
J. Checkbox(1):checkbox
K. Just(1):(r)ight (l)eft (c)ent
L. Do_sum(1):sum up
M. No_out(1):(o)blig. (X)no out
N. outputlen:output length
O. seltext-l:long key word
P. seltext_m:middle key word
Q. seltext_s:short key word
R. reptext_ddic:heading(ddic)
S. ddictxt(1):(s)hort (m)iddle (l)ong
T. datatype:datatype

2. SLIS_T_EVENT

Internal table for storing all the possible events of the ALV. This can be populated by the function module Reuse_alv_events_get

The columns are :

name: name of the event
form : name of the routine

Syntaxes For The Routines

I_callback_pf_status_set

Syntax : FORM set_pf_status USING rt_extab TYPE slis_t_extab
The table RT_EXTAB contains the function codes which are hidden in the standard interface.

I_callback_user_command

Syntax : FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.
The parameter r_ucomm contains the function code. The structure rs_selfield has the details about the current cursor position.

How to Create DYNAMIC Structures?

  1. Create a dynamic report inside the program.
  2. Create a global internal table to store the lines of dynamic report. Ex: DATA: BEGIN OF INCTABL OCCURS 10, Line(72), End of INCTABL.
  3. Create a internal table like, Data: begin of STRUCT occurs 10, FILDNAME(25) type c, ABPTYPE(4) type c, Length type i, End of STRUCT.
  4. Insert the structure (dynamically) in to the internal table.
  5. Whole code is inside internal table INCTABL.
  6. Move dynamically created report code from INCTABL to dynamic report ZDYNPRO Insert report 'ZDYNPRO' from INCTABL.
  7. Submit the dynamic report Submit ZDYNPRO and return. System leaves the active program, and starts the new dynamic report ZDYNPRO. Once the execution is over program will use the structure which is created dynamically.

Restrictions

  • Not all of the existing types of tables and lists can be replaced by one of the ALV components.
  • Matrices could not be replaced by ALV.
  • Nets could not be replaced by ALV. (Nets are data structures with more complex interconnections than the hierarchical ones in trees. )
  • There is no currency handling
  • Limited function compared to drilldown reporting.

Read Here for More SAP ABAP Tutorials


Related Articles

0.0126 seconds.