ABAP List Viewer (ALV)
ABAP List Viewer (ALV)
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
Advantages of ALV
Looks better. User friendly 1. Filtering / Sorting
ALV Features
Email Change Layout Download to Excel Filtering Sorting Column Heading Row(s) Selection
Display Graphics
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
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
IMPORTING
et_events EXCEPTIONS list_type_wrong = 1 OTHERS = 2.
16
17
Exceptions
Totals Interaction Detail screen
Color
Other
18
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'.
19
group : '* ' = new page at group value change ,'UL' = underline at group value change
20
TABLES
T_OUTTAB = I_SFLIGHT.
21
Result: REUSE_ALV_LIST_DISPLAY
22
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
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.
Result :
27
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
29
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
31
Thank You!