1、 选择屏中的搜索帮助
2、 Alv 中的搜索帮助
3、 Tabcontrol中的搜索帮助
4、 自定义搜索帮助
1、选择屏中的搜索帮助
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_lifnr-low.
PERFORM frm_f4_xxx.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_lifnr-high.
PERFORM frm_f4_xxx.
FORM frm_f4_lifnr .
DATA: BEGIN OF lt_lifnr OCCURS 0,
lifnr TYPE lfa1-lifnr,
name1 TYPE lfa1-name1,
END OF lt_lifnr.
if r_lifnr[] is INITIAL.
MESSAGE s000(zmm01) WITH '未发现值'.
return.
ENDIF.
SELECT lifnr name1
INTO TABLE lt_lifnr
FROM lfa1.
sort lt_lifnr.
DELETE ADJACENT DUPLICATES FROM lt_lifnr COMPARING ALL FIELDS. delete lt_lifnr WHERE lifnr not in r_lifnr."过滤无权限查看lifnr
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'LIFNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'S_LIFNR'
value_org = 'S'
TABLES
value_tab = lt_LIFNR
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
ENDFORM. " FRM_F4_LIFNR
* *****取屏幕输入值****
DATA: lt_dynpread TYPE STANDARD TABLE OF dynpread .
DATA: lw_dynpread TYPE dynpread .
lw_dynpread-fieldname = 'P_UMWRK'.
APPEND lw_dynpread TO lt_dynpread .
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = sy-repid
dynumb = sy-dynnr
TABLES
dynpfields = lt_dynpread
EXCEPTIONS
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
invalid_parameter = 7
undefind_error = 8
double_conversion = 9
stepl_not_found = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT lt_dynpread INTO lw_dynpread .
SELECT lgort lgobe
INTO TABLE lt_umlgo
FROM t001l WHERE werks = lW_dynpread-fieldvalue.
ENDLOOP.
2、ALV 内搜索帮助
OO ALV
SET HANDLER lc_evt_receiver->handle_lifnr_f4 FOR gc_grid_imp.
"设置供应商f4帮助
CLEAR lt_f4.
lt_f4-fieldname = 'LIFNR'.
lt_f4-register = 'X'.
lt_f4-chngeafter = 'X'.
APPEND lt_f4.
CALL METHOD gc_grid_imp->register_f4_for_fields
EXPORTING
it_f4 = lt_f4[].
CALL METHOD gc_grid_imp->set_table_for_first_display
CLASS cl_evt_receiver DEFINITION.
PUBLIC SECTION.
"修改事件定义
METHODS handle_lifnr_f4 FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname e_fieldvalue es_row_no er_event_data et _bad_cells e_display.
ENDCLASS."cl_evt_receiver DEFINITION
METHOD handle_lifnr_f4.
DATA: ls_modi TYPE lvc_s_modi.
DATA: lt_retab TYPE TABLE OF ddshretval.
DATA: ls_retab TYPE ddshretval.
DATA: BEGIN OF ls_data,
lifnr TYPE lfa1-lifnr,
name1 TYPE lfa1-name1,
END OF ls_data,
lt_data LIKE TABLE OF ls_data.
FIELD-SYMBOLS: <fs_mod> TYPE STANDARD TABLE.
CHECK e_fieldname = 'LIFNR'.
SELECT a~lifnr b~name1
INTO TABLE lt_data
FROM ztfc_mm024b AS a
LEFT JOIN lfa1 AS b ON a~lifnr = b~lifnr
WHERE brand = p_brand.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'LIFNR'
value_org = 'S'
* dynpprog = sy-repid
* dynpnr = sy-dynnr
TABLES
value_tab = lt_data
return_tab = lt_retab
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
READ TABLE lt_retab INDEX 1 INTO ls_retab.
IF sy-subrc = 0.
ls_modi-row_id = es_row_no-row_id.
ls_modi-fieldname = e_fieldname.
ls_modi-value = ls_retab-fieldval.
ASSIGN er_event_data->m_data->* TO <fs_mod>.
APPEND ls_modi TO <fs_mod>.
ENDIF.
er_event_data->m_event_handled = 'X'.
ENDMETHOD. "handle_lifnr_f4
3、tabcontrol中的搜索帮助
*搜索帮助
PROCESS ON VALUE-REQUEST.
FIELD IT_DATA-MATNR_I MODULE VALUE_MATNR_I.
4、自定义搜索帮助
VALUE CHECK 、 fixed Values 、 Value Table
PARAMETERS p_1 TYPE zmy_dm_200 VALUE CHECK . " 注: SELECT-OPTIONS 没有此选项
如果选择屏幕字段参考数据元素所对应的 Domaim 设置了 固定值 ( fixed Values )或 值表 ( Value Table )时,使用 VALUE CHECK 选项后,会验证输入值是否在固定值或值表( 若要使值表检查生效 ,则首先需要将此 Domain 引用到表字段,再对此表字段通过 按钮进行外键分配,并且外键一定是来自的值表的主键,最后使用 PARAMETERS 定义屏幕参数时要参照此表字段,否则如果只是直接参照所对应的 DataElement 是不起作用, 即 Value Table 一定要经过转换为 Check Table 后再起作用 )范围之内
注: 如果要使用 VALUE CHECK 选项,则 Domain 的类型只能是 C 或者 N 类型 , 否则运行会抛异常。另外, 如果未使用该选项,但 F4 Help 还是会出现 (有固定值或检查表的情况下),但不进行有效性检查了
检查表 Check Table --- Value Table
也可以在 Domain 中指定一个值表( Value Table )作为字段取值范围的限制,但是与指定 固定值 的方式不同的是:为一个 Domain 简单地指定一个取值表不会导致用户的输入被自动校验,也不会自动出现 F4 Help 。 只有 通过表外键 按钮将该 Value Table 指定为主表之后,一个值表才能真正成为 Check Table 。所以要想成为真正有效的 Check Table ,必须要做两个操作:
一是 要为字段对应的 Domain 设置 Value Table (即主表 ,其实这一步不是必须的,在通过 按钮指定主表时,可以不用指定为字段所参照的元素所对应 Domain 所设置的 Value Table ,而是指定其他的主表也是可以的—— 但最好不要这样做 , Value Check 时会出其他问题) ,二是 要为表字段通过 为它设置外键 。
搜索帮助创建函数
在屏幕的 ON VALUE-REQUEST 事件里可以通过下面几个函数来创建搜索帮助:
F4IF_ FIELD _VALUE_REQUEST : 函数的作用是在运行时,可以 动态 的为某个屏幕字段 指定 Search Help ,这个被引用的 Help 来自某个表(或结构)字段上绑定的 Help
F4IF_ INT_TABLE _VALUE_REQUEST : 在程序运行时, 将某个内表动态的用作 Search help 的数据来源 ,即使用该函数可以将某个内表转换为 Search help ,可实现联动效果
TR_F4_HELP : 简单实现 Search Help ,数据来源于内表
老式ALV添加OO事件
REUSE_ALV_GRID_DISPLAY_LVC
参考程序名 ZMME0010
DATA: lt_events TYPE slis_t_event WITH HEADER LINE.
CLEAR: lt_events,lt_events[].
lt_events-name = 'CALLER_EXIT'.
lt_events-form = 'FRM_SET_EVENT'.
APPEND lt_events.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid " report id
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'PF' " 'STANDARD_STATUS'
is_layout_lvc = wa_layout " for layout
it_fieldcat_lvc = it_field " field catalog
i_save = 'X'
it_events = lt_events[]
TABLES
t_outtab = it_mard " internal table
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
FORM frm_set_event USING e_grid TYPE slis_data_caller_exit.
DATA: lc_evt_receiver TYPE REF TO cl_evt_receiver.
DATA: alv_grid TYPE REF TO cl_gui_alv_grid.
DATA: lt_f4 TYPE lvc_t_f4 WITH HEADER LINE.
lt_f4-fieldname = 'ZMASKID'.
lt_f4-register = 'X'.
lt_f4-getbefore = 'X'.
lt_f4-chngeafter = 'X'.
APPEND lt_f4.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = alv_grid.
CREATE OBJECT lc_evt_receiver.
CALL METHOD alv_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
CALL METHOD alv_grid->register_f4_for_fields
EXPORTING
it_f4 = lt_f4[].
SET HANDLER lc_evt_receiver->handle_data_changed FOR alv_grid.
SET HANDLER lc_evt_receiver->handle_data_changed_finished FOR alv_grid.
SET HANDLER lc_evt_receiver->handle_onf4 FOR alv_grid.
ENDFORM. " FRM_SET_EVENT
*&---------------------------------------------------------------------*
*& °üº¬ ZFC_MM002_D_CLASS
*&---------------------------------------------------------------------*
CLASS cl_evt_receiver DEFINITION.
PUBLIC SECTION.
METHODS handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed e_onf4 e_onf4_before e_ucomm.
METHODS handle_data_changed_finished FOR EVENT data_changed_finished OF cl_gui_alv_grid
IMPORTING e_modified et_good_cells.
METHODS handle_onf4 FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING
e_fieldname e_fieldvalue es_row_no er_event_data et_bad_cells e_display .
ENDCLASS. "cl_event_receiver DEFINITION
*----------------------------------------------------------------------*
* CLASS cl_evt_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_evt_receiver IMPLEMENTATION.
METHOD handle_onf4.
DATA: BEGIN OF ls_data,
zmaskid TYPE zmasktype-zmaskid,
device TYPE zmasktype-device,
END OF ls_data.
DATA: lt_data LIKE TABLE OF ls_data.
FIELD-SYMBOLS:<fs_data> TYPE ty_mard.
DATA: lt_return TYPE STANDARD TABLE OF ddshretval.
DATA: ls_return TYPE ddshretval.
FIELD-SYMBOLS: <fs_modi> TYPE lvc_t_modi.
DATA: ls_modi TYPE lvc_s_modi.
CHECK e_fieldname = 'ZMASKID'.
READ TABLE it_mard INDEX es_row_no-row_id ASSIGNING <fs_data>.
CHECK sy-subrc = 0.
SELECT zmaskid device
INTO TABLE lt_data
FROM zmasktype
WHERE kunnr = <fs_data>-zkunnr
AND maktx = <fs_data>-maktx
.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'ZMASKID' "ltÄÚ±íÀïÃæµÄ×Ö¶Î
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'ZMASKID' "»ÃæÉÏ°ó¶¨×Ö¶Î
value_org = 'S'
callback_program = sy-repid
TABLES
value_tab = lt_data "ÐèÒªÏÔʾ°ïÖúµÄÖµÄÚ±í
return_tab = lt_return "·µ»ØÖµ
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc = 0.
READ TABLE lt_return INDEX 1 INTO ls_return.
IF sy-subrc = 0.
CLEAR ls_modi.
ls_modi-row_id = es_row_no-row_id.
ls_modi-fieldname = e_fieldname.
ls_modi-value = ls_return-fieldval.
ASSIGN er_event_data->m_data->* TO <fs_modi>.
APPEND ls_modi TO <fs_modi>.
ENDIF.
ENDIF.
er_event_data->m_event_handled = 'X'."¸æÖªalvµ±Ç°f4ʼþÒÑ´¥·¢
ENDMETHOD. "handle_onf4
METHOD handle_data_changed .
DATA: lv_modi TYPE lvc_s_modi.
DATA: alv_grid TYPE REF TO cl_gui_alv_grid.
FIELD-SYMBOLS: <fs_data> TYPE ty_mard.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = alv_grid.
LOOP AT er_data_changed->mt_mod_cells INTO lv_modi.
IF lv_modi-fieldname = 'ZMASKID'.
READ TABLE it_mard INDEX lv_modi-row_id ASSIGNING <fs_data>.
SELECT SINGLE device
INTO <fs_data>-device
FROM zmasktype
WHERE kunnr = <fs_data>-zkunnr
AND maktx = <fs_data>-maktx
AND zmaskid = <fs_data>-zmaskid
.
ENDIF.
*
ENDLOOP.
* CALL METHOD alv_grid->refresh_table_display
* EXPORTING
* is_stable = stbl.
ENDMETHOD.
METHOD handle_data_changed_finished.
DATA: lx_mod_cells TYPE lvc_s_modi.
DATA: lv_modi TYPE lvc_s_modi. "»ñÈ¡¸ü¸Äºóµ¥Ôª¸ñµÄÊý¾Ý ¶ÔÊý¾Ý½øÐиü¸Ä
DATA: lt_modi TYPE lvc_t_modi.
FIELD-SYMBOLS: <fs_data> TYPE ty_mard.
DATA: gv_msg .