0% found this document useful (0 votes)
191 views37 pages

ABAP LIST VIEWER (ALV) - Presentation

ABC, Mail and Download to Excel. Add a ‘SAVE’ button.  Populate the excluding table IT_EXCLUDING with the function codes for ABC, Mail and Excel  Add a row to the RT_EXTAB table with the button text as ‘SAVE’ and icon as ‘Floppy’ CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS' TABLES IT_EXCLUDING = IT_EXCLUDING CHANGING CT_EXTAB = RT_EXTAB | © Copyright IBM Corporation 2003

Uploaded by

Adão da luz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views37 pages

ABAP LIST VIEWER (ALV) - Presentation

ABC, Mail and Download to Excel. Add a ‘SAVE’ button.  Populate the excluding table IT_EXCLUDING with the function codes for ABC, Mail and Excel  Add a row to the RT_EXTAB table with the button text as ‘SAVE’ and icon as ‘Floppy’ CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS' TABLES IT_EXCLUDING = IT_EXCLUDING CHANGING CT_EXTAB = RT_EXTAB | © Copyright IBM Corporation 2003

Uploaded by

Adão da luz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 37

IBM Global Services

ABAP LIST VIEWER (ALV)

| © Copyright IBM Corporation 2003


IBM Global Services

ALV

 ABAP List Viewer (ALV) is a simple, user friendly and better looking reporting
tool as compared to the usage of write statements in a conventional /
interactive report.

| © Copyright IBM Corporation 2003


IBM Global Services

Advantages of ALV

 Better Looking
 User friendly
- Filtering / Sorting
- Layout Change / Save
- Summation, Download to excel, E-Mail
- 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.

| © Copyright IBM Corporation 2003


IBM Global Services

ALV Features

Change /
Heading Save
Layout

Row(s)
Selection Sorting, Filtering Email, Excel
Additional
Buttons

| © Copyright IBM Corporation 2003


IBM Global Services
ALV Features

Bar Charts

Fields Open For


Input

| © Copyright IBM Corporation 2003


IBM Global Services

ALV Programming

 Two Approaches
- Conventional (Using Standard Function Modules)
- Object Oriented (Using Standard Classes and Methods)

| © Copyright IBM Corporation 2003


IBM Global Services

ALV Function Modules

REUSE_ALV_LIST_DISPLAY REUSE_ALV_GRID_DISPLAY

Program: BALVSD02 Program: BALVSD02_GRID


| © Copyright IBM Corporation 2003
IBM Global Services

ALV Function Modules

 Both REUSE_ALV_LIST_DISPLAY and REUSE_ALV_GRID_DISPLAY have similar


parameters
 Both Display the contents of an internal table passed by the parameter T_OUTTAB

| © Copyright IBM Corporation 2003


IBM Global Services

ALV Function Modules: Parameters

 Important Parameters
- I_CALLBACK_PROGRAM

 The program that contains the subroutine for user command handling
 The program that will be the reference for user specific layout variants
 SY-CPROG in most cases
- I_CALLBACK_PF_STATUS_SET

 The subroutine name that will set the PF-STATUS (which in turn may
contain user defined buttons)
- I_CALLBACK_USER_COMMAND

 The subroutine name in the calling program that will be triggered on any user
command

| © Copyright IBM Corporation 2003


IBM Global Services

ALV Function Modules: Parameters

 Important Parameters
- I_STRUCTURE_NAME

 The type of the internal table to be displayed


- I_GRID_TITLE

 The Heading / Title of the GRID


- IS_LAYOUT

 Defines the layout in which the internal table will be displayed


 Layout specific Features like Optimize Column Width, Window Title Bar, No
Summing Up, colors etc. are defined here
- IT_FIELDCAT

 Defines the properties of individual fields (columns) of the internal table to be


displayed
 Field specific features like Editable / Non Editable, Heading, Column
Position, Left / Right Justification etc. are defined here

| © Copyright IBM Corporation 2003


IBM Global Services

ALV Function Modules: Parameters

 Important Parameters
- IT_EXCLUDING

 The Buttons / Function codes that need to be disabled


- I_SAVE

 Whether Users should be able to save layout variants of their choice


- IT_EVENTS

 The various events which need to be trapped and dealt with


Initialize the events using REUSE_ALV_EVENTS_GET
Populate the internal table provided by the FM to include the subroutines
that contain the various events
 Some of the events are callback events
I_CALLBACK_PF_STATUS_SET – For setting PF Status
I_CALLBACK_USER_COMMAND – For handling user command interactions
I_CALLBACK_TOP_OF_PAGE – Top of Page

| © Copyright IBM Corporation 2003


IBM Global Services

- IT_SORT
The order in which the fields should be grouped before display
It contains the following fields
spos:- Sort order
fieldname:- Field name in the internal output table
up 'X' = Sorted in ascending order
down 'X' = Sorted in descending order
subtot 'X' = Subtotals for control level changes

| © Copyright IBM Corporation 2003


IBM Global Services

Simple Programs Walkthrough

 Populate the internal table with the contents to be displayed and call the function
module.

Data: i_sflight type standard table of sflight initial size 0 with header line.
Select * from sflight into table i_sflight.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
I_CALLBACK_PROGRAM = sy-cprog
I_STRUCTURE_NAME = 'SFLIGHT'
TABLES
T_OUTTAB = i_sflight.

| © Copyright IBM Corporation 2003


IBM Global Services

Result

| © Copyright IBM Corporation 2003


IBM Global Services

Simple Programs Walkthrough

 Saving Layout Variants (Order of Columns, Hiding Specific Columns etc.)


I_SAVE = ‘A’

Change / Save /
Select Layout

Give Layout Name,


User Specific / Default
Layout

| © Copyright IBM Corporation 2003


IBM Global Services

Simple Programs Walkthrough

 Grid Title Required


I_GRID_TITLE = ‘Flight Information’

Heading

| © Copyright IBM Corporation 2003


IBM Global Services

Simple Programs Walkthrough

 Suppose the first 4 fields of the internal table are required in the order CARRID, FLDATE, CONNID, PRICE.
Also the fields CURRENCY and PLANETYPE are not to be displayed.
Populate the Field Catalog table appropriately
data: i_fcat type slis_t_fieldcat_alv,
wa_fcat type slis_fieldcat_alv.

wa_fcat-tabname = 'I_SFLIGHT'.
wa_fcat-fieldname = 'CURRENCY'.
wa_fcat-col_pos = '1'.
wa_fcat-no_out = 'X'.
wa_fcat-fieldname = 'CARRID'.
append wa_fcat to i_fcat.
append wa_fcat to i_fcat.
wa_fcat-fieldname = 'PLANETYPE'.
wa_fcat-col_pos = '2'.
wa_fcat-no_out = 'X'.
wa_fcat-fieldname = 'FLDATE'.
append wa_fcat to i_fcat.
append wa_fcat to i_fcat.
wa_fcat-col_pos = '3'.
wa_fcat-fieldname = 'CONNID'. In the function module,
append wa_fcat to i_fcat.
IT_FIELDCAT = i_fcat
wa_fcat-col_pos = '4'.
wa_fcat-fieldname = 'PRICE'.
append wa_fcat to i_fcat.
| © Copyright IBM Corporation 2003
IBM Global Services

Result

PRICE
CONNID
No CURRENCY And PLANETYPE
FLDATE

CARRID

| © Copyright IBM Corporation 2003


IBM Global Services

Simple Programs Walkthrough

 Obtaining the field catalog internal table using the internal table name
 Use Function Module REUSE_ALV_FIELDCATALOG_MERGE

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'


EXPORTING
I_INTERNAL_TABNAME = 'I_SFLIGHT'
I_STRUCTURE_NAME = 'SFLIGHT'
CHANGING
CT_FIELDCAT = I_FCAT

| © Copyright IBM Corporation 2003


IBM Global Services

Simple Programs Walkthrough

 Suppose it is required to add a button ‘SAVE’ to the application toolbar. Also, the ABC
Analysis, Mail and Download to Excel need to be removed.
 Create a Subroutine SET_PF_STATUS using rt_extab type slis_t_extab
 Within this subroutine, write
SET PF-STATUS ‘YFLIGHTS’.
 Double Click on ‘YFLIGHTS’ and create a PF-STATUS
 Go to Extras -> Adjust Template and Choose the List Viewer Radio Button. Standard ALV PF-
STATUS will be selected.
 Remove the function keys and Buttons for ABC Analysis and Mail and Download to Excel from
the PF-STATUS
 Add a function code and button for SAVE.
 Save and Activate the PF-STATUS
 While calling the function module ‘REUSE_ALV_GRID_DISPLAY’ use
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'

 Alternatively, Removal of Buttons can be done by populating the internal table


IT_EXCLUDING with the relevant function codes

| © Copyright IBM Corporation 2003


IBM Global Services

Result

SAVE Button

No Excel, Email or ABC


Analysis Buttons

| © Copyright IBM Corporation 2003


IBM Global Services

Simple Programs Walkthrough

 Suppose we need to make the price editable and saved to the database table
SFLIGHT
 Use Function Module REUSE_ALV_FIELDCATALOG_MERGE to get the Field
Catalog internal table
 Change the Field Catalog table for fieldname entry ‘PRICE’
read table i_fcat into wa_fcat with key fieldname = 'PRICE'.
if sy-subrc = 0.
wa_fcat-edit = 'X'.
modify i_fcat index sy-tabix from wa_fcat transporting edit.
endif.
 Create a PF-Status as described previously and use a function code
&DATA_SAVE

| © Copyright IBM Corporation 2003


IBM Global Services

Simple Programs Walkthrough

 Create a Subroutine USER_COMMAND using r_ucomm like sy-ucomm


rs_selfield type slis_selfield.
 Within this subroutine, handle user command
if r_ucomm = '&DATA_SAVE'.
modify sflight from table i_sflight.
message i000 with 'Data saved'.
rs_selfield-refresh = 'X'.
rs_selfield-col_stable = 'X'.
rs_selfield-row_stable = 'X'.
endif.

 While calling the function module ‘REUSE_ALV_GRID_DISPLAY’ use


I_CALLBACK_USER_COMMAND = ‘USER_COMMAND'

| © Copyright IBM Corporation 2003


IBM Global Services
Result

Function Code
and Button for
Other Fields &DATA_SAVE
(Non Editable)
PRICE
(Editable)

| © Copyright IBM Corporation 2003


IBM Global Services

Important Information

 Use Programs Starting with BALV and BCALV


 Use Function Module Helps

| © Copyright IBM Corporation 2003


IBM Global Services

The Object Oriented methodology in ALV

 ALVs can be used using object oriented methodology


 Class mainly used is CL_GUI_ALV_GRID
 Instance is created with reference to CL_GUI_ALV_GRID
 Class contains both control-specific methods and methods of the OO Control
Framework

| © Copyright IBM Corporation 2003


IBM Global Services

Class Hierarchy Structure

CL_GUI_OBJECT

CL_GUI_CONTROL

CL_GUI_ALV_GRID_BASE

CL_GUI_ALV_GRID

| © Copyright IBM Corporation 2003


IBM Global Services

Working with Controls

 Create a Screen for the Report and embed a custom control in the screen
 Call methods for the various operations in PBO for initializing the ALV
 Call methods for performing user actions or handling events

| © Copyright IBM Corporation 2003


IBM Global Services

Screen Creation

 Create a Screen for the Report by using “Call Screen”


• Normal Conventional Reports are displayed in the standard SAP
Screen
• ALV Reports need its own screen for data display
• Create a Custom Control in the newly created screen

| © Copyright IBM Corporation 2003


IBM Global Services

PBO

 Calling methods for the various operations (PBO)


 Create a Container Object for the ALV
CREATE OBJECT v_custom_container1
EXPORTING
container_name = v_container1.
( v_container is the name of the Custom Control)
 Create an ALV object
CREATE OBJECT obj_alv_grid1
EXPORTING
i_parent = v_custom_container1

 Build Field Catalogue Table

 Display ALV using method set_table_for_first_display

| © Copyright IBM Corporation 2003


IBM Global Services

PBO

CALL METHOD obj_alv_grid1->set_table_for_first_display


EXPORTING
i_structure_name = c_tabnam
is_variant = wa_variant
i_save = c_a
is_layout = wa_layout
CHANGING
it_outtab = i_final
it_fieldcatalog = l_i_fcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.

| © Copyright IBM Corporation 2003


IBM Global Services

PBO

 Check before creating objects in the PBO that they should not be instantiated time
and again, so a check should be present whether the object is already instantiated

IF v_custom_container1 IS INITIAL.
CREATE OBJECT v_custom_container1
EXPORTING
container_name = v_container1.

*-- Initiating the wrapper class for the ALV Grid and associating
it with the container
CREATE OBJECT obj_alv_grid1
EXPORTING
i_parent = v_custom_container1.
ENDIF

| © Copyright IBM Corporation 2003


IBM Global Services

PAI

 Call methods for performing user actions or handling events


• Call the various methods defined in program for performing user
interactions
• Handle events

| © Copyright IBM Corporation 2003


IBM Global Services

Important methods of CL_GUI_ALV_GRID

 Get_current_cell

CALL METHOD OB_IDOC_GRID->GET_CURRENT_CELL


IMPORTING
E_ROW = L_ROW
E_VALUE = L_VALU
ES_COL_ID = L_TABCOL
 get_selected_columns
 get_selected_rows
 get_subtotals
 set_selected_cells
 set_drop_down_table

| © Copyright IBM Corporation 2003


IBM Global Services

Important Events of CL_GUI_ALV_GRID

 double_click - gets triggered when you double click on a cell


 hotspot_click - gets triggered when you click on the hotspot
 Data_changed - when some data changes in an editable ALV
( Very useful for editable ALV’s )

| © Copyright IBM Corporation 2003


IBM Global Services

Implementing Event Driven Functionalities

 Declare Methods related to the events


Methods: data_changed
FOR EVENT
data_changed OF cl_gui_alv_grid
IMPORTING
er_data_changed.
 Set handlers for the methods that are going to be called
SET HANDLER obj_eve1->data_changed FOR obj_alv_grid1.

| © Copyright IBM Corporation 2003


IBM Global Services

Sample Program Walk Through

 /AMS/FMXCSR_AUTO_CUST_PAYMENTS

| © Copyright IBM Corporation 2003

You might also like