原文出自: http://blog.chinaunix.net/uid-8527621-id-2029501.html
REPORT z_barry_tc_f4 .
CONTROLS: tc01 TYPE TABLEVIEW USING SCREEN 0100.
TYPES: BEGIN OF ty_itab,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
END OF ty_itab.
DATA: itab TYPE TABLE OF ty_itab ,
wa TYPE ty_itab .
DATA: progname TYPE sy-repid,
dynnum TYPE sy-dynnr,
dynpro_values TYPE TABLE OF dynpread,
field_value LIKE LINE OF dynpro_values .
DATA: ok_code LIKE sy-ucomm.
START-OF-SELECTION.
wa-carrid = 'A01'.
wa-connid = '0001'.
APPEND wa TO itab.
CALL SCREEN 100.
*---------------------------------------------------------------------*
* MODULE TC01_change_tc_attr OUTPUT *
*---------------------------------------------------------------------*
MODULE tc01_change_tc_attr OUTPUT.
DESCRIBE TABLE itab LINES tc01-lines.
ENDMODULE.
*---------------------------------------------------------------------*
* MODULE TC01_modify INPUT *
*---------------------------------------------------------------------*
MODULE tc01_modify INPUT.
READ TABLE itab INTO wa INDEX tc01-current_line
TRANSPORTING NO FIELDS .
IF sy-subrc = 0 .
MODIFY itab FROM wa INDEX tc01-current_line.
ELSE.
INSERT wa INTO itab INDEX tc01-current_line.
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module status_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'MAIN100'.
progname = sy-repid.
dynnum = sy-dynnr.
ENDMODULE. " status_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'BACK'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module showf4 INPUT
*&---------------------------------------------------------------------*
MODULE showf4 INPUT.
DATA: l_selline LIKE sy-stepl,
d_values TYPE TABLE OF dynpread,
f_value LIKE LINE OF dynpro_values .
DATA: tmpitab LIKE itab.
CLEAR tmpitab.
GET CURSOR LINE l_selline.
CALL FUNCTION 'DYNP_VALUES_READ' "获取屏幕字段
EXPORTING
dyname = progname
dynumb = dynnum
request = 'A'
TABLES
dynpfields = d_values.
READ TABLE d_values INTO f_value
WITH KEY fieldname = 'WA-CARRID'
stepl = l_selline.
SELECT carrid connid
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE tmpitab
WHERE carrid = f_value-fieldvalue.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'CONNID'
dynpprog = progname
dynpnr = dynnum
dynprofield = 'CONNECTION'
value_org = 'S'
TABLES
value_tab = tmpitab.
ENDMODULE. " showf4 INPUT
***************
PROCESS BEFORE OUTPUT.
MODULE status_0100.
MODULE tc01_change_tc_attr.
LOOP AT itab
INTO wa
WITH CONTROL tc01
CURSOR tc01-current_line.
ENDLOOP.
PROCESS AFTER INPUT.
MODULE user_command_0100.
LOOP AT itab.
CHAIN.
FIELD wa-carrid.
FIELD wa-connid.
MODULE tc01_modify ON CHAIN-REQUEST.
ENDCHAIN.
ENDLOOP.
PROCESS ON VALUE-REQUEST.
FIELD wa-connid MODULE showf4.