ABAP 使用DYNP_VALUES_READ来获取屏幕字段值
有的时候我们在程序中需要使用到屏幕字段的某些值,比如说一个search help的取数逻辑中要使用到已经输入的其他输入框中的值,但是结果往往不如人意,我们可能捕捉不到其他字段的值,从而无法得到我们想要的结果,那么这种情况下,我们应该使用 DYNP_VALUES_READ 方法,立即获取屏幕字段的值。
如下是使用的例子:
DATA: lt_dynpread TYPE STANDARD TABLE OF dynpread .
DATA: lw_dynpread TYPE dynpread .
lw_dynpread-fieldname = 'SO_CNTR-LOW'.
APPEND lw_dynpread TO lt_dynpread .
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = sy-repid
dynumb = sy-dynnr
TABLES
dynpfields = lt_dynpread
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 ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CLEAR lw_dynpread .
LOOP AT lt_dynpread INTO lw_dynpread .
IF lw_dynpread-fieldname EQ 'SO_CNTR-LOW'.
IF lw_dynpread-fieldvalue NE space OR
lw_dynpread-fieldvalue IS NOT INITIAL.
so_cntr-low = lw_dynpread-fieldvalue .
so_cntr-sign = 'I'.
so_cntr-option = 'EQ'.
APPEND so_cntr.
ENDIF.
ENDIF.
ENDLOOP.