SAP DYNP_VALUES_UPDATE/READ 更新/获取屏幕字段函数用法

【函数】Function DYNP_VALUES_READ, DYNP_VALUES_UPDATE

【作用】实时获取和更新屏幕上的最新值。

【场景】GUI选择屏幕,选择公司代码,过滤所属公司下的项目;选择项目过滤所属的分期。



REPORT zdynp_values_read MESSAGE-ID 00 NO STANDARD PAGE HEADING.
TABLES:t001,ztsd0011.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-t01.
PARAMETERS p_bukrs TYPE t001-bukrs.
PARAMETERS p_pspnr TYPE ztsd0011-pspnr.
SELECT-OPTIONS:
  s_fqwbs  FOR ztsd0011-fqwbs  MODIF ID m1.

SELECTION-SCREEN END OF BLOCK b2.
*----------------------------------------------------------------------
*  AT SELECTION-SCREEN ON VALUE-REQUEST
*----------------------------------------------------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_pspnr.
  PERFORM frm_fqwbs_f4 USING 'P_PSPNR-LOW' 1 'P_BUKRS'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_fqwbs-low.
  PERFORM frm_fqwbs_f4 USING 'S_FQWBS-LOW' 2 'P_PSPNR'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_fqwbs-high.
  PERFORM frm_fqwbs_f4 USING 'S_FQWBS-HIGH' 2 'P_PSPNR'.

*&---------------------------------------------------------------------*
*&      Form  FRM_FQWBS_F4
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_fqwbs_f4  USING uv_name uv_level uv_bukrs.
  DATA: BEGIN OF lt_posid OCCURS 0,
          posid TYPE prps-posid,              "工作分解结构元素
          post1 TYPE prps-post1,              "短描述
          pbukr TYPE prps-pbukr,              "短描述
        END OF lt_posid.
  DATA: l_pspnr  TYPE prps-pspnr,
        lv_bukrs TYPE bukrs_d,
        l_posid  TYPE prps-posid,
        l_psphi  type prhi-psphi.

  DATA:
    wa_posid   LIKE lt_posid,
    scr_fields LIKE dynpread OCCURS 1 WITH HEADER LINE.

  CLEAR: scr_fields, scr_fields[].

  scr_fields-fieldname = uv_bukrs.
  APPEND scr_fields.

  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname               = sy-repid
      dynumb               = sy-dynnr
    TABLES
      dynpfields           = scr_fields
    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 EQ 0.
    READ TABLE scr_fields INDEX 1.
    CASE uv_level.
      WHEN '1'.
        lv_bukrs = scr_fields-fieldvalue.
      WHEN '2'.
        l_posid = scr_fields-fieldvalue.
    ENDCASE.
  ENDIF.

  "获取项目内码
  SELECT SINGLE pspnr psphi INTO ( l_pspnr, l_psphi ) FROM prps WHERE pspnr = l_posid.

  CASE uv_level.
    WHEN '1'.
      "公司代码过滤所属项目
      IF lv_bukrs IS NOT INITIAL.
        SELECT prps~posid
        prps~post1
        prps~pbukr
        INTO CORRESPONDING FIELDS OF TABLE lt_posid
        FROM prps
        JOIN prhi ON prps~pspnr EQ prhi~posnr
        WHERE prps~stufe EQ uv_level
        AND pbukr = lv_bukrs.
      ELSE.
        SELECT prps~posid
        prps~post1
        prps~pbukr
        INTO CORRESPONDING FIELDS OF TABLE lt_posid
        FROM prps
        JOIN prhi ON prps~pspnr EQ prhi~posnr
        WHERE prps~stufe EQ uv_level.
      ENDIF.
    WHEN '2'.
      "项目过滤所属的分期
      IF l_psphi IS NOT INITIAL.
        SELECT prps~posid
        prps~post1
        prps~pbukr
        INTO CORRESPONDING FIELDS OF TABLE lt_posid
        FROM prps
        JOIN prhi ON prps~pspnr EQ prhi~posnr
        WHERE prps~stufe = '2'
          AND prhi~psphi = l_psphi.
      ENDIF.
  ENDCASE.

  SORT lt_posid BY posid.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'POSID'
      dynpprog        = sy-repid
      dynpnr          = sy-dynnr
      dynprofield     = uv_name
      value_org       = 'S'
    TABLES
      value_tab       = lt_posid
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.
ENDFORM.

【实现效果】


下面是一个简单的ABAP dialog程序例子,演示如何实现回车带出描述功能: ``` REPORT ZTEST_DIALOG. TABLES: MARA. DATA: BEGIN OF IT_MARA OCCURS 0, MATNR LIKE MARA-MATNR, MTART LIKE MARA-MTART, MAKTX LIKE MARA-MAKTX, END OF IT_MARA. DATA: WA_MARA LIKE LINE OF IT_MARA. MODULE STATUS_0100 OUTPUT. SET PF-STATUS '100'. SET TITLEBAR '100'. LOOP AT IT_MARA INTO WA_MARA. WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MAKTX. ENDLOOP. ENDMODULE. MODULE USER_COMMAND_0100 INPUT. CASE OK_CODE. WHEN 'BACK'. LEAVE TO SCREEN 0. WHEN 'ENTER'. CALL FUNCTION 'DYNP_VALUES_READ' EXPORTING DYNAME = SY-REPID DYNUMB = SY-DYNNR TABLES DYNPFLD = IT_FIELD. READ TABLE IT_FIELD WITH KEY FIELDNAME = 'MATNR'. READ TABLE MARA INTO WA_MARA WITH KEY MATNR = IT_FIELD-FIELDVALUE. IF SY-SUBRC = 0. WA_MARA-MAKTX = IT_FIELD-FIELDVALUE+20(40). MODIFY MARA FROM WA_MARA. CALL FUNCTION 'DYNP_VALUES_UPDATE' EXPORTING DYNAME = SY-REPID DYNUMB = SY-DYNNR TABLES DYNPFLD = IT_FIELD. ENDIF. ENDCASE. ENDMODULE. MODULE INITIALIZATION. SELECT * FROM MARA INTO TABLE IT_MARA. ENDMODULE. ``` 在上述例子中,我们在屏幕布局中设置了MATNR和MAKTX两个字段的文本行和输出行属性都为2,这样就可以在输入MATNR时,同时在MAKTX字段中显示描述信息。在用户输入MATNR并按下回车键后,我们通过DYNP_VALUES_READ函数读取输入,然后根据MATNR查询相应的MARA表记录,将MAKTX字段更新为相应的描述信息,最后通过DYNP_VALUES_UPDATE函数更新屏幕字段
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值