-
It’s an ABAP OO class that displays data in a grid (table-like format) inside a screen container.
-
Unlike the simpler
CL_SALV_TABLE
, this grid is fully interactive and customizable.
Main Features
-
Editable cells → You can let users change data directly in the grid.
-
Field catalog → You define which columns to show, their titles, and if they’re editable.
-
Layout control → Zebra patterns, column widths, key columns, hotspots, etc.
-
Events → You can react to user actions (e.g., double-click, toolbar buttons, cell value changes).
-
Container-based → You need a custom control on a dynpro (screen) to host the ALV Grid.
How it Works (Step-by-Step Flow)
-
Create a Screen (Dynpro)
-
Add a Custom Control (like a placeholder on the screen).
-
Give it a name, e.g.,
CC_ALV
.
-
-
Create Container
-
In your program, create an object of class
CL_GUI_CUSTOM_CONTAINER
linked toCC_ALV
. -
This is the “holder” where the ALV will appear.
-
-
Create ALV Grid
-
Instantiate
CL_GUI_ALV_GRID
using the container as its parent.
-
-
Build Field Catalog
-
Define column properties (
FIELDNAME
,SELTEXT_M
,EDIT
, etc.). -
Each entry describes how a column is shown in the ALV grid.
-
-
Pass Data to ALV
-
Call method
set_table_for_first_display
with your internal table (IT_OUTTAB
) and the field catalog.
-
-
Display Grid
-
The ALV Grid now shows inside the screen.
-
Users can scroll, filter, sort, and (if allowed) edit data.
-
Steps to Implement CL_GUI_ALV_GRID
1. Create a Screen (e.g., Screen 100)
-
Go to SE80 → your program → create a screen (No. 100).
-
On the screen, draw a Custom Control (name it
CC_ALV
). -
Add a GUI status (with functions BACK, EXIT, CANCEL).
REPORT z_alv_grid_editable.
************************************************************************
* TYPES & DATA DECLARATIONS
************************************************************************
TYPES: BEGIN OF ty_spfli,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
cityfrom TYPE spfli-cityfrom,
cityto TYPE spfli-cityto,
END OF ty_spfli.
DATA: gt_spfli TYPE TABLE OF ty_spfli,
gs_spfli TYPE ty_spfli.
” ALV references
DATA: go_container TYPE REF TO cl_gui_custom_container,
go_alv TYPE REF TO cl_gui_alv_grid.
” Field catalog & layout
DATA: gt_fieldcat TYPE lvc_t_fcat,
gs_fieldcat TYPE lvc_s_fcat,
gs_layout TYPE lvc_s_layo.
************************************************************************
* START-OF-SELECTION
************************************************************************
START-OF-SELECTION.
” Fetch some demo data
SELECT carrid connid cityfrom cityto
FROM spfli
INTO TABLE gt_spfli.
” Call ALV screen
CALL SCREEN 100.
************************************************************************
* MODULES FOR SCREEN 100
************************************************************************
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘MAIN’. ” Create a status MAIN in GUI status
IF go_container IS INITIAL.
” Create container linked to CC_ALV on screen
CREATE OBJECT go_container
EXPORTING container_name = ‘CC_ALV’.
” Create ALV Grid object
CREATE OBJECT go_alv
EXPORTING i_parent = go_container.
” Layout options
gs_layout-zebra = abap_true. ” striped display
” Build field catalog
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = ‘CARRID’.
gs_fieldcat-seltext_m = ‘Carrier ID’.
gs_fieldcat-edit = abap_true. ” Editable
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = ‘CONNID’.
gs_fieldcat-seltext_m = ‘Connection ID’.
gs_fieldcat-edit = abap_true. ” Editable
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = ‘CITYFROM’.
gs_fieldcat-seltext_m = ‘From City’.
gs_fieldcat-edit = abap_true. ” Editable
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = ‘CITYTO’.
gs_fieldcat-seltext_m = ‘To City’.
gs_fieldcat-edit = abap_true. ” Editable
APPEND gs_fieldcat TO gt_fieldcat.
” Display data in ALV
CALL METHOD go_alv->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_fieldcatalog = gt_fieldcat
it_outtab = gt_spfli.
ENDIF.
ENDMODULE.
************************************************************************
* Handle user commands
************************************************************************
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN ‘BACK’ OR ‘EXIT’ OR ‘CANCEL’.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.