ABAP SM30自定义搜素帮助,且带出相关描述,也可回车带出。

本篇文章用SM30字段BUKRS带出BUTXT为例。

ABAP SM30自定义搜素帮助,且带出相关描述,也可回车带出。_第1张图片

ABAP SM30自定义搜素帮助,且带出相关描述,也可回车带出。_第2张图片

MODULE zfzhdm_f4help INPUT.
 DATA: lt_dynpfields1 TYPE STANDARD TABLE OF dynpread,
           ls_dynpfields1 TYPE dynpread,
           lt_return1     TYPE STANDARD TABLE OF ddshretval,
           ls_return1     TYPE ddshretval,
           lv_povstepl1   TYPE sy-stepl,
           lv_index1      TYPE sy-stepl.
  DATA:lv_zfzhdm TYPE zfzh_dm1-zfzhdm,
       lv_zfzhms TYPE zfzh_dm1-zfzhms.

  TYPES: BEGIN OF ty_out,
        zfzhdm TYPE zfzh_dm1-zfzhdm,
        zfzhms TYPE zfzh_dm1-zfzhms,
    END OF ty_out.
  DATA : it_out1 TYPE TABLE OF ty_out,
         is_out1 TYPE ty_out.

  DATA : lv_flag TYPE c.
  CLEAR lv_flag .
*  CLEAR:lv_zfzhdm,lv_zfzhms.
* 获取本页当前行号
  CALL FUNCTION 'DYNP_GET_STEPL'
    IMPORTING
      povstepl        = lv_povstepl1
    EXCEPTIONS
      stepl_not_found = 1.

* 当前行号 = TC(包括翻页)的首行行号 + 本页当前行号 - 1
  lv_index1 = tctrl_zz006_zhbblx-top_line + lv_povstepl1 - 1.
  CLEAR lt_dynpfields1[].
  ls_dynpfields1-fieldname = 'ZZ006_ZHBBLX-ZFZHDM'.
  ls_dynpfields1-stepl     = lv_index1.
  APPEND ls_dynpfields1 TO lt_dynpfields1.
  CLEAR ls_dynpfields1.

* 获取屏幕值(以防用户修改后未按回车)
  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname               = sy-repid
      dynumb               = sy-dynnr
      translate_to_upper   = 'X'
    TABLES
      dynpfields           = lt_dynpfields1
    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.
  READ TABLE lt_dynpfields1 INTO ls_dynpfields1 INDEX 1.
  IF sy-subrc = 0.
    lv_zfzhdm = ls_dynpfields1-fieldvalue.
  ENDIF.

*  IF lv_zfzhdm IS INITIAL .
  SELECT
    zfzhdm
    zfzhms
    FROM zfzh_dm1
    INTO CORRESPONDING FIELDS OF TABLE it_out1.
*  ELSE.
*    SELECT
*      zfzhdm
*      zfzhms
*    FROM zfzh_dm1
*    INTO CORRESPONDING FIELDS OF TABLE it_out1
*    WHERE zfzhdm = lv_zfzhdm.
*  ENDIF.


* 自定义搜索帮助
*  CLEAR :lt_return1,ls_return1.
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'ZFZHDM'
      value_org       = 'S'
    TABLES
      value_tab       = it_out1
      return_tab      = lt_return1
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.
  IF sy-subrc = 0.
    READ TABLE lt_return1 INTO ls_return1 INDEX 1.
    IF sy-subrc = 0.
*      zbukrs_zhbblx-bukrs = ls_return1-fieldval.
      SELECT SINGLE zfzhms INTO lv_zfzhms FROM zfzh_dm1 WHERE zfzhdm = ls_return1-fieldval.
*      MODIFY lt_dynpfields1 FROM ls_dynpfields1 INDEX lv_index1 .
*   ELSE.
*     lv_flag = 'X'.
    ENDIF.
  ENDIF.

*更新屏幕上已经修改的字段
  IF lv_flag <> 'X'.
    DATA : lt_systems1    LIKE dynpread OCCURS 0 WITH HEADER LINE.
    CLEAR: lt_systems1[],lt_systems1.
    lt_systems1-fieldname = 'ZZ006_ZHBBLX-ZFZHDM'.
    lt_systems1-stepl = lv_index1.
    lt_systems1-fieldvalue = ls_return1-fieldval. "返回的选择值
    APPEND lt_systems1.
    lt_systems1-fieldname = 'ZZ006_ZHBBLX-ZFZHMS'.
    lt_systems1-stepl = lv_index1.
    lt_systems1-fieldvalue = lv_zfzhms.
    APPEND lt_systems1.

    CALL FUNCTION 'DYNP_VALUES_UPDATE'
      EXPORTING
        dyname               = sy-repid
        dynumb               = '0001'
      TABLES
        dynpfields           = lt_systems1
      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.
  ENDIF.
ENDMODULE.  

你可能感兴趣的:(java,数据库,开发语言)