table control的修改/排序/刪除功能實現例項
阿新 • • 發佈:2019-01-08
本例項仿照SAP DEMO而寫 DEMO名稱是:demo_dynpro_tabcont_loop_at,自動動手寫一次的目的是把將該程式的註釋寫明白一點,希望本文對剛入門的博友在理解table control有一點幫助,依然很噁心這編輯器不能很方便的插入圖片。
主程式:
*宣告table control裡面表控制元件使用的結構
TABLES demo_conn.
*宣告table control
CONTROLS sflight TYPE TABLEVIEW USING SCREEN 100.
*定義control cols表的行工作區
DATA col LIKE LINE OF sflight-cols.
*定義一個整型變數用來儲存內錶行數
DATA fill TYPE i.
*定義內表用來填充control的table
DATA itab TYPE STANDARD TABLE OF demo_conn.
*定義OK_CODE 儲存ftcode
DATA ok_code TYPE sy-ucomm.
DATA ok_save TYPE sy-ucomm.
*---------------------------------------------------------*
*Event blocks *
*---------------------------------------------------------*
*start-of-selection event---------------------------------
START-OF-SELECTION.
*獲取資料
SELECT *
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE itab.
*取得內錶行數
DESCRIBE TABLE itab LINES fill.
*初始化table control的行數
sflight-lines = fill.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* 設定選單 工具 欄
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_001'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module MODIFY_CT INPUT
*&---------------------------------------------------------------------*
* 更新內表
*----------------------------------------------------------------------*
MODULE modify_ct INPUT.
MODIFY itab FROM demo_conn INDEX sflight-current_line.
ENDMODULE. " MODIFY_CT INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* 處理那些按鈕事件
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
ok_save = ok_code.
CLEAR ok_code.
CASE ok_save.
WHEN 'CHANGE'.
*當點選修改按鈕,此時要需要修改control cols的input屬性(cols包含所有列相關資訊)
LOOP AT sflight-cols INTO col WHERE index GT 2.
IF col-screen-input EQ '1'.
col-screen-input = '0'.
modify sflight-cols from col index sy-tabix.
ELSEIF col-screen-input EQ '0'.
col-screen-input = '1'.
modify sflight-cols from col index sy-tabix.
ELSE.
ENDIF.
ENDLOOP.
*當點選sort_down按鈕,此時需要對內錶針對選中的地列進行排序
WHEN 'SORT_DOWN'.
READ TABLE sflight-cols INTO col WITH KEY selected = 'X'.
IF sy-subrc = 0.
SORT itab BY (col-screen-name+10) DESCENDING.
col-selected = ''.
MODIFY sflight-cols FROM col INDEX sy-tabix.
ENDIF.
*當點選sort_up按鈕。。。。 。。。
WHEN 'SORT_UP'.
READ TABLE sflight-cols INTO col WITH KEY selected = 'X'.
IF sy-subrc = 0.
SORT itab BY (col-screen-name+10) ASCENDING.
col-selected = ''.
MODIFY sflight-cols FROM col INDEX sy-tabix.
ENDIF.
*當點選刪除按鈕,此時需要更新內表
WHEN 'DELETE'.
READ TABLE sflight-cols INTO col WITH KEY screen-input = '1'.
IF sy-subrc = 0.
LOOP AT itab INTO demo_conn WHERE mark = 'X'.
DELETE itab INDEX sy-tabix.
ENDLOOP.
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module READ_DATA OUTPUT
*&---------------------------------------------------------------------*
* 讀取內表資料
*----------------------------------------------------------------------*
MODULE read_data OUTPUT.
READ TABLE itab INTO demo_conn INDEX sflight-current_line.
ENDMODULE. " READ_DATA OUTPUT
*&---------------------------------------------------------------------*
*& Module CANCEL INPUT
*&---------------------------------------------------------------------*
* 強制退出
*----------------------------------------------------------------------*
MODULE cancel INPUT.
LEAVE PROGRAM.
ENDMODULE. " CANCEL INPUT
螢幕邏輯流:
PROCESS BEFORE OUTPUT.
MODULE status_0100.
LOOP WITH CONTROL sflight.
MODULE read_data.
ENDLOOP.
PROCESS AFTER INPUT.
MODULE cancel AT EXIT-COMMAND.
LOOP WITH CONTROL sflight.
MODULE modify_ct.
ENDLOOP.
MODULE user_command_0100.