ABAP 代码自定义本地搜索帮助(F4IF_INT_TABLE_VALUE_REQUEST)

目录

1. 简介

2. 功能点

2.1 常规用法

2.2 搜索帮助数据表头自定义文本描述

2.3 根据选中行数据自动填充多个屏幕字段

2.4 多行选择

3. 其它自定义控制


1. 简介

        函数名:F4IF_INT_TABLE_VALUE_REQUEST

        主要功能: 通过代码逻辑取值,提供搜索帮助可选数据,自定义本地搜索帮助。一般用在选择屏幕或者屏幕开发。

2. 功能点

2.1 常规用法

        参考代码:

lt_value_tab = VALUE #( ( ebeln = '1' ebelp = '10' ) ( ebeln = '1' ebelp = '20' ) ( ebeln = '2' ebelp = '10' ) ).
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'EBELN'            " 展示列表中的字段名
      dynpprog        = sy-repid
      dynpnr          = '1000'             " 屏幕号
       dynprofield     = 'P_EBELN'         " 屏幕字段   
*     WINDOW_TITLE    = WINDOW_TITLE       " 
      value_org       = 'S'
    TABLES
      value_tab       = lt_value_tab       " 搜索帮助可选数据
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.

        效果:

ABAP 代码自定义本地搜索帮助(F4IF_INT_TABLE_VALUE_REQUEST)_第1张图片

        双击选中数据会将搜索帮助内表中选中行的EBELN字段值填充到1000屏幕的P_EBELN字段中

2.2 搜索帮助数据表头自定义文本描述

        参考代码:

lr_tabdescr ?= cl_abap_structdescr=>describe_by_data( ls_value_tab ).
  lt_dfies = cl_salv_data_descr=>read_structdescr( lr_tabdescr ).
  LOOP AT lt_dfies INTO ls_dfies.
    ls_dfies-lfieldname = ls_dfies-fieldname.
    ls_dfies-offset     = lv_offset.
    CASE ls_dfies-fieldname.
      WHEN 'EBELN'.
        ls_dfies-scrtext_l = ls_dfies-scrtext_m = ls_dfies-scrtext_s = ls_dfies-reptext = '贸易采购订单号'.
      WHEN 'EBELP'.
        ls_dfies-scrtext_l = ls_dfies-scrtext_m = ls_dfies-scrtext_s = ls_dfies-reptext = '订单行项目'.
      WHEN OTHERS.
    ENDCASE.
    lv_offset = lv_offset + ls_dfies-intlen.
    MODIFY lt_dfies FROM ls_dfies.
  ENDLOOP.

  lt_value_tab = VALUE #( ( ebeln = '1' ebelp = '10' ) ( ebeln = '1' ebelp = '20' ) ( ebeln = '2' ebelp = '10' ) ).
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'EBELN'
      dynpprog        = sy-repid
      dynpnr          = '1000'
      dynprofield     = 'P_EBELN'
*     WINDOW_TITLE    = WINDOW_TITLE
      value_org       = 'S'
* IMPORTING
*     USER_RESET      = USER_RESET
    TABLES
      value_tab       = lt_value_tab
      field_tab       = lt_dfies
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.
  IF sy-subrc <> 0.

  ENDIF.

        效果:

ABAP 代码自定义本地搜索帮助(F4IF_INT_TABLE_VALUE_REQUEST)_第2张图片

注意:搜索帮助数据表数据和 field_tab中字段的关联不是通过field_name,而是通过offset偏移对应,且是根据内部长度偏移(即一个字符两个长度)

2.3 根据选中行数据自动填充多个屏幕字段

        参考代码:

lr_tabdescr ?= cl_abap_structdescr=>describe_by_data( ls_value_tab ).
  lt_dfies = cl_salv_data_descr=>read_structdescr( lr_tabdescr ).
  LOOP AT lt_dfies INTO ls_dfies.
    ls_dfies-lfieldname = ls_dfies-fieldname.
    ls_dfies-offset     = lv_offset.
    CASE ls_dfies-fieldname.
      WHEN 'EBELN'.
        ls_dfies-scrtext_l = ls_dfies-scrtext_m = ls_dfies-scrtext_s = ls_dfies-reptext = '贸易采购订单号'.
      WHEN 'EBELP'.
        ls_dfies-scrtext_l = ls_dfies-scrtext_m = ls_dfies-scrtext_s = ls_dfies-reptext = '订单行项目'.
      WHEN OTHERS.
    ENDCASE.
    lv_offset = lv_offset + ls_dfies-intlen.
    MODIFY lt_dfies FROM ls_dfies.
  ENDLOOP.

  ls_dynpfld_mapping-dyfldname = 'P_EBELN'.
  ls_dynpfld_mapping-fldname   = 'EBELN'.
  APPEND ls_dynpfld_mapping TO lt_dynpfld_mapping.

  ls_dynpfld_mapping-dyfldname = 'P_EBELP'.
  ls_dynpfld_mapping-fldname   = 'EBELP'.
  APPEND ls_dynpfld_mapping TO lt_dynpfld_mapping.
  
  lt_value_tab = VALUE #( ( ebeln = '1' ebelp = '10' ) ( ebeln = '1' ebelp = '20' ) ( ebeln = '2' ebelp = '10' ) ).
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'P_EBELN'
      dynpprog        = sy-repid
      dynpnr          = '1000'
      dynprofield     = 'P_EBELN'
*     WINDOW_TITLE    = WINDOW_TITLE
      value_org       = 'S'
* IMPORTING
*     USER_RESET      = USER_RESET
    TABLES
      value_tab       = lt_value_tab
      field_tab       = lt_dfies
*     return_tab      = return_tab
      dynpfld_mapping = lt_dynpfld_mapping
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.
  IF sy-subrc <> 0.

  ENDIF.

        效果:

注意:此时参数retfield的传值不再是内表字段名

2.4 多行选择

        参考代码:

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'S_EBELN'
      dynpprog        = sy-repid
      dynpnr          = '1000'
      dynprofield     = 'S_EBELN'
* IMPORTING
*     USER_RESET      = USER_RESET
    TABLES
      value_tab       = lt_value_tab
      return_tab      = lt_return_tab
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.

          效果:

ABAP 代码自定义本地搜索帮助(F4IF_INT_TABLE_VALUE_REQUEST)_第3张图片

注意:此时需要结合return_tab(返回参数,为搜索帮助页面选择的数据)对屏幕字段进行赋值,一行多列的实现也可以选择使用该返回参数中值进行页面数据的填充.

3. 其它自定义控制

        补充参数CALLBACK_FORM,可以提供类似SE11中搜索帮助出口函数的个性化设置,通过对搜索帮助的参数更改来实现各种自定义的功能,比如一行多列数据的填充可以在该form中对参数shlp-interface进行更改达到目的。

        参考代码:

lt_value_tab = VALUE #( ( ebeln = '1' ebelp = '10' ) ( ebeln = '1' ebelp = '20' ) ( ebeln = '2' ebelp = '10' ) ).
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield         = 'P_EBELN'
      dynpprog         = sy-repid
      dynpnr           = '1000'
      dynprofield      = 'P_EBELN'
*     WINDOW_TITLE     = WINDOW_TITLE
      callback_program = sy-repid
      callback_form    = 'S_EBELN_EXITFORM'
* IMPORTING
*     USER_RESET       = USER_RESET
    TABLES
      value_tab        = lt_value_tab
      return_tab       = lt_return_tab
    EXCEPTIONS
      parameter_error  = 1
      no_values_found  = 2
      OTHERS           = 3.

ENDFORM.

FORM s_ebeln_exitform TABLES record_tab STRUCTURE seahlpres
              CHANGING shlp TYPE shlp_descr_t
                callcontrol LIKE ddshf4ctrl.

ENDFORM.

你可能感兴趣的:(ABAP,速食,abap)