Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ALV Grid editable cells

Former Member
0 Likes
6,726

Howdy pros,

I've stumbled upon a problem. I want to make some of my alv cells editable.

I've build my alv with cl_gui_alv_grid. ( so no salv or function alv ).

This is exercise purpose only.

I know i can make fields of my alv editable by using my field_catalog ( field_catalog-edit = 'X' ) and it works fine with this.


But how can i use the layout to do this? ( how can i edit only one row, like when i want to add a new one and it becomes ready for input and after i save the new row it becomes unable to edit )

I've found some useful stuff but i think i'm still missing something.

1) I've added to my data_table  a new field cellstyles.

In a loop have filled the fileds

style = cl_gui_alv_grid=>mc_style_enabled

fieldname = 'FIELDNAME'

( in debuger i can see that it takes the values i passed. ( i think style get 008000 ))



2) I've added the gs_layout- stylefname = 'CELLTAB'.


3) I call this method after set_table_for_first_display.

CALL METHOD go_alvgrid->set_ready_for_input

      EXPORTING

        i_ready_for_input = 1.


So my question is, did i missed anything else?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,768

Hi,

This wiki sample will help you a lot.

ALV - Editable grid control

Regards,

Jake

Howdy pros,

I've stumbled upon a problem. I want to make some of my alv cells editable.

I've build my alv with cl_gui_alv_grid. ( so no salv or function alv ).

This is exercise purpose only.

I know i can make fields of my alv editable by using my field_catalog ( field_catalog-edit = 'X' ) and it works fine with this.


But how can i use the layout to do this? ( how can i edit only one row, like when i want to add a new one and it becomes ready for input and after i save the new row it becomes unable to edit )

I've found some useful stuff but i think i'm still missing something.

1) I've added to my data_table  a new field cellstyles.

In a loop have filled the fileds

style = cl_gui_alv_grid=>mc_style_enabled

fieldname = 'FIELDNAME'

( in debuger i can see that it takes the values i passed. ( i think style get 008000 ))



2) I've added the gs_layout- stylefname = 'CELLTAB'.


3) I call this method after set_table_for_first_display.

CALL METHOD go_alvgrid->set_ready_for_input

      EXPORTING

        i_ready_for_input = 1.


So my question is, did i missed anything else?

6 REPLIES 6
Read only

dayakar_sama
Explorer
0 Likes
4,767

Hi,

The below link may help you with the very relative info. Just go through it.

http://scn.sap.com/blogs/dayakarsama/2012/06/01/oo-alv-with-check-boxes-icon-and-popup-message-to-mo...

Thanks,

sama

Read only

Former Member
0 Likes
4,769

Hi,

This wiki sample will help you a lot.

ALV - Editable grid control

Regards,

Jake

Read only

0 Likes
4,767

Yep it helped me

I found my mistake

I had my new field 'cellstyle', but when i declared my layout style a had:

gs_layout-stylefname = 'CELLTAB'.

So it could not recognize what modification i was requesting

Read only

venkateswaran_k
Active Contributor
0 Likes
4,767

You can do it in this way.. Hope it will be simple to you..

1. You add a new  column in your alv - say Status with Char(1).

2. When you display the ALV first time - This status field should have value 'X'.

3. When you add a new entry - this Status field wil be BLANK..

4. When you save. you put Status value to 'X'

In the Field catalog specification,  Put if statement....  If Status feld is NE 'X' then editable else No..

Regards,

Venkat

Read only

0 Likes
4,767

very simple idea indeed , thx but is not really what I wanted. Modifying edit from fieldcatalog just makes the entire column ready for input.

Thank you all guys for the materials. They are really helpful and i'll try to see if now i can make my program work.

Thanks,

Alexandru F

Read only

0 Likes
2,692
Editable ALV Report with Row-Based Selection Using LVC_ROWMARK
*---------------------------------------------------------------------*
* CLASS Event Handler for Double Click
*---------------------------------------------------------------------*
CLASS LCL_EVENTS DEFINITION.
PUBLIC SECTION.
METHODS:on_edit_button for EVENT user_command of CL_GUI_ALV_GRID.
ENDCLASS.

*---------------------------------------------------------------------*
* START-OF-SELECTION
*---------------------------------------------------------------------*
START-OF-SELECTION.
data(obj_lcl) = new LCL_EVENTS( ).
CALL SCREEN 200.
*---------------------------------------------------------------------*
* SCREEN 200 - Header Screen
*---------------------------------------------------------------------*
MODULE STATUS_0200 OUTPUT.
SET PF-STATUS 'ZSTANDARD'.
PERFORM LOAD_HEADER_DATA.
ENDMODULE.

MODULE USER_COMMAND_0200 INPUT.
CASE SY-UCOMM.
WHEN 'BACK'. LEAVE PROGRAM.
WHEN 'SAVE'.
PERFORM SAVE_HEADER_DATA.
WHEN 'EDIT'. " New custom function code for edit
OBJ_LCL->ON_EDIT_BUTTON( ).
ENDCASE.
ENDMODULE.

FORM LOAD_HEADER_DATA.
SELECT VBELN ERNAM ERDAT VSTEL VKORG
INTO CORRESPONDING FIELDS OF TABLE GT_LIKP
FROM ZDB_EDIT_ALV
WHERE VBELN IN S_VBELN.

PERFORM INIT_CELL_STYLES CHANGING GT_LIKP.

PERFORM BUILD_FIELDCATALOG USING GT_FCAT1 'HEADER'.

IF O_CONT1 IS INITIAL.
CREATE OBJECT O_CONT1 EXPORTING CONTAINER_NAME = 'CONTAINER1'.
CREATE OBJECT O_GRID1 EXPORTING I_PARENT = O_CONT1.

GS_LAYOUT-STYLEFNAME = 'CELLTAB'.
GS_LAYOUT-SEL_MODE = 'D'.
GS_LAYOUT-NO_TOOLBAR = 'X'.

CALL METHOD O_GRID1->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING IS_LAYOUT = GS_LAYOUT
CHANGING IT_OUTTAB = GT_LIKP
IT_FIELDCATALOG = GT_FCAT1.

SET HANDLER OBJ_LCL->ON_EDIT_BUTTON FOR O_GRID1.

ELSE.
CALL METHOD O_GRID1->REFRESH_TABLE_DISPLAY
EXPORTING IS_STABLE = VALUE LVC_S_STBL( ROW = 'X' COL = 'X' ).
ENDIF.
ENDFORM.

FORM SAVE_HEADER_DATA.
CALL METHOD O_GRID1->CHECK_CHANGED_DATA.
LOOP AT GT_LIKP INTO GS_LIKP.
UPDATE ZDB_EDIT_ALV SET
ERDAT = GS_LIKP-ERDAT
VSTEL = GS_LIKP-VSTEL
VKORG = GS_LIKP-VKORG
WHERE VBELN = GS_LIKP-VBELN AND ERNAM = GS_LIKP-ERNAM.
ENDLOOP.
COMMIT WORK.
MESSAGE 'Header data saved successfully' TYPE 'S'.
"Optional: Reset editable row
CLEAR GV_EDIT_ROW_INDEX.
ENDFORM.

*---------------------------------------------------------------------*
* Form: INIT_CELL_STYLES
*---------------------------------------------------------------------*
FORM INIT_CELL_STYLES CHANGING PT_TABLE TYPE STANDARD TABLE.
FIELD-SYMBOLS: <ROW> TYPE TY_ZDB_EDIT_ALV.

DATA: LT_DISABLED_FIELDS TYPE LVC_T_STYL,
LS_STYLE TYPE LVC_S_STYL.

CLEAR LT_DISABLED_FIELDS.

INSERT VALUE #( FIELDNAME = 'VBELN' STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED ) INTO TABLE LT_DISABLED_FIELDS.
INSERT VALUE #( FIELDNAME = 'ERNAM' STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED ) INTO TABLE LT_DISABLED_FIELDS.
INSERT VALUE #( FIELDNAME = 'ERDAT' STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED ) INTO TABLE LT_DISABLED_FIELDS.
INSERT VALUE #( FIELDNAME = 'VSTEL' STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED ) INTO TABLE LT_DISABLED_FIELDS.
INSERT VALUE #( FIELDNAME = 'VKORG' STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED ) INTO TABLE LT_DISABLED_FIELDS.

LOOP AT PT_TABLE ASSIGNING <ROW>.
<ROW>-CELLTAB = LT_DISABLED_FIELDS.
ENDLOOP.
ENDFORM.

FORM BUILD_FIELDCATALOG USING PT_FCAT TYPE LVC_T_FCAT P_TYPE.
DATA: LS_FCAT TYPE LVC_S_FCAT.

CLEAR PT_FCAT.

IF P_TYPE = 'HEADER'.
CLEAR LS_FCAT.

LS_FCAT-FIELDNAME = 'VBELN'. LS_FCAT-COLTEXT = 'Delivery'. "LS_FCAT-MARK = 'X' .
APPEND LS_FCAT TO PT_FCAT.

LS_FCAT-FIELDNAME = 'ERNAM'. LS_FCAT-COLTEXT = 'Created By'. APPEND LS_FCAT TO PT_FCAT.

LS_FCAT-FIELDNAME = 'ERDAT'. LS_FCAT-COLTEXT = 'Created On'. LS_FCAT-EDIT = 'X'. APPEND LS_FCAT TO PT_FCAT.

LS_FCAT-FIELDNAME = 'VSTEL'. LS_FCAT-COLTEXT = 'Shipping Point'. LS_FCAT-EDIT = 'X'. APPEND LS_FCAT TO PT_FCAT.

LS_FCAT-FIELDNAME = 'VKORG'. LS_FCAT-COLTEXT = 'Sales Org'. LS_FCAT-EDIT = 'X'. APPEND LS_FCAT TO PT_FCAT.

ENDFORM.

CLASS LCL_EVENTS IMPLEMENTATION.

METHOD ON_EDIT_BUTTON.
FIELD-SYMBOLS: <LS_ROW> TYPE TY_ZDB_EDIT_ALV.

DATA: LT_STYLE TYPE LVC_T_STYL,
LS_STYLE TYPE LVC_S_STYL,
LT_MARKED_ROWS TYPE LVC_T_ROW,
LS_ROW_MARK TYPE LVC_S_ROW,
lt_temp TYPE TABLE OF TY_ZDB_EDIT_ALV.

CLEAR: GV_EDIT_ROW_INDEX.

CALL METHOD O_GRID1->GET_SELECTED_ROWS
IMPORTING ET_INDEX_ROWS = LT_MARKED_ROWS.

READ TABLE LT_MARKED_ROWS INTO LS_ROW_MARK INDEX 1.
IF SY-SUBRC = 0.
GV_EDIT_ROW_INDEX = LS_ROW_MARK-INDEX.
ENDIF.
LT_TEMP = GT_LIKP.
LOOP AT LT_TEMP ASSIGNING <LS_ROW> FROM 1.
CLEAR LT_STYLE.

" Always disable primary keys
INSERT VALUE #( FIELDNAME = 'VBELN' STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED ) INTO TABLE LT_STYLE.
INSERT VALUE #( FIELDNAME = 'ERNAM' STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED ) INTO TABLE LT_STYLE.

IF SY-TABIX = GV_EDIT_ROW_INDEX.
" Selected row – enable non-primary key fields
INSERT VALUE #( FIELDNAME = 'ERDAT' STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED ) INTO TABLE LT_STYLE.
INSERT VALUE #( FIELDNAME = 'VSTEL' STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED ) INTO TABLE LT_STYLE.
INSERT VALUE #( FIELDNAME = 'VKORG' STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED ) INTO TABLE LT_STYLE.
ELSE.
" Other rows – disable all fields
INSERT VALUE #( FIELDNAME = 'ERDAT' STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED ) INTO TABLE LT_STYLE.
INSERT VALUE #( FIELDNAME = 'VSTEL' STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED ) INTO TABLE LT_STYLE.
INSERT VALUE #( FIELDNAME = 'VKORG' STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED ) INTO TABLE LT_STYLE.
ENDIF.
<LS_ROW>-CELLTAB = LT_STYLE.
MODIFY GT_LIKP FROM <LS_ROW> INDEX SY-TABIX.
ENDLOOP.

O_GRID1->REFRESH_TABLE_DISPLAY( ).

CALL METHOD O_GRID1->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING IS_LAYOUT = GS_LAYOUT
CHANGING IT_OUTTAB = GT_LIKP
IT_FIELDCATALOG = GT_FCAT1.

GS_LAYOUT-STYLEFNAME = 'CELLTAB'.
GS_LAYOUT-SEL_MODE = 'D'.
GS_LAYOUT-NO_TOOLBAR = 'X'.

ENDMETHOD.

ENDCLASS.
Editable ALV Report with Row-Based Selection Using LVC_ROWMARK
Description:
This ABAP report implements a two-screen ALV-based editable interface using CL_GUI_ALV_GRID. It features:
  • Display and editing of delivery header data from the custom table ZDB_EDIT_ALV.
  • Row-based selection using LVC_ROWMARK: Users can select a row and click the EDIT button to enable editing for non-primary key fields (ERDAT, VSTEL, VKORG) on the selected row only.
  • Primary key fields (VBELN, ERNAM) remain non-editable to ensure data integrity.
  • Editable cell behavior is controlled via the CELLTAB mechanism, dynamically applied based on user selection.
  • Toolbar function ‘EDIT’ is handled via a custom event method (ON_EDIT_BUTTON).
  • Data is updated in the database table upon clicking ‘SAVE’. Help me out this