关于SAP ABAP table control 显示数据、修改数据的问题

2024-12-02 13:23:33
推荐回答(3个)
回答1:

问题1:取内表数据你改到pbo事件中完成(显示table control前)。
目前可能你写到pai才会造成回车后才能显示数据。。。
问题2:追加modify命令
PROCESS AFTER INPUT.
*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'TBL_9000'
LOOP AT ITAB_9100.
CHAIN.
FIELD H_9100-MATNR.
FIELD H_9100-ERSDA.
MODULE TBL_9000_MODIFY ON CHAIN-REQUEST.
endchain.
ENDLOOP.
module TBL_9000_MODIFY input.
MODIFY ITAB_9100
FROM H_9100
INDEX TBL_9000-CURRENT_LINE.
endmodule. " TBL_9000_MODIFY INPUT

回答2:

TABLE CONTROL里面最初显示界面是 PBO显示的,按钮是先触发了PAI ,然后走PBO的,所以在要写在PBO里面

回答3:

主程序:

*声明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.