ABAP Code Sample For Data Browser Using ALV Grid
ABAP Code Sample For Data Browser Using ALV Grid
Summary :
Here is a code sample that performs the operation similar to Data Browser.
This adopts the simplest way to display any table from Data Dictionary and
the data of any table can be edited right from ALV Grid itself.
Some of the concepts that can be learnt from this code samples are
a. Creating ALV grid (for Displaying as well as editing Data).
b. Generating Field Catalog Automatically.
c. Creating Dynamic internal Table.
d. Moving buttons to the ALV tool-bar & Creating Event-Handlers.
*&--------------------------------------------------------------------*
*& Report ZIALV_EDIT_SIMPLE1 *
*&--------------------------------------------------------------------*
*---------------------------------------------------------------------*
* Description : ALV to perform Displaying and Editing Tables
* Technical Contact : [email protected]
* Technical Spec. Number : ZIALV_EDIT_SIMPLE1
* Created on : 24/01/04
*---------------------------------------------------------------------*
report zialv_edit_simple1 .
include <icon>.
*----------------------------------------------------------------------
* Definition of Grid event-handler class
*----------------------------------------------------------------------
class lcl_grid_event_receiver definition.
public section.
methods:
toolbar for event toolbar
of cl_gui_alv_grid
importing e_object
e_interactive
endclass.
*-------------------------------------------------------------------*
*mplementation of Grid event-handler class
*-------------------------------------------------------------------*
class lcl_grid_event_receiver implementation.
*---------------------------------------------------------------------
* Method for handling all creation/modification calls to the toolbar
*---------------------------------------------------------------------
method toolbar.
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'UPDA' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'UPDATE' to ls_toolbar-text.
move icon_system_save to ls_toolbar-icon.
move 'Click2Update' to ls_toolbar-quickinfo.
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'EXIT' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'EXIT' to ls_toolbar-text.
move icon_system_end to ls_toolbar-icon.
move 'Click2Exit' to ls_toolbar-quickinfo.
endmethod.
*----------------------------------------------------------------------
* Method to handle user commands from toolbar
*----------------------------------------------------------------------
method user_command.
case e_ucomm .
when 'EDIT'.
perform set_input.
when 'UPDA'.
perform refresh_disp.
perform update_table.
when 'EXIT'.
leave program.
endcase.
endmethod.
endclass.
*---------------------------------------------------------------*
* Declarations
*---------------------------------------------------------------*
parameters:
p_intab type dfies-tabname default 'SAPLANE'.
data :
dref type ref to data,
it_grid_fcat type lvc_t_fcat,
struct_grid_lset type lvc_s_layo,
tab_info like table of dfies.
field-symbols :
<fs_tab> like line of tab_info,
**** Output Structure****
<it_disptab> type table.
data :
*----------------------------------------------------------------------
* Container Object [grid_container]
*----------------------------------------------------------------------
,grid_container type ref to cl_gui_custom_container
*----------------------------------------------------------------------
* Control Object [grid]
*----------------------------------------------------------------------
,grid type ref to cl_gui_alv_grid
*----------------------------------------------------------------------
* Event-Handler Object [grid_handler]
*----------------------------------------------------------------------
,grid_handler type ref to lcl_grid_event_receiver
. " period
*----------------------------------------------------------------------
* Begin of process logic
*----------------------------------------------------------------------
start-of-selection.
*--------------------------------------------------------------------*
* ALV GRID
*--------------------------------------------------------------------*
if grid_container is initial.
perform populate_grid_data .
endif.
endmodule.
*&--------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&--------------------------------------------------------------------*
module user_command_0100 input.
*&--------------------------------------------------------------------*
*& Form EXIT_PROGRAM
*&--------------------------------------------------------------------*
form exit_program.
leave program.
*&--------------------------------------------------------------------*
*& Form populate_grid_data
*&--------------------------------------------------------------------*
form populate_grid_data.
*---------------------------------------------------------------------*
* FORM refresh_disp *
*---------------------------------------------------------------------*
form refresh_disp.
endform.
*---------------------------------------------------------------------*
* FORM update_table *
*---------------------------------------------------------------------*
form update_table.
endform.
*---------------------------------------------------------------------*
* FORM set_input *
*---------------------------------------------------------------------*
form set_input.
endform.
Screen Logic :
module status_0100.
process after input.
module user_command_0100.
Screen No : 100
The screen consists of just a custom control of name CCONTAINER1