ALV Grid using Objects - Simple example


This example shows a simple example of  how to create an ALV grid using ABAP Objects

Insert the code below in a report
Create screen 0100 and place a Custom contol on the screen. Name the control MY_CONTAINER
In PROCESS BEFORE OUTPUT for screen 0100 insert:   MODULE create_objects.
Run the report
Double click on a row in the grid


Result






Code

REPORT zalv_test.


*---------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS: on_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING
es_row_no
e_column.
ENDCLASS. "lcl_event_handler DEFINITION


*---------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD on_double_click.
DATA: msg_string TYPE string,
row_string TYPE string.
row_string = es_row_no-row_id.
CONCATENATE 'Row: ' row_string ' Column: ' e_column-fieldname
INTO msg_string.
MESSAGE msg_string TYPE 'I'.
ENDMETHOD. "on_double_click
ENDCLASS. "lcl_event_handler IMPLEMENTATION

DATA:
r_cont TYPE REF TO cl_gui_custom_container,
r_grid TYPE REF TO cl_gui_alv_grid,
itab TYPE TABLE OF spfli,
r_handler TYPE REF TO lcl_event_handler.



START-OF-SELECTION.
SELECT * FROM spfli
INTO TABLE itab.

CALL SCREEN 100.


*&---------------------------------------------------------------------*
*& Module create_objects OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE create_objects OUTPUT.
CHECK r_cont IS INITIAL.
CREATE OBJECT r_cont EXPORTING container_name = 'MY_CONTAINER'.
CREATE OBJECT r_grid EXPORTING i_parent = r_cont.
r_grid->set_table_for_first_display(
EXPORTING i_structure_name = 'SPFLI'
CHANGING it_outtab = itab ).
CREATE OBJECT r_handler.
SET HANDLER r_handler->on_double_click FOR r_grid.
ENDMODULE. " create_objects OUTPUT
Converted from CHM to HTML with chm2web Standard 2.7 (unicode)