ABAP Program with Editable ALV Grid Contents

0
1362

Using ALV Grid is always beneficial in terms operations and activities we can perform on the data. It even allow us to download data in various formats. But when compared to Table Control, its main disadvantage is, un-editable / read-only data.

Here is a simple program to make certain cells of an ALV grid control editable.

Editable Table Grid
Editable Table Grid

 

In present context the VBRK details are displayed where the KALSM is editable only where Sales Organization(VKORG) is ‘0300’.

Note: Please do the following before executing the program.

1) create the gui interface ‘pf-status’ (with BACK and EXIT buttons) and a container ( give name as CONTAINER) for the screen.

2) In PBO of screen, write ‘MODULE LIST.’ after ‘MODULE STATUS_0100′.

 

Sample Code:

REPORT Z_ALV_EDIT_CELL.

*internal table declaration
DATA:
BEGIN OF t_itab OCCURS 0.
INCLUDE STRUCTURE VBRK.

*Adding a table of type LVC_T_SCOL to the output table that holds the status of editable cells
DATA t_editcell TYPE lvc_t_styl.
DATA END OF t_itab.

*Style table for cells and its work area
DATA: t_editcell TYPE lvc_t_styl,
fs_editcell LIKE LINE OF t_editcell.

*declaring the container & grid for output table display

DATA:
r_container TYPE REF TO cl_gui_custom_container,
r_grid TYPE REF TO cl_gui_alv_grid.

*structure of layout

DATA:
fs_layout TYPE lvc_s_layo.

START-OF-SELECTION.

SELECT * FROM VBRKt INTO CORRESPONDING FIELDS OF TABLE t_itab UP TO 20 ROWS.

*—————————————————————————–

*populating layout

fs_layout-stylefname = ‘T_EDITCELL’.

*—————————————————————————–

LOOP AT t_itab.

REFRESH t_editcell.

*making the KALSM editable for editing data for specific Sales Organization(0300)
IF t_itab-vkorg = ‘0300’.

*populating t_editcell which contains fieldname+style of cell

fs_editcell-fieldname = ‘ KALSM’.

fs_editcell-style = cl_gui_alv_grid=>MC_STYLE_ENABLED. ” the value represents EDIT ENABLED

APPEND fs_editcell TO t_editcell.

ENDIF.

INSERT LINES OF t_editcell INTO TABLE t_itab-t_editcell.

MODIFY t_itab.

ENDLOOP.

 

CALL SCREEN 100.

 

*&———————————————————————

*&Module STATUS_0100 OUTPUT

*&———————————————————————

* text

*———————————————————————-

MODULE status_0100 OUTPUT.

SET PF-STATUS ‘SCREEN1’.

ENDMODULE.” STATUS_0100 OUTPUT

*&———————————————————————

*&Module USER_COMMAND_0100 INPUT

*&———————————————————————

* text

*———————————————————————-

MODULE user_command_0100 INPUT.

CASE sy-ucomm.

WHEN ‘BACK’.

LEAVE TO SCREEN 0.

WHEN ‘EXIT’.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE.” USER_COMMAND_0100 INPUT

*&———————————————————————

*& Module LIST OUTPUT

*&———————————————————————

* text

*———————————————————————-

MODULE list OUTPUT.

CREATE OBJECT r_container

EXPORTING

container_name = ‘CONTAINER’.

CREATE OBJECT r_grid

EXPORTING

i_parent = r_container.

*call this method to make the cell ready for input

CALL METHOD r_grid->set_ready_for_input

EXPORTING

i_ready_for_input = 1.

*passing the layout structure, fieldcatalog and output table for display

CALL METHOD r_grid->set_table_for_first_display

EXPORTING

i_structure_name = ‘SFLIGHT’

is_layout = fs_layout

CHANGING

it_outtab = t_itab[].

ENDMODULE. ” LIST OUTPUT

 


LEAVE A REPLY

Please enter your comment!
Please enter your name here