No products in the cart.
ALV
Editable ALV using the procedural approach
To create an editable ALV using the procedural approach, we use the REUSE_ALV_GRID_DISPLAY function module. However, to make cells editable, we must use a Field Catalog.
In a field catalog, you define the properties of each column. By setting the EDIT field to ‘X’, the cell becomes an input field.
The ABAP Code
REPORT z_editable_alv_procedural.
* 1. Data Declaration
TABLES: sflight.
DATA: it_sflight TYPE TABLE OF sflight,
it_fieldcat TYPE slis_t_fieldcat_alv, ” Internal table for field catalog
wa_fieldcat TYPE slis_fieldcat_alv. ” Work area for field catalog
* 2. Data Retrieval
START-OF-SELECTION.
SELECT * FROM sflight INTO TABLE it_sflight UP TO 20 ROWS.
* 3. Building the Field Catalog manually to enable editing
” Define Column: Flight Connection ID
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = ‘CONNID’.
wa_fieldcat-seltext_m = ‘Connection ID’.
wa_fieldcat-tabname = ‘IT_SFLIGHT’.
APPEND wa_fieldcat TO it_fieldcat.
” Define Column: Price (Make this EDITABLE)
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = ‘PRICE’.
wa_fieldcat-seltext_m = ‘Flight Price’.
wa_fieldcat-tabname = ‘IT_SFLIGHT’.
wa_fieldcat-edit = ‘X’. ” This makes the column editable
APPEND wa_fieldcat TO it_fieldcat.
* 4. Display ALV Report
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
it_fieldcat = it_fieldcat
TABLES
t_outtab = it_sflight
EXCEPTIONS
program_error = 1
OTHERS = 2.
How the Editability Works
- The Field Catalog (slis_t_fieldcat_alv): Unlike the previous example where we passed i_structure_name, here we manually define the columns. This is necessary because the standard structure is “read-only” by default.
- The EDIT Flag: By setting wa_fieldcat-edit = ‘X’, the ABAP runtime renders that specific column as an input field (usually with a white background instead of grey).
- Data Synchronization: When the user types a new value in the grid and presses “Enter” or “Save,” the values are updated in the internal table it_sflight in the program’s memory.
Important Note on Saving
- The code above makes the screen editable, but it does not save changes to the database. To save data, you would need to:
- Add a custom button to the ALV toolbar (using a PF-STATUS).
- Capture the user action in a USER_COMMAND subroutine.
- Execute an UPDATE sflight … statement using the modified data in it_sflight.