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

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

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.  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ChampaignWolf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值