SAP ABAP table control中用帮助(F4)实现自动填充另一字段教程
最近在和一个朋友的交流中,遇到了这么一个需求,就是在TC中对一个字段实现帮助,然后从帮助选择值时能把文本带到TC中的文本字段中,原来没做过这种实现,只是做过回车后,通过CHAIN中的MODULE实现把文本自动带出来,这种方法比较简单,这里就不再说明了。后来找了一点资料,经过测试,用一种笨的方法实现了这个需求,应该还有更简单的方法,以后用到了再更新。现在把这种方法贴出来,与大家共享一下。希望对你有所帮助,也希望我下次能记住。
1、屏幕设计
在屏幕tc增加一列zwx-matnr,勾选输入字段复选框。
2、在逻辑流中输入以下代码
process on value-request.
field zwx-matnr module matnr_f4.
process on value-request.
field zwx-matnr module matnr_f4.
3、具体module代码
module matnr_f4.
data:
l_row like sy-tabix,
lt_return_tab type table of ddshretval,
ls_return_tab like line of lt_return_tab,
lt_systems like dynpread occurs 0 with header line.
data:
l_row like sy-tabix,
lt_return_tab type table of ddshretval,
ls_return_tab like line of lt_return_tab,
lt_systems like dynpread occurs 0 with header line.
*取出屏幕行
call function 'DYNP_GET_STEPL'
importing
povstepl = l_row.
importing
povstepl = l_row.
*调用帮助函数
call function 'F4IF_FIELD_VALUE_REQUEST'
exporting
tabname = 'MARA'
fieldname = 'MATNR'
dynpprog = sy-repid
dynpnr = '0110' "你的屏幕号
call function 'F4IF_FIELD_VALUE_REQUEST'
exporting
tabname = 'MARA'
fieldname = 'MATNR'
dynpprog = sy-repid
dynpnr = '0110' "你的屏幕号
dynprofield = 'ZWX-MATNR'
stepl = l_row
multiple_choice = ''
display = l_display
tables
return_tab = lt_return_tab
exceptions
field_not_found = 1
no_help_for_field = 2
inconsistent_help = 3
no_values_found = 4
others = 5.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
stepl = l_row
multiple_choice = ''
display = l_display
tables
return_tab = lt_return_tab
exceptions
field_not_found = 1
no_help_for_field = 2
inconsistent_help = 3
no_values_found = 4
others = 5.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
*查询成功,取出物料描述放入屏幕TC中的文本字段中
read table lt_return_tab into ls_return_tab index 1.
select single 描述 into 你的描述字段 from 表 where 字段 = ls_return_tab-fieldval.
endif.
read table lt_return_tab into ls_return_tab index 1.
select single 描述 into 你的描述字段 from 表 where 字段 = ls_return_tab-fieldval.
endif.
*更新屏幕上已经修改的字段
lt_systems-fieldname = '你的字段'.
lt_systems-stepl = l_row.
lt_systems-fieldvalue = ls_return_tab-fieldval. “返回的选择值
append lt_systems.
lt_systems-fieldname = '你的字段'.
lt_systems-stepl = l_row.
lt_systems-fieldvalue = 取出的文本值
append lt_systems.
lt_systems-stepl = l_row.
lt_systems-fieldvalue = ls_return_tab-fieldval. “返回的选择值
append lt_systems.
lt_systems-fieldname = '你的字段'.
lt_systems-stepl = l_row.
lt_systems-fieldvalue = 取出的文本值
append lt_systems.
call function 'DYNP_VALUES_UPDATE'
exporting
dyname = sy-repid
dynumb = '你的屏幕号'
tables
dynpfields = lt_systems
exceptions
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
undefind_error = 7
others = 8.
if sy-subrc <> 0.
endif.
endmodule. " MATNR_F4
exporting
dyname = sy-repid
dynumb = '你的屏幕号'
tables
dynpfields = lt_systems
exceptions
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
undefind_error = 7
others = 8.
if sy-subrc <> 0.
endif.
endmodule. " MATNR_F4
这里用物料来举例,当然也可以自己做帮助,也可以是系统的标准帮助,有兴趣的可以试一试,只有真正测试成功的时候,你才会感觉到自己又学到了新的知识!