5 Replies Latest reply: Aug 9, 2007 8:57 AM by Walter Tighzert RSS

Deleting records from ALV grid

Sriram S
Currently Being Moderated

Hi,

I have small requirement..

I am displaying values using alv grid ... each records have one check box.

i want delete records wch are selected by using checkbox.

For example: if i select 3 records(i marked 3 records in 3 checkboxes for 3 records)..

After press Delete button on Applocation toolbar . i want to delte those 3 records from our internal table...

i am deleting records but it is deleted the last records(based on index)...

hw can i delete more than 1 records at single time...

 

Please help me for this issue...

  • Re: Deleting records from ALV grid
    Walter Tighzert
    Currently Being Moderated

    Hello,

    Check programm BCALV_EDIT_04: it explains how to delete selected rows in an ALV grid.

    Regards,

    walter

  • Re: Deleting records from ALV grid
    Mahesh Kumar Raganmoni
    Currently Being Moderated

    Hi,

     

      You might be using this logic in the user command subroutine.

     

        when 'DELE'   " When Deleted

        delete itab where chkbox eq 'x'.

        call the reuse_alv_list_display.

     

    Thanks

    Mahesh

  • Re: Deleting records from ALV grid
    Sudheer Junnuthula
    Currently Being Moderated

    Hi,

    look at the demo program BCALV_EDIT_04 to delete the records and Append the records

     

     

     

    regards

    Sudheer

  • Re: Deleting records from ALV grid
    Rinzy Deena Mathews
    Currently Being Moderated

    Hi Sri,

     

    Kindly find the following code:

    Hope this may help you.

     

    TYPE-POOLS : slis.

     

    TYPES : BEGIN         OF ty_final,

              check       TYPE char01,

              vbeln           TYPE vbeln_va,

              posnr           TYPE posnr_va,

              matnr           TYPE matnr,

              arktx           TYPE arktx,

              kwmeng      TYPE kwmeng,

              vrkme           TYPE vrkme,

              netwr           TYPE netwr_ap,

           END            OF ty_final.

     

    DATA : t_vbap         TYPE STANDARD TABLE OF zvbap,

           t_final        TYPE STANDARD TABLE OF ty_final,

           t_hfcatalog    TYPE slis_t_fieldcat_alv.

     

    DATA : x_final        TYPE ty_final,

           x_vbap         TYPE zvbap,

           x_hfcatalog    TYPE slis_fieldcat_alv.

     

     

    SELECT *

           INTO CORRESPONDING FIELDS OF TABLE t_final

           FROM zvbap

           UP TO 50 ROWS.

     

    PERFORM build_fieldcatalog USING : 'CHECK'  ' ',

                                      'VBELN' 'Sales Document',

                                      'POSNR'  'Sales Document Item',

                                      'MATNR'  'Material Number',

                                      'ARKTX'  'Short text for sales order item',

                                      'KWMENG' 'Cumulative Order Quantity',

                                      'VRKME'  'Sales unit',

                                      'NETWR'  'Net value'.

     

    PERFORM display_alv.

    &----


    *&      Form  BUILD_FIELDCATALOG

    &----


    •       Build Field Catalog

    ----


    •      -->P_0089   Field Name

    •      -->P_0090   Field Text

    ----


    FORM build_fieldcatalog  USING    value(p_0089)

                                      value(p_0090).

     

      IF p_0089 EQ 'CHECK'.

        x_hfcatalog-fieldname     = p_0089.

        x_hfcatalog-tabname = 'T_FINAL'.

        x_hfcatalog-seltext_l     = p_0090.

        x_hfcatalog-checkbox      = 'X'.

        x_hfcatalog-edit = 'X'.

        x_hfcatalog-outputlen = 3.

        x_hfcatalog-just = ' '.

        APPEND x_hfcatalog TO t_hfcatalog.

      ELSE.

        x_hfcatalog-fieldname     = p_0089.

        x_hfcatalog-tabname = 'T_FINAL'.

        x_hfcatalog-seltext_l     = p_0090.

        x_hfcatalog-checkbox      = ' '.

        x_hfcatalog-edit = 'X'.

        IF p_0089 NE 'ARKTX'.

          x_hfcatalog-outputlen = 15.

        ELSE.

          x_hfcatalog-outputlen = 30.

        ENDIF.

        x_hfcatalog-just = ' '.

        APPEND x_hfcatalog TO t_hfcatalog.

      ENDIF.

     

     

    ENDFORM.                    " BUILD_FIELDCATALOG

     

    &----


    *&      Form  user_command

    &----


    •       User Command

    ----


    •      -->R_UCOMM      text

    •      -->RS_SELFIELD  text

    ----


    FORM user_command  USING r_ucomm LIKE sy-ucomm

                                       rs_selfield TYPE slis_selfield.

       

      DATA ref1 TYPE REF TO cl_gui_alv_grid.

      CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

        IMPORTING

          e_grid = ref1.

      CALL METHOD ref1->check_changed_data.

     

      CASE r_ucomm.

        WHEN 'DELETE'.

          LOOP AT t_final INTO x_final.

            READ TABLE t_final INTO x_final WITH KEY check = 'X'.

            IF sy-subrc EQ 0.

              DELETE TABLE t_final FROM x_final.

            ENDIF.

          ENDLOOP.

      ENDCASE.

     

      CALL METHOD ref1->refresh_table_display.

     

    ENDFORM.                    "user_command

     

    &----


    *&      Form  set_pf_status

    &----


    •       Set PF Status

    ----


    •      -->RT_EXTAB   text

    ----


    FORM set_pf_status USING rt_extab TYPE slis_t_extab.

      SET PF-STATUS 'ZSTANDARD' .

    ENDFORM.                    "set_pf_status

    &----


    *&      Form  DISPLAY_ALV

    &----


    •       Display ALV

    ----


    FORM display_alv .

     

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

       i_callback_program                = sy-repid

       i_callback_pf_status_set          = 'SET_PF_STATUS'

       i_callback_user_command           = 'USER_COMMAND'

       it_fieldcat                       = t_hfcatalog

      TABLES

        t_outtab                          = t_final

    EXCEPTIONS

       program_error                     = 1

       OTHERS                            = 2

              .

      IF sy-subrc <> 0.

        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

      ENDIF.

     

    ENDFORM.                    " DISPLAY_ALV

     

    Thanks and regards

    Rinzy Deena Mathews

Actions