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: 

How to make some columns of an ALV Grid Editable?

Former Member
0 Kudos

hi!

I have a gt_itab that is displayed by an ALV Grid with FM.

I want to make some columns of ALV Gridi editable and finally want to save the modified gt_itab to a database table.

How can I do that ?

thanks.

4 REPLIES 4

Sandeep_Kumar
Product and Topic Expert
Product and Topic Expert
0 Kudos

check this demo program : BCALV_EDIT_02

Former Member

Hi

You can make some caolums of the alv grid using Field catalog.You can use the Edit parametere of field catalog to have the particular column editable.

Sample code:

DATA : C_CHECK TYPE C VALUE 'X'.

DATA : I_FCAT TYPE SLIS_T_FIELDCAT_ALV,
       wa_fcat TYPE SLIS_FIELDCAT_ALV.

LOOP AT I_FCAT INTO WA_FCAT.
  if ( wa_fcat-fieldname = 'MATNR' ).
  WA_FCAT-EDIT = C_CHECK.
  ENDIF.
  MODIFY i_fcat  FROM wa_fcat TRANSPORTING edit .
  ENDLOOP.

Thanks!!

RJ

Former Member
0 Kudos

Hi,

You can easily search this thing in SDN.

Please go through these links.

They have very good description for each and every step.

http://wiki.sdn.sap.com/wiki/display/Snippets/ALV-Editingandsavingtheeditedvaluesin+Database(OOPS)

http://wiki.sdn.sap.com/wiki/display/Snippets/ASimpleProgramforEditableALVgrid+control

May it helps you.

Regards.

DS.

Former Member

Hi,

For making the ALV grid editable, there is an attribute called 'edit' for field catalogue. This should be supplied with 'X' while creating the field catalogue.


data: gi_header type lvc_t_fcat,
        wa_header type lvc_s_fcat.
data: gv_grid type ref to cl_gui_alv_grid.
  clear wa_header.
  n = n + 1.
  wa_header-fieldname = 'DBGNO'. "'DD/BG No.'.
  wa_header-coltext = 'DD/BG No.'.
  wa_header-inttype = 'C'.
  WA_HEADER-EDIT = 'X'.
  wa_header-row_pos = '0'.
  wa_header-col_pos = n."9
  append wa_header to gi_header[].

The grid can be displayed using the followin code

        call method gv_grid->set_ready_for_input
          exporting
            i_ready_for_input = 1.

        call method gv_grid->set_table_for_first_display
          exporting
            it_toolbar_excluding          = lt_exclude
          changing
            it_outtab                     = gi_output
            it_fieldcatalog               = gi_header
          exceptions
            invalid_parameter_combination = 1
            program_error                 = 2
            too_many_lines                = 3
            others                        = 4.
        if sy-subrc <> 0.
*      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        endif.

The above sample will take care of making a column in the alv grid editable.

Now, coming to ur second question, to get the modified the data from the grid, cl_gui_alv_grid has an event called 'data changed'. It has a parameter called 'ER_DATA_CHANGED' This parameter contains all the data changed in the grid. Thus u can get the changed data from the grid and update any database table or do further processing.

Thanks and Regards,

Avinash Bolisetty