ABAP--如何使用REUSE_ALV_GRID_DISPLAY函数删除内表数据(样例代码,感谢依风提供)

请注意程序中的五处红色标记的代码,其他代码请用户自己按自己的需要进行修改

*&---------------------------------------------------------*
*& REPORT CREATE TRANSFER                                  *
*&---------------------------------------------------------*
*& Create date       : 2007/06/21                          *
*& Program type      : Report                              *
*&---------------------------------------------------------*
*& Modifications :                                         *
*& Date      | Programmer |Change request | Description    *
*&                                                         *
*&-------------------------------------------------------- *
REPORT zsdpr_yfdj MESSAGE-ID zmc01 NO STANDARD PAGE HEADING LINE-SIZE 500.
************************************************************
*  TABLES
************************************************************
TABLES : zadtb_yf.

TYPE-POOLS: slis.
************************************************************
*INTERNAL TABLE DEFINITION
************************************************************
DATA: BEGIN OF gs_it,
        lfdat(10),
        vbeln(50),
        zstation(20),
      END OF gs_it.
DATA : gt_it  LIKE gs_it   OCCURS 0 WITH HEADER LINE.
DATA : gt_itab LIKE zadtb_yf OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF gs_yf  OCCURS 0 .
*1内表增加一个选中字段
DATA:  gv_check TYPE c.
       INCLUDE TYPE zadtb_yf.
DATA: END OF gs_yf.

DATA : gt_yf   LIKE gs_yf OCCURS 0 WITH HEADER LINE.
************************************************************
* Variable  DEFINITION
***********************************************************
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      gs_layout   TYPE slis_layout_alv,
      usercommand TYPE slis_fieldname VALUE 'USERCOMMAND',
      gt_sort     TYPE slis_t_sortinfo_alv.
DATA: progname    LIKE sy-repid,
      title(70).
DATA : gv_cancel(1) TYPE c,
       gv_flag TYPE i.
************************************************************
* SELECTION-SCREEN
************************************************************
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-bl1.
SELECTION-SCREEN SKIP 1.
SELECT-OPTIONS:
           so_lfdat     FOR zadtb_yf-lfdat,"提货日期
           so_vbeln     FOR zadtb_yf-vbeln,"销售凭证
           so_erdat     FOR zadtb_yf-erdat."录入日期
SELECTION-SCREEN END OF BLOCK bl1.
SELECTION-SCREEN BEGIN OF BLOCK bl3 WITH FRAME TITLE text-bl3.
PARAMETERS: pa_z2 RADIOBUTTON GROUP pa2 ."删除
SELECTION-SCREEN SKIP 1 .
SELECTION-SCREEN END OF BLOCK bl3.
***********************************************************
* START OF  SELECTION
***********************************************************
START-OF-SELECTION.
    PERFORM get_date.
END-OF-SELECTION.
    PERFORM output_date.
*&---------------------------------------------------------------------*
*&      Form  GET_DATE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_date .
  SELECT *
       INTO CORRESPONDING FIELDS OF TABLE gt_yf
       FROM zadtb_yf
       WHERE  lfdat IN   so_lfdat  "提货日期
       AND    vbeln IN   so_vbeln  "销售凭证
       AND    erdat IN  so_erdat.  "录入日期
ENDFORM.                    " GET_DATE
*&---------------------------------------------------------------------*
*&      Form  OUTPUT_DATE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM output_date .
  REFRESH  gt_fieldcat.
  progname = sy-repid.
  title = '运费查询及信息删除'.

  gs_layout-zebra  = 'X'.            "设置每行的背景颜色交错 显示。
  gs_layout-colwidth_optimize = 'X'.  "ALV输出时候自动优化宽 度
  gs_layout-detail_popup    = 'X'.

*2此处代码设置屏幕的chekbox选中字段
 gt_fieldcat-fieldname = 'GV_CHECK'.
  gt_fieldcat-seltext_m  = '选择'.
  gt_fieldcat-outputlen = 1.
  gt_fieldcat-checkbox = 'X'.
  gt_fieldcat-input = 'X'.
  gt_fieldcat-edit = 'X'.
  APPEND gt_fieldcat.
  CLEAR gt_fieldcat.

 gt_fieldcat-fieldname = 'LFDAT'.
  gt_fieldcat-seltext_m  = '提货日期'.
  gt_fieldcat-outputlen = 10.
  APPEND gt_fieldcat.
  CLEAR gt_fieldcat.

  gt_fieldcat-fieldname = 'VBELN'.
  gt_fieldcat-seltext_m  = '销售凭证'.
  gt_fieldcat-outputlen = 50.
  APPEND gt_fieldcat.
  CLEAR gt_fieldcat.

  gt_fieldcat-fieldname = 'ZSTATION'.
  gt_fieldcat-seltext_m  = '到站'.
  gt_fieldcat-outputlen = 20.
  APPEND gt_fieldcat.
  CLEAR gt_fieldcat.

*3设置处理代码
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = progname
      is_layout                = gs_layout
      it_fieldcat              = gt_fieldcat[]
     i_grid_title             = title
      i_callback_pf_status_set = 'PF_STATUS_SET'
      i_callback_user_command  =  usercommand
*      i_save                  = 'A'
    TABLES
      t_outtab                 = gt_yf
    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.                    " OUTPUT_DATE
*&---------------------------------------------------------------------*
*&      FORM user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM usercommand USING ucomm TYPE sy-ucomm
                    selfield TYPE slis_selfield.
  DATA: lr_grid TYPE REF TO cl_gui_alv_grid.

*4此处代码将用户输入读入内表(这一步不可少)
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = lr_grid.
  CALL METHOD lr_grid->check_changed_data.

*5此处代码阻止'REUSE_ALV_GRID_DISPLAY创建新的屏幕,造成屏幕多层
  selfield-refresh = 'X'.
  CASE sy-ucomm.
    WHEN 'DELE'.
      CLEAR  sy-ucomm.
      LOOP AT gt_yf.
        IF gt_yf-gv_check = 'X'.
*请填写删除操作
           DELETE gt_yf.
        ENDIF.
      ENDLOOP.
  ENDCASE.
ENDFORM.                    "USER_COMMAND
*&---------------------------------------------------------------------*
*&      FORM PF_STATUS_SET
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM pf_status_set USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'YFDJ'  .
ENDFORM.                    "frm_PF_STATUS_SET 

posted on 2007-06-30 09:19  毛小娃  阅读(299)  评论(0编辑  收藏  举报

导航