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