其他分享
首页 > 其他分享> > ABAP DIALOG自定义搜素帮助,且带出相关描述。

ABAP DIALOG自定义搜素帮助,且带出相关描述。

作者:互联网

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

***INCLUDE LZBUKRS_ZHBBLXI01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  BUKRS_F4HELP  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE bukrs_f4help INPUT.
  DATA: lt_dynpfields TYPE STANDARD TABLE OF dynpread,
         ls_dynpfields TYPE dynpread,
         lt_return     TYPE STANDARD TABLE OF ddshretval,
         ls_return     TYPE ddshretval,
         lv_povstepl   TYPE sy-stepl,
         lv_index      TYPE sy-stepl.
  DATA:lv_bukrs TYPE t001-bukrs,
       lv_butxt TYPE t001-butxt.

  TYPES: BEGIN OF ty_out,
    bukrs TYPE t001-bukrs,
    butxt TYPE t001-butxt,
    END OF ty_out.
  DATA : it_out TYPE TABLE OF ty_out,
         is_out TYPE ty_out.


* 获取本页当前行号
  CALL FUNCTION 'DYNP_GET_STEPL'
    IMPORTING
      povstepl        = lv_povstepl
    EXCEPTIONS
      stepl_not_found = 1.

* 当前行号 = TC(包括翻页)的首行行号 + 本页当前行号 - 1
  lv_index = tctrl_zbukrs_zhbblx-top_line + lv_povstepl - 1.
  CLEAR lt_dynpfields[].
  ls_dynpfields-fieldname = 'ZBUKRS_ZHBBLX-BUKRS'.
  ls_dynpfields-stepl     = lv_index.
  APPEND ls_dynpfields TO lt_dynpfields.
  CLEAR ls_dynpfields.

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

  IF lv_bukrs IS INITIAL .
    SELECT
      bukrs
      butxt
      FROM t001
      INTO CORRESPONDING FIELDS OF TABLE it_out.
  ELSE.
    SELECT
    bukrs
    butxt
    FROM t001
    INTO CORRESPONDING FIELDS OF TABLE it_out
    WHERE bukrs = lv_bukrs.
  ENDIF.


* 自定义搜索帮助
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'BUKRS'
      value_org       = 'S'
    TABLES
      value_tab       = it_out
      return_tab      = lt_return
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.
  IF sy-subrc = 0.
    READ TABLE lt_return INTO ls_return INDEX 1.
    IF sy-subrc = 0.
*      zbukrs_zhbblx-bukrs = ls_return-fieldval.
      SELECT SINGLE butxt INTO lv_butxt FROM t001 WHERE bukrs = ls_return-fieldval.
*      MODIFY lt_dynpfields FROM ls_dynpfields INDEX lv_index .
    ENDIF.
  ENDIF.

*更新屏幕上已经修改的字段
  DATA : lt_systems    LIKE dynpread OCCURS 0 WITH HEADER LINE.
  CLEAR: lt_systems[],lt_systems.
  lt_systems-fieldname = 'ZBUKRS_ZHBBLX-BUKRS'.
  lt_systems-stepl = lv_index.
  lt_systems-fieldvalue = ls_return-fieldval. "返回的选择值
  APPEND lt_systems.
  lt_systems-fieldname = 'ZBUKRS_ZHBBLX-BUTXT'.
  lt_systems-stepl = lv_index.
  lt_systems-fieldvalue = lv_butxt.
  APPEND lt_systems.

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

ENDMODULE.                 " BUKRS_F4HELP  INPUT```

标签:自定义,lt,lv,ABAP,ls,搜素,dynpfields,bukrs,systems
来源: https://www.cnblogs.com/Hao9933/p/15740061.html