SELECTION-SCREEN选择界面字段值的实时获取-函数DYNP_VALUES_READ
项目中ABAP程序会遇到一种需求:实时获取屏幕字段的值。如下图所示:
根据销售组织/分销渠道/产品组来限制凭证类型的选择,类似与系统VA01操作。因为存在大量的必输字段,导致一个问题:只有把所有的必输字段维护完成之后,程序才会经过AT SELECTION-SCREEN的节点,但是实际的业务需求:未维护完整其他必输的情况下,也可以约束到凭证类型的选择范围。
为此,我们首先采用了MEMORY ID的方法,即想把销售组织/分销渠道/产品组3个字段维护的值写入到内存中,但是实际操作发现,必输字段没有维护完整,这些值无法写入内存。
因为和VA01的操作类似,通过调试系统标准程序,发现如下代码段和函数:
DATA: DA_AUART LIKE VBAK-AUART,
DA_BEZEI LIKE TVAKT-BEZEI.
DATA: BEGIN OF DYNPFIELDS OCCURS 5.
INCLUDE STRUCTURE DYNPREAD.
DATA: END OF DYNPFIELDS.
MOVE ‘VBAK-VKORG’ TO DYNPFIELDS-FIELDNAME.
APPEND DYNPFIELDS.
MOVE ‘VBAK-VTWEG’ TO DYNPFIELDS-FIELDNAME.
APPEND DYNPFIELDS.
MOVE ‘VBAK-SPART’ TO DYNPFIELDS-FIELDNAME.
APPEND DYNPFIELDS.
CALL FUNCTION ‘DYNP_VALUES_READ’
EXPORTING
DYNAME = SY-CPROG
DYNUMB = SY-DYNNR
TABLES
DYNPFIELDS = DYNPFIELDS
EXCEPTIONS
INVALID_ABAPWORKAREA = 01
INVALID_DYNPROFIELD = 02
INVALID_DYNPRONAME = 03
INVALID_DYNPRONUMMER = 04
INVALID_REQUEST = 05
NO_FIELDDESCRIPTION = 06
UNDEFIND_ERROR = 07.
IF SY-SUBRC EQ 0. “nur falls Transport-Felder im Dynpro existieren
READ TABLE DYNPFIELDS WITH KEY ‘VBAK-VKORG’.
IF SY-SUBRC = 0.
VBAK-VKORG = DYNPFIELDS-FIELDVALUE.
ENDIF.
READ TABLE DYNPFIELDS WITH KEY ‘VBAK-SPART’.
IF SY-SUBRC = 0.
VBAK-SPART = DYNPFIELDS-FIELDVALUE.
ENDIF.
READ TABLE DYNPFIELDS WITH KEY ‘VBAK-VTWEG’.
IF SY-SUBRC = 0.
VBAK-VTWEG = DYNPFIELDS-FIELDVALUE.
ENDIF.
ENDIF.
CALL FUNCTION ‘RV_HELP’
EXPORTING
KEY = VBAK-VKORG
KEY2 = VBAK-VTWEG
KEY3 = VBAK-SPART
KEY4 = T180-TRVOG
NUMBER = ‘008’
TRTYP = T185F-TRTYP
FIELD_IN = VBAK-AUART
DESCRIPTION_IN = TVAKT-BEZEI
IMPORTING
FIELD = DA_AUART
DESCRIPTION = DA_BEZEI.
IF DA_AUART IS INITIAL. ” Anwender hat F4-Hilfe abgebrochen
DA_AUART = TVAKT-AUART.
DA_BEZEI = TVAKT-BEZEI.
VBAK-AUART = DA_AUART.
ENDIF.
* Ermitteln der Anzeigeart für die Auftragsart (Anzeigen/Ändern)
REFRESH DYNPFIELDS.
CLEAR DYNPFIELDS.
MOVE ‘VBAK-AUART’ TO DYNPFIELDS-FIELDNAME.
APPEND DYNPFIELDS.
CALL FUNCTION ‘DYNP_VALUES_READ’
EXPORTING
DYNAME = SY-CPROG
DYNUMB = SY-DYNNR
TABLES
DYNPFIELDS = DYNPFIELDS
EXCEPTIONS
INVALID_ABAPWORKAREA = 01
INVALID_DYNPROFIELD = 02
INVALID_DYNPRONAME = 03
INVALID_DYNPRONUMMER = 04
INVALID_REQUEST = 05
NO_FIELDDESCRIPTION = 06
UNDEFIND_ERROR = 07.
READ TABLE DYNPFIELDS WITH KEY ‘VBAK-AUART’.
IF DYNPFIELDS-FIELDINP <> SPACE.
* Auftragsart ist zur Eingabe offen
VBAK-AUART = DA_AUART.
TVAKT-AUART = DA_AUART.
TVAKT-BEZEI = DA_BEZEI.
ENDIF.
REFRESH DYNPFIELDS.
CLEAR DYNPFIELDS.
通过对上述方法进行分析,总结如下解决方法:
手工对选择字段“凭证类型”P_AUART创建一个搜索帮助,如下所示
SELECT-OPTIONS:s_vkorg FOR vbak-vkorg NO-DISPLAY,
s_vtweg FOR vbak-vtweg NO-DISPLAY,
s_spart FOR vbak-spart NO-DISPLAY.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_auart.
DATA ls_auart LIKE help_info-dynprofld.
“获取销售凭证类型的搜索帮助内容
PERFORM frm_auart_f4.
ls_auart = ‘P_AUART’.
CALL FUNCTION ‘F4IF_INT_TABLE_VALUE_REQUEST’
EXPORTING
retfield = ‘AUART’
value_org = ‘S’
dynprofield = ls_auart
dynpprog = sy-repid
dynpnr = sy-dynnr
TABLES
value_tab = it_auart.
*&———————————————————————*
*& Form FRM_AUART_F4
*&———————————————————————*
* 获取销售凭证类型的搜索帮助内容
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM FRM_AUART_F4 .
DATA: BEGIN OF DYNPFIELDS OCCURS 5.
INCLUDE STRUCTURE DYNPREAD.
DATA: END OF DYNPFIELDS.
MOVE ‘P_VKORG’ TO DYNPFIELDS-FIELDNAME.
APPEND DYNPFIELDS.
MOVE ‘P_VTWEG’ TO DYNPFIELDS-FIELDNAME.
APPEND DYNPFIELDS.
MOVE ‘P_SPART’ TO DYNPFIELDS-FIELDNAME.
APPEND DYNPFIELDS.
CALL FUNCTION ‘DYNP_VALUES_READ’
EXPORTING
DYNAME = SY-CPROG
DYNUMB = SY-DYNNR
TABLES
DYNPFIELDS = DYNPFIELDS
EXCEPTIONS
INVALID_ABAPWORKAREA = 01
INVALID_DYNPROFIELD = 02
INVALID_DYNPRONAME = 03
INVALID_DYNPRONUMMER = 04
INVALID_REQUEST = 05
NO_FIELDDESCRIPTION = 06
UNDEFIND_ERROR = 07.
IF SY-SUBRC EQ 0.
READ TABLE DYNPFIELDS WITH KEY ‘P_VKORG’.
IF SY-SUBRC = 0.
P_VKORG = DYNPFIELDS-FIELDVALUE.
ENDIF.
READ TABLE DYNPFIELDS WITH KEY ‘P_SPART’.
IF SY-SUBRC = 0.
P_SPART = DYNPFIELDS-FIELDVALUE.
ENDIF.
READ TABLE DYNPFIELDS WITH KEY ‘P_VTWEG’.
IF SY-SUBRC = 0.
P_VTWEG = DYNPFIELDS-FIELDVALUE.
ENDIF.
ENDIF.
CLEAR:s_vkorg[],
s_vtweg[],
s_spart[].
s_vkorg-low = p_vkorg.
IF s_vkorg-low IS NOT INITIAL.
s_vkorg-sign = ‘I’.
s_vkorg-option = ‘EQ’.
APPEND s_vkorg.
ENDIF.
s_vtweg-low = p_vtweg.
IF s_vtweg-low IS NOT INITIAL.
s_vtweg-sign = ‘I’.
s_vtweg-option = ‘EQ’.
APPEND s_vtweg.
ENDIF.
s_spart-low = p_spart.
IF s_spart-low IS NOT INITIAL.
s_spart-sign = ‘I’.
s_spart-option = ‘EQ’.
APPEND s_spart.
ENDIF.
CLEAR:it_auart[],
it_auart.
SELECT tvakz~auart
tvakt~bezei
INTO CORRESPONDING FIELDS OF TABLE it_auart
FROM tvakz
INNER JOIN tvakt
ON tvakt~auart = tvakz~auart
WHERE tvakz~vkorg IN s_vkorg
AND tvakz~vtweg IN s_vtweg
AND tvakz~spart IN s_spart
AND tvakt~spras = sy-langu
.
SORT it_auart.
DELETE ADJACENT DUPLICATES FROM it_auart.
ENDFORM. ” FRM_AUART_F4
至此完成,对选择屏幕数据的实时获取!!!
转载自:https://blog.csdn.net/wangjolly/article/details/14453187