在AT SELECTION-SCREEN ON VALUE-REQUEST事件中,是不能直接取得选择屏幕字段的默认值或输入的值,而是需要通过函数 DYNP_VALUES_READ读取。
例子程序:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | 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为空,
随后通过DYNP_VALUES_READ读出,如下:
以上。