例1
REPORT ZTEST_SAM_SEARCH_HELP.
data:begin of ithp_pline occurs 0,
WERKS type lips-WERKS,
LGORT type lips-LGORT,
end of ithp_pline.
parameters: t_WERKS type lips-WERKS,
t_LGORT type lips-LGORT.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR t_LGORT.
clear ithp_pline.
select distinct WERKS LGORT
into corresponding fields of table ithp_pline
from lips where WERKS = t_WERKS.
call function 'F4IF_INT_TABLE_VALUE_REQUEST' "调用函数
exporting
retfield = 'LGORT'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'T_LGORT'
value_org = 'S'
tables
value_tab = ithp_pline.
例2
REPORT zgffi_002.
TABLES: reguh,bsak,ztfi_paymethod.
"变量定义
DATA: ld_filename TYPE string,"文件名变量
ld_path TYPE string,
ld_fullpath TYPE string,
ld_result TYPE i,
gd_file TYPE c.
DATA: BEGIN OF tlaufk OCCURS 1."F4帮助变量
INCLUDE STRUCTURE ilaufk.
DATA: END OF tlaufk.
DATA: gt_ZSREGUH01 TYPE TABLE OF zsreguh01,"主数据内表
wt_reguh TYPE zsreguh01,
gt_bsak TYPE TABLE OF bsak,"发票数据内表
wt_bsak TYPE bsak.
TYPE-POOLS: vrm.
DATA: it_val1 TYPE vrm_values,"下拉框变量
w_line LIKE LINE OF it_val1.
"选择屏幕
PARAMETERS: p_laufd TYPE reguh-laufd OBLIGATORY,"運行日期
p_laufi TYPE reguh-laufi OBLIGATORY,"標識
p_datum TYPE sy-datum OBLIGATORY,"付款日期
p_fpath TYPE rlgrap-filename OBLIGATORY."文件名
PARAMETERS: p_bank LIKE ztfi_paymethod-zpaymethod AS LISTBOX VISIBLE LENGTH 8 OBLIGATORY."HSBC/STS
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fpath.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
default_extension = 'csv'
default_file_name = 'accountsdata.csv'
initial_directory = 'c:/temp/'
CHANGING
filename = ld_filename
path = ld_path
fullpath = ld_fullpath
user_action = ld_result.
p_fpath = ld_fullpath.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_laufd.
REFRESH tlaufk.
tlaufk-laufk = space.
tlaufk-sign = 'I'.
APPEND tlaufk.
CALL FUNCTION 'F4_ZAHLLAUF'
EXPORTING
f1typ = 'D'
f2nme = 'P_LAUFI'
IMPORTING
laufd = p_laufd
laufi = p_laufi
TABLES
laufk = tlaufk.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_laufi.
REFRESH tlaufk.
tlaufk-laufk = space.
tlaufk-sign = 'I'.
APPEND tlaufk.
CALL FUNCTION 'F4_ZAHLLAUF'
EXPORTING
f1typ = 'I'
f2nme = 'P_LAUFD'
IMPORTING
laufd = p_laufd
laufi = p_laufi
TABLES
laufk = tlaufk.
"对选择屏幕的数据进行检查
AT SELECTION-SCREEN.
IF p_datum <= sy-datum.
MESSAGE 'date error' TYPE 'E'.
ENDIF.
"初始化程序
INITIALIZATION.
CLEAR w_line.
REFRESH it_val1[].
w_line-key = 'STS'.
w_line-text = '渣打银行'.
APPEND w_line TO it_val1.
p_bank = w_line-key.
w_line-key = 'HSBC'.
w_line-text = '汇丰银行'.
APPEND w_line TO it_val1.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'p_bank'
values = it_val1
* EXCEPTIONS
* ID_ILLEGAL_NAME = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
例3
MODULE search_so INPUT.
CLEAR ITAB_SO_INFO.
* DATA: BEGIN OF ITAB_SO_TIT OCCURS 0,
* PATTERN(10) TYPE C, "花样编号
* COMB(10) TYPE C, "颜色组合
* END OF ITAB_SO_TIT.
* field_value-fieldname = 'Pattern'.
* APPEND field_value to dynpro_values.
* field_value-fieldname = 'Comb'.
* APPEND field_value to dynpro_values.
SELECT VBELN MATNR MATKL
FROM VBAP
INTO TABLE ITAB_SO_INFO .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
"ddic_structure = 'JBIZKARTLIST'
retfield = 'PATTERN'
dynprofield = 'MATNR' "字段2
dynpprog = sy-repid
dynpnr = sy-dynnr
value_org = 'S'
callback_program = sy-repid
callback_form = 'F_SOINFO_FORM'
TABLES
value_tab = ITAB_SO_INFO
return_tab = return_tab
"DYNPFLD_MAPPING = dynpro_values
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDMODULE.
FORM f_soinfo_form TABLES record_tab STRUCTURE seahlpres
CHANGING shlp TYPE shlp_descr
callcontrol LIKE ddshf4ctrl.
DATA: interface LIKE LINE OF shlp-interface.
READ TABLE shlp-interface INTO interface INDEX 1.
interface-shlpfield+4(1) = '2'."字段2 interface-valfield = 'ITAB_HDR-MATNR'.
APPEND interface TO shlp-interface.
interface-shlpfield+4(1) = '3'."字段3
interface-valfield = 'ITAB_HDR-NAME'.
APPEND interface TO shlp-interface.
ENDFORM.
当选择屏幕上的一个字段所参考的数据元素没有建立搜索帮助时,可以手工建立一个:
1、在se11创建一个搜索帮助ZAUTEST,需要输入:
(1)描述;
(2)选择方法:即搜索帮助显示字段所在的透明表;
(3)搜索帮助参数:即搜索帮助要显示的字段;
(4)IMP:输入字段,勾上即表示显示该字段;
(5)EXP:输出字段,勾上即表示该字段是搜索帮助需要的输入字段;
(6)Lpos:搜索帮助下半部分字段排序;Spos:搜索帮助上半部分字段排序。
如下图:
在Dialog屏幕中给输入字段建立搜索帮助,有以下三种情况:
一:直接使用系统已有的搜索帮助,对于系统已存在搜索帮助的输入字段可直接使用:在屏幕格式器里双击输入字段框,在其“属性”栏的“搜索帮助”框内填入该字段的搜索帮助名称。如物料“matnr”的搜索帮助名称为“MAT1”。注意:MAT1一定要大写,对于所有在屏幕输入的字符,不管以任何形式输入都要大写,否则系统是不认识的,就如在代码里引号内的字符串要大写才正确一样。
二:自建搜索帮助,其过程如下:
1、在dialog屏幕的逻辑流里在user_command后定义module,如下:
process before output.
...
process after input.
module user_command_0100.
process on value-request. "输入字段的响应
field t_pline module f4_help_for_pline. "“t_plnnr”是输入字段的“name”,“f4_help_for_pline”是module名,自己随便起吧
2、双击“f4_help_for_pline”创建该module,这时进入程序代码编辑,module如下:
module f4_help_for_pline input.
call function 'F4IF_INT_TABLE_VALUE_REQUEST' "调用函数
exporting
retfield = 'PLINE' "搜索帮助内表要输出的的帮助字段名,注:要大写
dynpprog = sy-repid
dynpnr = sy-dynnr
* dynprofield = ''
value_org = 'S'
tables
value_tab = ithp_pline. "存储搜索帮助内容的内表
endmodule. " f4_help_for_pline INPUT
注:“retfield”的内表输出字段的名字要和输入字段保持一致,并最好和透明表的字段名一致,否则弹出的搜索帮助会显示不了字段名。
3、在屏幕输出前或在上一屏幕进入本屏幕的动作发生后,取得搜索帮助的内容,如下:
clear ithp_pline[].
select pline pltxt
into corresponding fields of table ithp_pline
from afpo
where dwerk = t_werks
and matnr = t_matnr.
内表ithp_pline有两个字段pline、pltxt即是搜索帮助将显示的两个列,其中ithp_pline是输入字段。
三:联动搜索帮助的建立:有两个输入字段要建立搜索帮助,并且这两个字段是相互关联的,选择一个字段的输入值同时也选择了另一个字段的值,比如顺序与工序的关系必需是相互的。
1、定义
data:field_tab_vgn type dfies occurs 0,
dynpfld_mapping_vgn type dselc occurs 0,
wa_map_vgn type dselc,
field_tab_pln type dfies occurs 0,
dynpfld_mapping_pln type dselc occurs 0,
wa_map_pln type dselc.
2、在dialog屏幕的逻辑流里在user_command后定义module,如下:
process before output.
...
process after input.
module user_command_0100.
process on value-request.
field:it_bg-plnfl module f4_help_for_vornr, "顺序、工序的联动搜索
it_bg-vornr module f4_help_for_vornr.
3、双击“f4_help_for_vornr”创建该module,这时进入程序代码编辑,module如下:
module f4_help_for_vornr input.
call function 'F4IF_INT_TABLE_VALUE_REQUEST'
exporting
retfield = 'PLNFL' "搜索帮助要输出的的帮助字段名
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'T_PLNFL' "“T_PLNFL”为输入字段,在此用T_VORNR也可以但上面的retfield名也要改
value_org = 'S'
tables
field_tab = field_tab_vgn "联动关系表
dynpfld_mapping = dynpfld_mapping_vgn "存储联动内容的内表
value_tab = ithp_vgn. "存储搜索帮助的内表
endmodule. " f4_help_for_vornr INPUT
4、在屏幕输出前或在上一屏幕进入本屏幕的动作发生后,取得搜索帮助的内容,如下:
clear ithp_vgn[].
select plnfl vornr ltxa1
into corresponding fields of table ithp_vgn
from afko
inner join afvc on afvc~aufpl = afko~aufpl
where afko~aufnr = t_aufnr.
"调用联动函数
call function 'ZSET_F4_FIELD_FROM_VALUE_TAB'
tables
value_tab = ithp_vgn "存储搜索帮助的内表
field_tab = field_tab_vgn. "联动关系表
clear dynpfld_mapping_vgn[].
wa_map_vgn-fldname = 'PLNFL'. "帮助内表字段
wa_map_vgn-dyfldname = 'T_PLNFL'. "输入字段
append wa_map_vgn to dynpfld_mapping_vgn.
wa_map_vgn-fldname = 'VORNR'.
wa_map_vgn-dyfldname = 'T_VORNR'.
append wa_map_vgn to dynpfld_mapping_vgn.
转载请注明来自“共产主义”!