Application Development 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: 

CL_GUI_ALV_GRID Editable Cell.

Former Member
0 Kudos
5,338

Hi,

I have create a fieldcatalog at runtime and used CALL METHOD cl_alv_table_create=>create_dynamic_table to create a dynamic internal table and used CALL METHOD grid1->set_table_for_first_display to display the alv in the Custom Containner.

I have 2 collums of the ALV as non-editable in the fieldcatalog.

Now my requirement is that i want to get the new row as editable by pressing the Create button on the ALV Toolbar.When i press this button then a new empty record gets inserted at the end of the table but those 2 collums are comming as non-editable whereas i want them as editable.

So how to achive this thing.

And secondly how to make the newly created record cell as mandatory(Required) field in the ALV.

Thanks

3 REPLIES 3

Former Member
0 Kudos
174

To control the edit/no edit conditions on a specific row, you will need to make use of CELLSTYLES.

This link gives very good directions.

http://www.abap4.it/download/ALV.pdf

This is an example of setting up the CELLSTYLES


DATA: BEGIN OF gt_outtab OCCURS 0.
        INCLUDE STRUCTURE zscemp_wk.
DATA: cellstyles    TYPE lvc_t_styl.
DATA: END OF gt_outtab.

And my code setting edit/no edit


*&---------------------------------------------------------------------*
*&      Form  adjust_editables
*&---------------------------------------------------------------------*
FORM adjust_editables USING    pt_list LIKE gt_outtab[].
  DATA: ls_listrow  LIKE LINE OF pt_list.
  DATA: ls_stylerow TYPE lvc_s_styl.
  DATA: ls_styletab TYPE lvc_t_styl.

  LOOP AT pt_list INTO ls_listrow.
    REFRESH ls_listrow-cellstyles.
    REFRESH ls_styletab.

    IF edit_mode EQ 'D'.
      ls_stylerow-fieldname = 'BRANCH'.
      ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
      APPEND ls_stylerow TO ls_styletab.
    ENDIF.

    ls_stylerow-fieldname = 'EMPNO'.
    IF  ls_listrow-empno IS INITIAL
    AND edit_mode EQ 'E'.
      ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.
    ELSE.
      ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
    ENDIF.
    APPEND ls_stylerow TO ls_styletab.

    INSERT LINES OF ls_styletab INTO TABLE ls_listrow-cellstyles.

    MODIFY pt_list FROM ls_listrow.
  ENDLOOP.

ENDFORM.                    " adjust_editables

Requiring the fields to be Mandatory, will be taken care of in your edit routines.

former_member194669
Active Contributor
0 Kudos
174

Call this method after set table first display


  call method g_grid->set_ready_for_input
    exporting
      i_ready_for_input = '1'.

for required check you can use event AFTER_USER_COMMAND

Former Member
0 Kudos
174

Hi,

Thanks for the Solution.But my problem is that i have a internal table created from the fieldcatalog.ie:

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_field_catalog

IMPORTING

ep_table = p_new_table.

where p_new_table type ref to data.

so how to add the the above include of the style structure in p_new_table.

Thanks