Skip to Content
0
Former Member
Mar 03, 2008 at 07:16 AM

Delete from db table using alv

16 Views

Hi ,

I am trying to select row from alv and delete them from custom table zrrmm02. structure zrrmm02 and i_d_wa is same. But this below code is not working. pls suggest.

REPORT zrralvcontrol .

TABLES: zrrmm02.

TYPE-POOLS: slis.

DATA: BEGIN OF itab OCCURS 0,
      box(1)  TYPE c,
      matnr LIKE zrrmm02-matnr,
      werks LIKE zrrmm02-werks,
      ersda LIKE zrrmm02-ersda,
      timestamp LIKE zrrmm02-timestamp,
      oldval LIKE zrrmm02-oldval,
      newval LIKE zrrmm02-newval,
      msg LIKE zrrmm02-msg,
      END OF itab,

      BEGIN OF i_d_wa,
      matnr LIKE zrrmm02-matnr,
      werks LIKE zrrmm02-werks,
      ersda LIKE zrrmm02-ersda,
      timestamp LIKE zrrmm02-timestamp,
      oldval LIKE zrrmm02-oldval,
      newval LIKE zrrmm02-newval,
      msg LIKE zrrmm02-msg,
      END OF i_d_wa,

      g_t_fieldcat TYPE slis_t_fieldcat_alv,
       g_r_fieldcat LIKE LINE OF g_t_fieldcat.

START-OF-SELECTION.

  SELECT * FROM zrrmm02 INTO CORRESPONDING FIELDS OF TABLE itab.
  PERFORM display_data.

END-OF-SELECTION.

*---------------------------------------------------------------------*
*       FORM display_data                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM display_data.
  DATA: l_f_repid LIKE sy-repid,
         l_r_layout TYPE slis_layout_alv.

  l_f_repid = sy-repid.
  l_r_layout-zebra = 'X'.
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
       EXPORTING
            i_program_name         = l_f_repid
            i_internal_tabname     = 'ITAB'
            i_client_never_display = 'X'
            i_inclname             = l_f_repid
       CHANGING
            ct_fieldcat            = g_t_fieldcat.

  LOOP AT g_t_fieldcat INTO g_r_fieldcat.
    CASE g_r_fieldcat-fieldname.
      WHEN 'BOX'.
        g_r_fieldcat-checkbox = 'X'.
        g_r_fieldcat-col_pos = 0.
        g_r_fieldcat-seltext_m = 'Check'.
        g_r_fieldcat-seltext_l = 'Check'.
        g_r_fieldcat-edit = 'X'.
      WHEN 'WERKS'.
        g_r_fieldcat-seltext_l =
        g_r_fieldcat-seltext_m =
        g_r_fieldcat-seltext_s =
        g_r_fieldcat-reptext_ddic = 'WERKS'.
      WHEN 'ERSDA'.
        g_r_fieldcat-seltext_l =
        g_r_fieldcat-seltext_m =
        g_r_fieldcat-seltext_s =
        g_r_fieldcat-reptext_ddic = 'DATE'.
      WHEN 'TIMESTAMP'.
        g_r_fieldcat-seltext_l =
        g_r_fieldcat-seltext_m =
        g_r_fieldcat-seltext_s =
        g_r_fieldcat-reptext_ddic = 'TIME'.
        g_r_fieldcat-edit = 'X'.
      WHEN 'NEWVAL'.
        g_r_fieldcat-seltext_l =
        g_r_fieldcat-seltext_m =
        g_r_fieldcat-seltext_s =
        g_r_fieldcat-reptext_ddic = 'New Value'.
      WHEN 'OLDVAL'.
        g_r_fieldcat-seltext_l =
        g_r_fieldcat-seltext_m =
        g_r_fieldcat-seltext_s =
        g_r_fieldcat-reptext_ddic = 'Old Value'.
      WHEN 'MSG'.
        g_r_fieldcat-seltext_l =
          g_r_fieldcat-seltext_m =
          g_r_fieldcat-seltext_s =
          g_r_fieldcat-reptext_ddic = 'Message'.

    ENDCASE.
    MODIFY g_t_fieldcat FROM g_r_fieldcat.
    CLEAR g_r_fieldcat.

  ENDLOOP.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            i_callback_program       = l_f_repid
            is_layout                = l_r_layout
            i_callback_pf_status_set = 'SET_PF_STATUS'
            i_callback_user_command  = 'USER_COMMAND'
            i_save                   = 'X'
            it_fieldcat              = g_t_fieldcat
       TABLES
            t_outtab                 = itab[]
       EXCEPTIONS
            program_error            = 1
            OTHERS                   = 2.

ENDFORM.

*---------------------------------------------------------------------*
*       FORM set_pf_status                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM set_pf_status USING extab TYPE slis_t_extab.
  SET PF-STATUS 'SET_PF_STATUS'.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM user_command                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  UCOMM                                                         *
*  -->  SEL_FIELD                                                     *
*---------------------------------------------------------------------*
FORM user_command USING ucomm LIKE sy-ucomm
               sel_field TYPE slis_selfield.
  CASE ucomm.
    WHEN 'SALL'.
      LOOP AT itab.
        itab-box = 'X'.
        MODIFY itab.
        CLEAR itab.
      ENDLOOP.
      sel_field-refresh = 'X'.
    WHEN 'DALL' .
      LOOP AT itab.
        itab-box = ' '.
        MODIFY itab.
        CLEAR itab.
      ENDLOOP.
      sel_field-refresh = 'X'.
    WHEN 'DELETE'.
      LOOP AT itab WHERE box = 'X'.
*        i_d_wa-matnr = itab-matnr.
*        i_d_wa-werks = itab-werks.
*        i_d_wa-ersda = itab-ersda.
*        i_d_wa-timestamp = itab-timestamp.
*        i_d_wa-oldval = itab-oldval.
*        i_d_wa-newval = itab-newval.
*        i_d_wa-msg = itab-msg.
        MOVE-corresponding itab to i_d_wa.
        DELETE  zrrmm02  FROM i_d_wa.
        CLEAR i_d_wa.
      ENDLOOP.
  ENDCASE.
ENDFORM.