SAP ABAP selection screen ,get field vaule without click Enter key.
有个需求,界面上几个字段的搜索帮助需要根据已输入值联动,比如AOP version 根据已输入的BU 过滤。
但尴尬的是在事件AT SELECTION-SCREEN ON VALUE-REQUEST FOR 中,各个字段已经输入的值无法更新到range 字段中,除非人为触发一个回车Enter,
解决方法是在 AT SELECTION-SCREEN ON VALUE-REQUEST FOR 中FRM中调用CALL FUNCTION 'DYNP_VALUES_READ' 动态获取。
部分代码如下:
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_BU-LOW.
PERFORM FRM_SHELP_BU.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_YM-LOW.
PERFORM FRM_SHELP_YM.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_VER-LOW.
PERFORM FRM_SHELP_VER.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
FORM FRM_SHELP_VER.
DATA: DYNPFIELDS TYPE TABLE OF DYNPREAD WITH HEADER LINE.
CLEAR: DYNPFIELDS, DYNPFIELDS[].
DYNPFIELDS-FIELDNAME = 'S_BU-LOW'."填入需要读值的字段名
APPEND DYNPFIELDS.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
DYNAME = SY-REPID
DYNUMB = SY-DYNNR
TRANSLATE_TO_UPPER = 'X'
TABLES
DYNPFIELDS = DYNPFIELDS
EXCEPTIONS
OTHERS = 9.
IF SY-SUBRC = 0.
READ TABLE DYNPFIELDS WITH KEY FIELDNAME = 'S_BU-LOW'.
IF sy-SUBRC = 0.
APPEND VALUE #( SIGN = 'I' OPTION = 'EQ'
LOW = DYNPFIELDS-FIELDVALUE ) TO S_BU.
ENDIF.
ENDIF.
IF S_BU[] IS NOT INITIAL.
SELECT ZBUSINESS_UNIT ,
ZYEAR_MONTH ,
AOP_VERSION
FROM ZYCDCN_AOPMV
INTO TABLE @DATA(LT_MV1)
WHERE ZBUSINESS_UNIT IN @S_BU.
ELSE.
SELECT ZBUSINESS_UNIT ,
ZYEAR_MONTH ,
AOP_VERSION
FROM ZYCDCN_AOPMV
INTO TABLE @DATA(LT_MV2) .
ENDIF.
IF LT_MV1 IS INITIAL.
APPEND LINES OF LT_MV2 TO LT_MV1.
ENDIF.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
RETFIELD = 'AOP_VERSION'
DYNPROFIELD = 'S_VER'
DYNPPROG = SY-CPROG
DYNPNR = SY-DYNNR
VALUE_ORG = 'S'
TABLES
VALUE_TAB = LT_MV1.
ENDFORM.
效果: