自定义 Search Help

在指定字段中,按F4键时,可调用自定义的程序或系统帮助数据;

该过程是通过单击F4事件来触发的,所以也可以通过ABAP事件控制语法 AT SELECTION-SCREEN来调用。

主要是通过调用函数:"F4IF_FIELD_VALUE_REQUEST".

 1 CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
 2     EXPORTING
 3       tabname                   = lv_tabname
 4       fieldname                 = lv_field
 5       searchhelp                = lv_help
 6    TABLES
 7      return_tab                = lt_return
 8    EXCEPTIONS
 9      field_not_found           = 1
10      no_help_for_field         = 2
11      inconsistent_help         = 3
12      no_values_found           = 4
13      OTHERS                    = 5

其中,lv_tabname 是对应参照表; lv_field是对应的参照字段

完整的代码:

 1 *&---------------------------------------------------------------------*
 2 *&      Form  f4_help
 3 *&---------------------------------------------------------------------*
 4 *       text
 5 *----------------------------------------------------------------------*
 6 *      -->LV_SEL_FIELD  text
 7 *      -->LV_TABNAME    text
 8 *      -->LV_FIELD      text
 9 *      -->LV_HELP       text
10 *----------------------------------------------------------------------*
11 FORM f4_help USING lv_sel_field lv_tabname lv_field lv_help.
12   DATA:lt_return LIKE ddshretval OCCURS 0 WITH HEADER LINE.
13   CLEAR:lt_return,lt_return[].
14 
15   CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
16     EXPORTING
17       tabname                   = lv_tabname
18       fieldname                 = lv_field
19       searchhelp                = lv_help
20 *   SHLPPARAM                 = ' ' “
21 *   DYNPPROG                  = ' ' "指定执行程序
22 *   DYNPNR                    = ' ' "指定执行程序屏幕编码
23 *   DYNPROFIELD               = ' ' "触发事件的屏幕对象名称
24 *   STEPL                     = 0   "
25 *   VALUE                     = ' ' "
26 *   MULTIPLE_CHOICE           = ' ' "多项选择,用于Select-options
27 *   DISPLAY                   = ' ' ”
28 *   SUPPRESS_RECORDLIST       = ' '
29 *   CALLBACK_PROGRAM          = ' '
30 *   CALLBACK_FORM             = ' '
31 *   SELECTION_SCREEN          = ' '
32 * IMPORTING
33 *   USER_RESET                =
34    TABLES
35      return_tab                = lt_return
36    EXCEPTIONS
37      field_not_found           = 1
38      no_help_for_field         = 2
39      inconsistent_help         = 3
40      no_values_found           = 4
41      OTHERS                    = 5
42             .
43   IF sy-subrc <> 0.
44     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
45             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
46   ELSE.
47     CLEAR lt_return.
48     READ TABLE lt_return INDEX 1.
49     lv_sel_field = lt_return-fieldval.
50   ENDIF.
51 
52 ENDFORM.                                                    " F4_HELP

在选择屏幕中直接调用即可:

1 AT SELECTION-SCREEN ON VALUE-REQUEST FOR so_venno-low.
2   PERFORM f4_help USING
3         so_venno-low 'MARA' 'ZZVC_NAME' 'ZSH_ZZVC_NO'.

 

posted @ 2012-11-05 22:32  沙茶叶  阅读(542)  评论(0编辑  收藏  举报