Você está na página 1de 65

•Definition:

- ALV stands for ABAP List Viewer.

- It is a type of graphical report.


- To Introduce ABAP List Viewer.

- To explain the steps in creating an ALV report.

- To explain Function Modules used in the ALV report.

- To explain briefly about the different types of ALV reports.


Why ALV ? •Minimum
Classical List output features
Display
Extract Data
Selection
to an internal
screen
table
•Advanced
ALV Display output options

• Easy to implement complex set of functions.

• Provides advanced features of data sorting, filtering,


alignment and export to external file formats.

• Gives better appearance and consistency of data.


• Display lists consistently with a modern design.

• Uses typical list functions - such as sorting and filtering, without extra
programming effort.

• Downloading designable spreadsheets.

• Basic calculations.

• Displaying several colors.

• Program responses to user actions (such as double-clicking a line)


individually.

• Programming overhead of mentioning exact positions in write statements not


needed.
Email,
BAR
Excel
Charts
ROW Sorting
Filtering
Selection
Change ,
save
Layout
Bar Charts

Fields Open For


Input
User specifc layout
 ALV_CHCK - Check Table for ALV_T_T2.

 ALV_TAB - Check Table for ALV_T_T2.

 ALV_CUR - Check Table for ALV_T_T2.

 ALV_T_T2 – Test data for ALV.


• ALV List Display

• ALV Grid Display

• ALV Hierarchical Display

• ALV Tree Display

• ALV Block List Display


Some limitations of ALV are:

1)ALV can not display deep structures, so you need to flatten the
data i.e. linear structure.

2)Can display only up to 90 columns at a single time.

3)Can display only up to 128 characters per cell.

4)In Grid Display, cells of sorted columns with same values can be
merged. It is not possible with ALV List Display.
5) In Grid Display, printing can only be done by switching
to list display.

6) Multi line headers are not possible in any kind of ALV


display.

7)ALV Tree has no filter functionality.

8)ALV tree can have a maximum of 1000 nodes.


Step 1: Data Declaration

Step 2: Selecting the variants (optional)

Step 3: Defining output Characteristics or preparing field catalog.

Step 4: Build up events table

Step 5: Define Output Layout of the report

Step 6: Deciding sort criteria

Step 7: Print Header Level information

Step 8: Display output internal table


The final step in the output of the report is through ALV
function modules.
Two Approaches

o Conventional (Using Standard Function Modules)

o Object Oriented (Using Standard Classes and Methods)

We will concentrate on the conventional approach


Type groups in alv
Type groups in ALV:
• SLIS - Global types for generic list modules

• FIBS (Contains FIBSC & STREE ) –


Balance Sheet/P & L-structure

• STREE - Hierarchy building blocks

• KKBLO - Type group for dynamic lists output


Function Modules used in ALV:
• REUSE_ALV_VARIANT_DEFAULT_GET

• REUSE_ALV_VARIANT_F4

• REUSE_ALV_VARIANT_EXISTENCE

• REUSE_ALV_EVENTS_GET

• REUSE_ALV_COMMENTARY_WRITE

• REUSE_ALV_FIELDCATALOG_MERGE

• REUSE_ALV_LIST_DISPLAY

• REUSE_ALV_GRID_DISPLAY

• REUSE_ALV_POPUP_TO_SELECT
Type Pool – SLIS.

Sap standard tables types taken from the type pools are:

•SLIS_LAYOUT_ALV

•SLIS_T_FIELDCAT_ALV

•SLIS_T_LISTHEADER

•SLIS_T_EVENT
• Display variants are used to set the default properties of an ALV
output.

• Display variants can be user specific and standard.

• You can provide an option on the selection screen to select what


display variant to be used.

• The common function modules related to selecting / validating


display variants are

REUSE_ALV_VARIANT_DEFAULT_GET

REUSE_ALV_VARIANT_F4

REUSE_ALV_VARIANT_EXISTENCE

REUSE_ALV_FIELDCATALOG_MERGE

• This function module is used to populate a field catalog


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.
• Define an internal table of type SLIS_T_FIELDCAT_ALV.

• Fill in attributes for each field

• Append the attributes for each field to the internal table.

• Example:
DATA: I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

X_FIELDCAT-COL_POS= 1.
X_FIELDCAT-FIELDNAME = ‘MATNR'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-SELTEXT_ M = ‘Material'.

* Append the specifications to the internal table for field catalog.


APPEND X_FIELDCAT TO I_FIELDCAT.
REUSE_ALV_EVENTS_GET:

•An event table is used for firing the user commands and
triggering the system dependent events such as TOP_OF _PAGE
, END_OF_PAGE etc.

• A list of possible events is populated into an event table


(I_EVENTS) when this table is passed from the function
module REUSE_ALV_EVENT_GET. The return table from
this function module contains all the possible events.
Sample code :
FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',
FORMNAME_END_OF_PAGE TYPE SLIS_FORMNAME VALUE
'END_OF_PAGE',
FORMNAME_USER_COMMAND TYPE SLIS_FORMNAME VALUE
'USER_COMMAND'.

DATA: L_I_EVENT TYPE SLIS_ALV_EVENT.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'


EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = I_EVENTS.
 ITEM_DATA_EXPAND

 REPREP_SEL_MODIFY

 CALLER_EXIT

 USER_COMMAND

 TOP_OF_PAGE

 TOP_OF_COVERPAGE

 END_OF_COVERPAGE

 FOREIGN_TOP_OF_PAGE

 GROUPLEVEL_CHANGE

 CONTEXT_MENU
 FOREIGN_END_OF_PAGE

 PF_STATUS_SET

 LIST_MODIFY

 TOP_OF_LIST

 END_OF_PAGE

 END_OF_LIST

 AFTER_LINE_OUTPUT

 BEFORE_LINE_OUTPUT

 SUBTOTAL_TEXT
A layout is build for the report output list description USING
the structure of type SLIS_LAYOUT_ALV
We fill the structure to specify general layout options for the
grid. With this structure we can set:

• Display options
• Exceptions
• Totals
•Display variants (only for hierarchical-sequential lists)
• Color
• Other
•Example code :

I_LAYOUT-zebra = 'X'.
I_LAYOUT-hotspot_fieldname = FIELDNAME.
• The sort table is used to get the current sort criteria of the list
or set the criteria dynamically or before the list is displayed
for the first time.

•An internal table of type SLIS_T_SORTINFO_ALV is used.


REUSE_ALV_COMMENTARY_WRITE

This FM 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
• Select the appropriate ALV output type

• Pass the data of the 6 steps to the appropriate function module

REUSE_ALV_LIST_DISPLAY - for LIST output

REUSE_ALV_GRID_DISPLAY – for GRID output

REUSE_ALV_HIERSEQ_LIST_DISPLAY – for hierarchical


display
ALV GRID DISPLAY
Output of ALV Hierarchical display

HEADER DATA

ITEM DATA
ALV Hierarchical display
• Hierarchical display is used to display the Master
(Header) data and Transactional (Item) data in the same
ALV.

• While building the field catalogue we will build at


header and item level i.e. we will call the function module
REUSE_ALV_FIELDCATLOG_MERGE twice one for
header and the other for item.

• The function module used for displaying a hierarchical


report is
Fieldcatalog for table names

Fieldcatalog for field names


ALV Block Display

This looks like a simple report but this report has the features of
sorting and filtering only.

The important functions used for creating this report are:

• REUSE_ALV_BLOCK_LIST_INIT

• REUSE_ALV_BLOCK_LIST_APPEND

• REUSE_ALV_BLOCK_LIST_DISPLAY

• REUSE_ALV_BLOCK_HS_LIST_APPEND
Block display contd.
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. The
parameters are similar to the one used in REUSE_ALV_LIST_DISPLAY
or REUSE_ALV_GRID_DISPLAY
Block Display contd.
REUSE_ALV_BLOCK_LIST_APPEND

Export :
a. is_layout : layout settings for block
b. it_fieldcat : field catalog
c. I_tabname : 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.


Block display contd.
REUSE_ALV_BLOCK_LIST_DISPLAY

Parameters : All the parameters are optional.

This function module display the list with data appended by the
above function.
Sample output

BLOCK 1

BLOCK 2

BLOCK 3
 RS_TREE_COMPRESS
 RS_TREE_EXPAND
 RS_TREE_CREATE
 RS_TREE_CONSTRUCT
 RS_TREE_LIST_DISPLAY

Você também pode gostar