【ABAP系列】SAP ABAP DYNP_VALUES_UPDATE 更新屏幕字段的函数及用法

公众号:matinal
本文作者:matinal
 

前言部分

大家可以关注我的公众号,公众号里的排版更好,阅读更舒适。

正文部分

​
用这两个函数Function DYNP_VALUES_READ, DYNP_VALUES_UPDATE
参考代码:
MODULE ztmdno_dr_help INPUT.
  DATA:
    l_lifnr   TYPE ztmt018-lifnr,
    l_zvehtab TYPE ztmt018-zvehtab,
    l_zvehid  TYPE ztmt018-zvehid.

  CLEAR: gt_dynfields,gh_dynfields,it_return[],it_ztmdno[],ih_ztmdno.

  gh_dynfields-fieldname = 'PRE_DATA-LIFNR'.
  APPEND gh_dynfields TO gt_dynfields.
  CLEAR gh_dynfields.
  gh_dynfields-fieldname = 'PRE_DATA-ZVEHTAB'.
  APPEND gh_dynfields TO gt_dynfields.
----------------------获取屏幕的值
  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname               = sy-repid
      dynumb               = sy-dynnr
      translate_to_upper   = 'X'
    TABLES
      dynpfields           = gt_dynfields
    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.
  IF sy-subrc <> 0.
    MESSAGE '函数DYNP_VALUES_READ,未能取值' TYPE 'E'.
    EXIT.
  ENDIF.
  READ TABLE gt_dynfields INTO gh_dynfields WITH KEY fieldname = 'PRE_DATA-LIFNR'.
  IF sy-subrc = 0.
    l_lifnr = gh_dynfields-fieldvalue.
  ENDIF.

  READ TABLE gt_dynfields INTO gh_dynfields WITH KEY fieldname = 'PRE_DATA-ZVEHTAB'.
  IF sy-subrc = 0.
    IF gh_dynfields-fieldvalue IS INITIAL.
      MESSAGE '请先输入车牌号' TYPE 'I'.
      EXIT.
    ENDIF.
    l_zvehtab = gh_dynfields-fieldvalue.
  ENDIF.

  SELECT SINGLE zvehid
    INTO l_zvehid
    FROM ztmt018
   WHERE lifnr = l_lifnr
     AND zvehtab = l_zvehtab.

  SELECT ztmdno
         ztmdname
         ztmmob
         zvehid
    INTO TABLE it_ztmdno
    FROM ztmt025
   WHERE zvehid = l_zvehid.
  IF it_ztmdno[] IS NOT INITIAL.
    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
      EXPORTING
        retfield        = 'ZTMDNO_DR'
        dynpprog        = sy-repid
        dynpnr          = sy-dynnr
        value_org       = 'S'
      TABLES
        value_tab       = it_ztmdno[]
        return_tab      = it_return[]
      EXCEPTIONS
        parameter_error = 1
        no_values_found = 2
        OTHERS          = 3.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

    READ TABLE it_return INDEX 1.
    IF sy-subrc = 0.
      pre_data-ztmdno_dr = it_return-fieldval.
      READ TABLE it_ztmdno INTO ih_ztmdno WITH KEY zvehid = l_zvehid.
      IF sy-subrc = 0.
        CLEAR gh_dynfields.
        gh_dynfields-fieldname = 'PRE_DATA-ZTMDNAME_DR'.
        gh_dynfields-fieldvalue = ih_ztmdno-ztmdname_dr.
        APPEND gh_dynfields TO gt_dynfields.
        CLEAR gh_dynfields.
        gh_dynfields-fieldname = 'PRE_DATA-ZTMMOB'.
        gh_dynfields-fieldvalue = ih_ztmdno-ztmmob.
        APPEND gh_dynfields TO gt_dynfields.
---------------------更新屏幕的值
        CALL FUNCTION 'DYNP_VALUES_UPDATE'
          EXPORTING
            dyname               = sy-repid
            dynumb               = sy-dynnr
          TABLES
            dynpfields           = gt_dynfields
          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.
    ENDIF.
  ENDIF.
ENDMODULE.                 " ZTMDNO_DR_HELP  INPUT
原文地址:https://www.cnblogs.com/SAPmatinal/p/11183339.html