Sei sulla pagina 1di 32

ABAP List Viewer (ALV)

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). Using ALV, we can have three types of reports: 1. Simple Report 2. Hierarchical Sequential Report ALV can be performed using two ways: 1. Using Function Modules

2. Using Classes and Objects (Not covered in this session )

Advantages of ALV
Looks better. User friendly 1. Filtering / Sorting

2. Layout Change / Save


3. Summation, Download to excel, E-Mail 4. Data can be open for input / change etc. Better Event handling Width of more than 256 characters possible Programming overhead of mentioning exact positions in write statements not needed.

ALV Features

Email Change Layout Download to Excel Filtering Sorting Column Heading Row(s) Selection

ALV Features contd.

Display Graphics

Fields Open For Input

Steps involved in creating a simple ALV report


Define field catalogue internal table which is of type slis_t_fieldcat_alv. This table contains the field attributes. Define Layout structure which is of type slis_layout_alv Define Events internal table which is of type slis_alv_event. This internal table contains all the possible events of ALV. Populating these tables into the Function Module as parameters. These Function Modules are used in displaying the output data. All the definitions of internal tables, structures, and constants are declared in type-pool called SLIS.

Step -1
1. Define field catalogue internal table which is of type slis_t_fieldcat_alv Eg : t_ls_fieldcat type slis_t_fieldcat_alv t_ls_fieldcat-tabname = t_spfli. t_ls_fieldcat-fieldname = scarr. t_ls_fieldcat-ref_tabname = par_reftabname. t_ls_fieldcat-ref_fieldname = par_ref_fieldname. t_ls_fieldcat-seltext_m = par_seltext. t_ls_fieldcat-input = par_input. t_ls_fieldcat-outputlen = 30. t_ls_fieldcat-do_sum = X.

APPEND t_ls_fieldcat.

Step - 2
2. Defining Layout structure which is of type slis_layout_alv Eg : par_ls_layout-zebra = X. par_ls_layout-no_colhead = X. par_ls_layout-no_hotspot = X.

Step - 3
3. Define Events internal table which is of type slis_alv_event and call it in function module REUSE_ALV_EVENTS_GET.

Step - 4

This step contain the function modules which displays the data in the list. Following are the function modules :
Simple Report Reuse_alv_list_display Reuse_alv_fieldcatalog_merge Reuse_alv_events_get Reuse_alv_commentary_write Reuse_alv_grid_display

Hierarchical Report Reuse_alv_hierseq_list_dispaly

Reuse_alv_list_display
This is the Function Module which prints the data.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = G_REPID

I_STRUCTURE_NAME = 'SFLIGHT'
IS_LAYOUT = GS_LAYOUT IT_FIELDCAT = GT_FIELDCAT[ ] IT_SPECIAL_GROUPS = GT_SP_GROUP[ ] I_SAVE = G_SAVE IS_VARIANT = G_VARIANT IT_EVENTS = GT_EVENTS[ ] * IMPORTING * E_EXIT_CAUSED_BY_CALLER = TABLES T_OUTTAB = GT_SFLIGHT.

10

Reuse_alv_fieldcatalog_merge
This Function Module is used to populate a field catalog which is essential to display the data in ALV.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE ' EXPORTING I_PROGRAM_NAME = I_INTERNAL_TABNAME = I_STRUCTURE_NAME = I_CLIENT_NEVER_DISPLAY = 'X' I_INCLNAME = I_BYPASSING_BUFFER = I_BUFFER_ACTIVE = CHANGING CT_FIELDCAT = EXCEPTIONS INCONSISTENT_INTERFACE =1 PROGRAM_ERROR =2 OTHERS = 3.

11

Reuse_alv_events_get
Returns table of possible events for a list type.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET' EXPORTING I_LIST_TYPE = 0 IMPORTING ET_EVENTS = E03_LT_EVENTS.

12

Reuse_alv_commentary_write
This is used in the Top-of-page event to print the headings and other comments for the list. E.g.
refresh GT_LIST_TOP_OF_PAGE. Move H to GT_LIST_TOP_OF_PAGE-typ. Move Materials Display to GT_LIST_TOP_OF_PAGE-info. Append GT_LIST_TOP_OF_PAGE. FORM TOP_OF_PAGE. CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' EXPORTING IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE. ENDFORM.

13

Reuse_alv_grid_display
A new function in 4.6 version, to display the results in grid rather than as a list.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = G_REPID I_STRUCTURE_NAME = 'SFLIGHT IS_LAYOUT = GS_LAYOUT IT_FIELDCAT = GT_FIELDCAT[ ] IT_SPECIAL_GROUPS = GT_SP_GROUP[ ] I_SAVE = G_SAVE Report program Name Structure of ALV Layout of ALV Catalog for Headings in ALV

IS_VARIANT = G_VARIANT
IT_EVENTS = GT_EVENTS[ ] * IMPORTING * E_EXIT_CAUSED_BY_CALLER = TABLES T_OUTTAB = GT_SFLIGHT.

Variants in ALV
Events in ALV

14

Reuse_alv_hierseq_list_dispaly
To display Hierarchical Sequential display of reports
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY' EXPORTING i_tabname_header = 'IT_SPFLI' i_tabname_item = 'IT_SFLIGHT' i_structure_name_header = 'SPFLI' i_structure_name_item = 'SFLIGHT' is_keyinfo = my_keyinfo Of Type slis_keyinfo_alv * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab_header = it_spfli t_outtab_item = it_sflight * EXCEPTIONS * PROGRAM_ERROR =1 * OTHERS =2 .

15

A table for Events


*Internal Table needed for events DATA: i_events TYPE slis_t_event. *Calling Function module to populate table with possible events CALL FUNCTION 'REUSE_ALV_EVENTS_GET' EXPORTING i_list_type =0 = i_events

IMPORTING
et_events EXCEPTIONS list_type_wrong = 1 OTHERS = 2.

SORT i_events BY name. Continued to next page

16

A table for Events contd.


SORT i_events BY name. *Reading events table READ TABLE i_events WITH KEY name = 'TOP_OF_PAGE' BINARY SEARCH. IF sy-subrc IS INITIAL. *Assign event name to variable MOVE 'TOP_OF_PAGE' TO i_events-form. MODIFY i_events INDEX sy-tabix. ENDIF.

17

The Layout for report display


A layout is build for the report output description USING the internal table for Layout (I_LAYOUT). The layout parameters are described under the following heads: Display options

Exceptions
Totals Interaction Detail screen

Color
Other

18

Preparing the Layout contd.

DATA: st_layout TYPE slis_layout_alv, " ALV Layout st_layout-box_fieldname st_layout-get_selinfos = 'BOX'. " Box Fieldname = 'X'. " Get info of select records

st_layout-colwidth_optimize = 'X'.
st_layout-no_keyfix = 'X'.

" To optimize coloumn width


" To scroll Key fields

19

The Sorting and/or Subtotaling of the basic list.


The Table IT_SORT is populated with the sort criteria for the different fields. The caller specifies the Sorting and/or Subtotaling of the basic list in the internal table IT_SORT. This internal table has the following fields: spos : Sort sequence fieldname : Internal output table field name tabname : Only relevant for hierarchical-sequential lists. Name of the internal output table. up : 'X' = sort in ascending order down : 'X' = sort in descending order subtot : 'X' = subtotal at group value change

group : '* ' = new page at group value change ,'UL' = underline at group value change

20

Simple Program Walkthrough : REUSE_ALV_LIST_DISPLAY


REPORT Y_DEMO_ALV_LIST NO STANDARD PAGE HEADING. * Data to be displayed DATA: I_SFLIGHT TYPE TABLE OF SFLIGHT. * Selection SELECT * FROM SFLIGHT INTO TABLE I_SFLIGHT. * Call ABAP List Viewer (ALV) CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' EXPORTING I_STRUCTURE_NAME = 'SFLIGHT'

TABLES
T_OUTTAB = I_SFLIGHT.

21

Result: REUSE_ALV_LIST_DISPLAY

22

Simple Program Walkthrough: REUSE_ALV_GRID_DISPLAY

REPORT Y_DEMO_ALV_GRID .
* Data to be displayed DATA: I_SFLIGHT TYPE TABLE OF SFLIGHT. * Selection SELECT * FROM SFLIGHT INTO TABLE I_SFLIGHT. * Call ABAP List Viewer (ALV) CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_STRUCTURE_NAME TABLES T_OUTTAB = I_SFLIGHT. = 'SFLIGHT'

23

Result : REUSE_ALV_GRID_DISPLAY

24

Simple Program Walkthrough: Including Title in the Report for GRID DISPLAY

Title

In the PARAMETERS give I_GRID_TITLE = 'Flight Information and Call the function 'REUSE_ALV_GRID_DISPLAY'

25

Simple Program Walkthrough: Using FIELDCAT to Position Columns


DATA: i_fcat TYPE slis_t_fieldcat_alv, wa_fcat TYPE slis_fieldcat_alv. wa_fcat-tabname = 'I_SFLIGHT'. wa_fcat-col_pos = '1'. wa_fcat-fieldname = 'CARRID'. append wa_fcat to i_fcat. wa_fcat-col_pos = '2'. wa_fcat-fieldname = 'FLDATE'. append wa_fcat to i_fcat. wa_fcat-col_pos = '3'. wa_fcat-fieldname = 'CONNID'. append wa_fcat to i_fcat. wa_fcat-col_pos = '4'. wa_fcat-fieldname = 'PRICE'. APPEND wa_fcat TO i_fcat.
26

wa_fcat-fieldname = 'CURRENCY'. wa_fcat-no_out = 'X'. APPEND wa_fcat TO i_fcat. wa_fcat-fieldname = 'PLANETYPE'. wa_fcat-no_out = 'X'. APPEND wa_fcat TO i_fcat.

In the function module pass :


IT_FIELDCAT = i_fcat

Result :

PRICE CONNID FLDATE CARRID

27

Simple Program Walkthrough : Make some fields Editable


Make the field PRICE editable by updating the field catalog.

wa_fcat-col_pos = '4'. wa_fcat-fieldname = 'PRICE'. wa_fcat-edit = 'X'. append wa_fcat to i_fcat. clear wa_fcat. To make PRICE field editable

28

Result : Field Editable

Editable Field - Price

29

Simple Program Walkthrough: REUSE_ALV_HIERSEQ_LIST_DISPLAY


REPORT Z15_ALV_HEIR. TYPE-POOLS: slis. DATA: it_sflight TYPE TABLE OF sflight, wa_sflight TYPE sflight, it_spfli TYPE TABLE OF spfli. DATA: my_keyinfo TYPE slis_keyinfo_alv. SELECT-OPTIONS: so_car FOR wa_sflight-carrid, so_con FOR wa_sflight-connid. CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY' EXPORTING i_tabname_header = 'IT_SPFLI' i_tabname_item = 'IT_SFLIGHT' i_structure_name_header = 'SPFLI' i_structure_name_item = 'SFLIGHT' is_keyinfo = my_keyinfo TABLES t_outtab_header = it_spfli t_outtab_item = it_sflight EXCEPTIONS PROGRAM_ERROR =1 OTHERS =2 . my_keyinfo-header01 = 'MANDT'. my_keyinfo-item01 = 'MANDT'. my_keyinfo-header02 = 'CARRID'. my_keyinfo-item02 = 'CARRID'. my_keyinfo-header03 = 'CONNID'. my_keyinfo-item03 = 'CONNID'.

START-OF-SELECTION. SELECT * FROM spfli INTO TABLE it_spfli WHERE carrid IN so_car AND connid IN so_con.
SELECT * FROM sflight INTO TABLE it_sflight WHERE carrid IN so_car AND connid IN so_con.

30

Result : REUSE_ALV_HIERSEQ_LIST_DISPLAY contd.

31

Thank You!

Potrebbero piacerti anche