如何在事件AT SELECTION-SCREEN ON VALUE-REQUEST中取得选择画面字段输入值详解编程语言

在AT SELECTION-SCREEN ON VALUE-REQUEST事件中,是不能直接取得选择屏幕字段的默认值或输入的值,而是需要通过函数 DYNP_VALUES_READ读取。

如何在事件AT SELECTION-SCREEN ON VALUE-REQUEST中取得选择画面字段输入值详解编程语言

例子程序:

REPORT ZTEST_F4_DEFAULT. 
PARAMETERS: p_folder TYPE file_table-filename. 
INITIALIZATION. 
* 初始化 
p_folder = 'C:/ZPKF'. 
*&---------------------------------------------------------------------* 
*&   Event AT SELECTION-SCREEN 
*&---------------------------------------------------------------------* 
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_folder. 
PERFORM frm_f4_pfolder. 
*&---------------------------------------------------------------------* 
*&      Form  FRM_F4_PFOLDER 
*&---------------------------------------------------------------------* 
*       text 
*----------------------------------------------------------------------* 
*  -->  p1        text 
*  <--  p2        text 
*----------------------------------------------------------------------* 
FORM frm_f4_pfolder . 
DATA: l_path  TYPE string, 
l_sel   TYPE string, 
lit_dyn TYPE TABLE OF dynpread, 
lwa_dyn TYPE dynpread. 
IF p_folder IS INITIAL. 
lwa_dyn-fieldname = 'P_FOLDER'. 
APPEND lwa_dyn TO lit_dyn. 
CALL FUNCTION 'DYNP_VALUES_READ' 
EXPORTING 
dyname               = sy-cprog 
dynumb               = sy-dynnr 
TABLES 
dynpfields           = lit_dyn 
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. 
READ TABLE lit_dyn INTO lwa_dyn WITH KEY fieldname = 'P_FOLDER'. 
l_path = lwa_dyn-fieldvalue. 
ELSE. 
l_path = p_folder. 
ENDIF. 
CALL METHOD cl_gui_frontend_services=>directory_browse 
EXPORTING 
initial_folder       = l_path 
CHANGING 
selected_folder      = l_sel 
EXCEPTIONS 
cntl_error           = 1 
error_no_gui         = 2 
not_supported_by_gui = 3 
OTHERS               = 4. 
IF sy-subrc EQ 0. 
p_folder = l_sel. 
ENDIF. 
ENDFORM.

debug截图:

发现,虽然P_folder有初始默认值z:/zpkf,但是在VALUE-REQUEST事件中,P_folder为空,

如何在事件AT SELECTION-SCREEN ON VALUE-REQUEST中取得选择画面字段输入值详解编程语言

随后通过DYNP_VALUES_READ读出,如下:

如何在事件AT SELECTION-SCREEN ON VALUE-REQUEST中取得选择画面字段输入值详解编程语言

以上。

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/19256.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论