【函数】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.
【实现效果】