Skip to Content
author's profile photo Former Member
Former Member

ALV GRID insert delete row


i want to add / delete rows in an alv grid.I found BCALV_EDIT_04.but it is very complicated.can u tell me how can i do this?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 05, 2008 at 06:37 PM

    Check this blog..




    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2008 at 04:23 AM

    Hi burc,

    Check this simple code.

    ****To identify the selected records to delete declare a field

    ****flag to layout

    gs_layout-box_fieldname = 'FLAG'.



    i_callback_program = ws_repid

    i_callback_pf_status_set = 'GUI_STAT'

    i_callback_user_command = 'STAT'

    is_layout = gs_layout

    it_fieldcat = i_fieldcat[]


    t_outtab = i_zaw_pol_plan.

    IF sy-subrc <> 0.



    ENDFORM. " change_data

    **--Setting Status of outout screen

    FORM gui_stat USING rt_extab TYPE slis_t_extab.

    ****In your PF status add button Delete


    SET TITLEBAR text-005.


    **--Calling the subroutine when button clicked on output

    FORM stat USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.

    DATA selfield TYPE slis_selfield.

    CASE r_ucomm.

    **--When Delete Button Pressed

    WHEN 'DELE'.

    LOOP AT internal table WHERE flag EQ c_x.

    DELETE the record from internal table or database



    ADD also same when press add button insert the records in internal table or database tables and refresh the output layout screen.

    to refresh the screen aftyer adding or deleting write below code.

    DATA ref1 TYPE REF TO cl_gui_alv_grid.



    e_grid = ref1.

    CALL METHOD ref1->check_changed_data.

    CALL METHOD ref1->refresh_table_display.

    Don't forget to reward if useful....



    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2008 at 01:20 PM

    Hi Guys

    Why do you insist on using Dinosaur Technology (the old way) for ALV grids

    The real SIMPLE way using the new cl_gui_alv_grid class is simply to display your table in EDIT mode; You'll then see on a standard toolbar the Insert / delete lines.

    You don't need to do any special coding or event handling.

    This also ensures the Grid is EDITABLE.

    Here's a simple program that does just this. It reads 200 entries from VAPMA and displays them in an editable grid.

    It will work for almost any structure as it builds a dynamic FCAT and Dynamic table.

    Ensure you have a simple screen (100) with just a custom control on it called CCONTAINER1 and a simple ststus (SE41) with BACK EXIT and CANCEL buttons on it.

    Here's the code

    * Define any structure
    types:  begin of s_elements,
      vbeln   type vapma-vbeln,
      posnr   type vapma-posnr,
      matnr   type vapma-matnr,
      kunnr   type vapma-kunnr,
      werks   type vapma-werks,
      vkorg   type vapma-vkorg,
      vkbur   type vapma-vkbur,
      status  type c,
    end of  s_elements.
    * end of your structure
    tables: vapma.
    data lr_rtti_struc type ref to cl_abap_structdescr .
        zog                     like line of lr_rtti_struc->components .
        zogt                    like table of zog,
      wa_it_fldcat type lvc_s_fcat,
      it_fldcat type lvc_t_fcat ,
      dy_line            type ref to data,
      dy_table           type ref to data.
     data:  dref               type ref to data.
     field-symbols: <fs> type any,
        <dyn_table>    type  standard table,
    data grid_container1 type ref to cl_gui_custom_container .
      data grid1 type ref to cl_gui_alv_grid .
    data: ok_code type sy-ucomm.
    data: STRUCT_GRID_LSET type lvc_s_layo.
    *now I want to build a field catalog
    * First get your data structure into a field symbol
    create data dref type s_elements.
      assign dref->* to <fs>.
      lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( <fs> ).
        zogt[]  = lr_rtti_struc->components.
     loop at zogt into zog.
          clear wa_it_fldcat.
          wa_it_fldcat-fieldname = zog-name .
          wa_it_fldcat-datatype = zog-type_kind.
          wa_it_fldcat-inttype = zog-type_kind.
          wa_it_fldcat-intlen = zog-length.
          wa_it_fldcat-decimals = zog-decimals.
          wa_it_fldcat-coltext = zog-name.
          wa_it_fldcat-lowercase = 'X'.
          append wa_it_fldcat to it_fldcat .
    * Let's create a dynamic table and populate it
    call method cl_alv_table_create=>create_dynamic_table
                it_fieldcatalog = it_fldcat
                ep_table = dy_table.
    assign dy_table->* to <dyn_table>.
      create data dy_line like line of <dyn_table>.
      assign dy_line->* to <dyn_wa>.
    * Fill the dynamic table
      select vbeln posnr matnr kunnr werks vkorg vkbur
             up to 200 rows
             from vapma
             into  corresponding fields of table <dyn_table>.
    * display grid via screen call.
    call screen 100.
    module status_0100 output.
    if grid_container1 is initial.
    create object grid_container1
               container_name = 'CCONTAINER1'.
        create object  grid1
              i_parent = grid_container1.
      struct_grid_lset-edit = 'X'.    "To enable editing in ALV
    call method grid1->set_table_for_first_display
      exporting is_layout =  struct_grid_lset
                 it_outtab       = <dyn_table>
                 it_fieldcatalog = it_fldcat.
    set pf-status '001'.
         set titlebar '000'.
      MODULE user_command_0100 INPUT.
          case sy-ucomm.
        when 'BACK'.
          leave program.
        when 'EXIT'.
          leave program.
        when 'RETURN'.
          leave program.
        when others.

    I don't want to see any more of the old Dinosaur SLIS type of function module calls.

    If you now ever need to take take longer than 5 mins to code simple ALV grids then please re-read this post as it is completely general for around 99.99% of SIMPLE Grids (not Trees or complicated data handling).

    This should show you the principle easily enough.



    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2008 at 05:58 AM

    Hi burc,

    If you are using classes for ALV...

    use method

    CALL METHOD grid->set_toolbar_interactive. -- where

    grid TYPE REF TO cl_gui_alv_grid, (This you should have already defined for creating grid)..



    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2008 at 06:00 AM

    Additionally, to copy any changes to your internal table... use method

    CALL METHOD grid->check_changed_data. in your PAI.

    I forgot to mention in my previous response.


    CALL METHOD grid->set_toolbar_interactive. -- in your PBO..

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.