在SAP中可以调用IE来打开URL地址(函数WS_EXECUTE),但如打开的网页需要登陆时,还需要使用单点登陆并打开网页,比如SAP本机的FIORI ,WebDynpro的URL地址时,以下分别说明在IE中打开当前SAP服务器的URL,及在SAP GUI中打开的方法,主要是解决打开并登陆的问题,如是只为打开可以直接使用函数WS_EXECUTE:
1.在SAPGUI 中打开URL
创建函数ZURL_EXECUTE_IN_PLACE。默认输入FIORI ,WDY的地址,就会在SAPGUI中打开
1.1.函数
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
FUNCTION zurl_execute_in_place. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" VALUE(PROTOCOL) TYPE STRING OPTIONAL *" VALUE(INTERNALMODE) TYPE CHAR01 DEFAULT 'X' *" VALUE(SMARTCLIENT) TYPE CHAR01 OPTIONAL *" REFERENCE(CONTAINER_NAME) TYPE SCRFNAME OPTIONAL *" REFERENCE(SUPPRESS_OUTPUT) TYPE CHAR01 OPTIONAL *" REFERENCE(TRY_TO_USE_SAPGUI_THEME) TYPE CHAR01 DEFAULT '' *" REFERENCE(IN_URL) TYPE STRING *" CHANGING *" REFERENCE(VIEWER) TYPE REF TO CL_GUI_WDR_VIEWER OPTIONAL *" EXCEPTIONS *" INVALID_APPLICATION *" BROWSER_NOT_STARTED *" ACTION_CANCELLED *"---------------------------------------------------------------------- DATA: char_url TYPE char1024. gen_url = in_url. CHECK suppress_output IS INITIAL. wdr_html_viewer = viewer. IF container_name IS INITIAL. fscr_mode = 'X'. ELSE. CLEAR fscr_mode. ENDIF. char_url = gen_url. IF internalmode EQ space AND smartclient EQ space. TRY. DATA: l_empty_co TYPE REF TO cl_gui_container. "#EC NEEDED CREATE OBJECT wdr_html_viewer EXPORTING parent = l_empty_co protocol = protocol EXCEPTIONS html_control_error = 1. IF sy-subrc EQ 0. CALL METHOD wdr_html_viewer->('DETACH_URL_IN_BROWSER') EXPORTING url = char_url. cl_gui_cfw=>flush( ). ELSE. CALL FUNCTION 'CALL_BROWSER' EXPORTING url = char_url EXCEPTIONS frontend_not_supported = 1 frontend_error = 2 prog_not_found = 3 no_batch = 4 unspecified_error = 5. IF sy-subrc NE 0. RAISE browser_not_started. ENDIF. ENDIF. CATCH cx_root. CALL FUNCTION 'CALL_BROWSER' EXPORTING url = char_url EXCEPTIONS frontend_not_supported = 1 frontend_error = 2 prog_not_found = 3 no_batch = 4 unspecified_error = 5. IF sy-subrc NE 0. RAISE browser_not_started. ENDIF. ENDTRY. ELSEIF internalmode NE space AND smartclient EQ space. DATA off TYPE i. DATA len TYPE i. FIND REGEX '[Zz]\w+(?=\?)' IN char_url MATCH OFFSET off MATCH LENGTH len . IF sy-subrc = 0. wdy_name = char_url+off(len). PERFORM get_wda_text. ENDIF. IF container_name IS INITIAL. CALL SCREEN 200. ELSE. IF wdr_html_viewer IS INITIAL. PERFORM initialize_viewer USING container_name. ENDIF. PERFORM show_url_in_viewer USING gen_url. ENDIF. ELSEIF internalmode EQ space AND smartclient NE space. CALL METHOD cl_gui_frontend_services=>execute EXPORTING application = 'sapwdgui.exe' parameter = gen_url EXCEPTIONS OTHERS = 99. IF sy-subrc NE 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 RAISING browser_not_started. ENDIF. ELSEIF internalmode NE space AND smartclient NE space. PERFORM get_wda_text. IF container_name IS INITIAL. CALL SCREEN 210. ELSE. PERFORM initialize_smartclient_viewer USING container_name. ENDIF. ENDIF. viewer = wdr_html_viewer. ENDFUNCTION. |
1.2.其中INCLUDE
initialize_viewer,show_url_in_viewer以下下的INCLUDE中定义
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
*----------------------------------------------------------------------* ***INCLUDE LWDY_PRGN_NODESF02 . *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form initialize_viewer *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM initialize_viewer USING container_name TYPE scrfname. DATA: sys_par_val(100) TYPE c. IF container_name IS INITIAL. CREATE OBJECT wdp_html_container EXPORTING container_name = 'HTML'. ELSE. CREATE OBJECT wdp_html_container EXPORTING container_name = container_name. ENDIF. CREATE OBJECT wdr_html_viewer EXPORTING parent = wdp_html_container. IF fscr_mode = abap_true. * CALL METHOD wdr_html_viewer->use_standard_exit * EXPORTING * flag = 'X'. CREATE OBJECT wdr_inplace_handler. set handler wdr_inplace_handler->on_wd_event FOR wdr_html_viewer. ENDIF. CALL 'C_SAPGPARAM' "#EC CI_CCALL ID 'NAME' FIELD 'login/create_sso2_ticket' ID 'VALUE' FIELD sys_par_val. IF sys_par_val < 0. " see SAP note 1562004 MESSAGE s530(swdp_wb_tool). ENDIF. CALL 'C_SAPGPARAM' "#EC CI_CCALL ID 'NAME' FIELD 'login/accept_sso2_ticket' ID 'VALUE' FIELD sys_par_val. IF sys_par_val NE 1. MESSAGE s530(swdp_wb_tool). ENDIF. DATA: icf_node TYPE string VALUE '/sap/public/myssocntl', icf_state TYPE icfactive VALUE 'X'. CALL METHOD cl_icf_tree=>if_icf_tree~service_from_url EXPORTING url = icf_node hostnumber = 0 authority_check = space IMPORTING icfactive = icf_state. IF sy-subrc IS NOT INITIAL OR icf_state IS INITIAL. MESSAGE s531(swdp_wb_tool). ENDIF. DATA: temp_str TYPE string, "#EC NEEDED host TYPE string, host_parts TYPE string_table, host_part TYPE string, i TYPE i. SPLIT gen_url AT '://' INTO temp_str host. SPLIT host AT ':' INTO host temp_str. TRANSLATE host TO LOWER CASE. SPLIT host AT '.' INTO TABLE host_parts. i = LINES( host_parts ). IF i > 0. READ TABLE host_parts INTO host_part INDEX i. CASE host_part. WHEN 'com' OR 'edu' OR 'net' OR 'org' OR 'gov' OR 'mil' OR 'int'. IF LINES( host_parts ) < 2. MESSAGE s532(swdp_wb_tool). ENDIF. WHEN OTHERS. IF LINES( host_parts ) < 3. MESSAGE s532(swdp_wb_tool). ENDIF. ENDCASE. ENDIF. ENDFORM. " initialize_viewer *&---------------------------------------------------------------------* *& Form show_url_in_viewer *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_GEN_URL text *----------------------------------------------------------------------* FORM show_url_in_viewer USING p_url. DATA: url_to_show(100000) TYPE c. url_to_show = p_url. wdr_html_viewer->show_url( url = url_to_show ). cl_gui_cfw=>flush( ). ENDFORM. " show_url_in_viewer *&---------------------------------------------------------------------* *& Form register_smartclient_event *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM register_smartclient_event. DATA: event_tab TYPE cntl_simple_events, p_event TYPE cntl_simple_event. p_event-eventid = 3. "cl_gui_webdynpro_viewer=>eventid_control_info. p_event-appl_event = 'x'. APPEND p_event TO event_tab. CALL METHOD wdp_smartclient_viewer->set_registered_events EXPORTING events = event_tab. ENDFORM. " register_smartclient_event *&---------------------------------------------------------------------* *& Form leave_wdr_html_viewer *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM leave_wdr_html_viewer. wdr_html_viewer->close_document( ). cl_gui_cfw=>flush( ). WAIT UP TO 1 SECONDS. wdr_html_viewer->free( ). CLEAR wdr_html_viewer. wdp_html_container->free( ). CLEAR wdp_html_container. ENDFORM. " leave_wdr_html_viewer *&---------------------------------------------------------------------* *& Form initialize_smartclient_viewer *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_SPACE text *----------------------------------------------------------------------* FORM initialize_smartclient_viewer USING container_name TYPE scrfname.. IF wdp_smartclient_viewer IS INITIAL. IF container_name IS INITIAL. CREATE OBJECT wdp_html_container EXPORTING container_name = 'HTML'. ELSE. CREATE OBJECT wdp_html_container EXPORTING container_name = container_name. ENDIF. CREATE OBJECT wdp_smartclient_viewer EXPORTING parent = wdp_html_container. cl_gui_cfw=>update_view( EXCEPTIONS cntl_system_error = 1 cntl_error = 2 OTHERS = 3 ). ENDIF. IF sy-subrc = 0. PERFORM register_smartclient_event. wdp_smartclient_viewer->navigate( gen_url ). ELSE. MESSAGE e088(st) WITH text-009. ENDIF. ENDFORM. " initialize_smartclient_viewer *&---------------------------------------------------------------------* *& Form leave_wdr_html_viewer *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM leave_wdr_smartclient_viewer. * wdp_smartclient_viewer->close_document( ). * cl_gui_cfw=>flush( ). * WAIT UP TO 1 SECONDS. wdp_smartclient_viewer->free( ). CLEAR wdp_smartclient_viewer. wdp_html_container->free( ). CLEAR wdp_html_container. ENDFORM. " leave_wdr_html_viewer *&---------------------------------------------------------------------* *& Form get_wda_text *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM get_wda_text . DATA: applobj TYPE REF TO object. CLEAR gen_text. TRY. CALL METHOD ('CL_WDY_MD_APPLICATION')=>('GET_OBJECT_BY_KEY') EXPORTING name = wdy_name suppress_access_permission = 'X' RECEIVING application = applobj. CALL METHOD applobj->('IF_WDY_MD_OBJECT~GET_DESCRIPTION') RECEIVING description = gen_text. CATCH cx_wdy_md_not_existing. MESSAGE e088(st) WITH text-001. CATCH cx_wdy_md_permission_failure. MESSAGE e088(st) WITH text-001. ENDTRY. ENDFORM. " get_wda_text *&---------------------------------------------------------------------* *& Form get_wda_text_new *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->E_TEXT text *----------------------------------------------------------------------* form get_wda_text_new changing e_text type bxmnodes-text. types: begin of s_buffer, wdy_name type wdy_application_name, config_id type wdy_config_id, text type bxmnodes-text, end of s_buffer. statics lth_buffer type hashed table of s_buffer with unique key wdy_name config_id. data l_text type wdy_md_description. data ls_buffer type s_buffer. data l_wdy_name type wdy_application_name. data l_config type wdy_config_id. l_wdy_name = wdy_name. TRANSLATE l_wdy_name TO UPPER CASE. l_config = wdy_config. TRANSLATE l_config to UPPER CASE. read table lth_buffer into ls_buffer with table key wdy_name = l_wdy_name config_id = l_config. if sy-subrc <> 0. ls_buffer-wdy_name = l_wdy_name. ls_buffer-config_id = l_config. if wdy_config is initial. select single description from wdy_applicationt into ls_buffer-text where langu = sy-langu and application_name = l_wdy_name. else. select single description from wdy_config_appt into ls_buffer-text where langu = sy-langu and config_id = l_config and config_type = if_wd_config_constants=>c_config_type_appl and config_var = ''. endif. insert ls_buffer into table lth_buffer. endif. e_text = ls_buffer-text. endform. "get_wda_text_new |
1.3.全局变量如下定义
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
FUNCTION-POOL ZWDY_PRGN_NODES MESSAGE-ID SWDP_RUNTIME. * --- Mode constants constants: c_create_mode value 'C', c_edit_mode value 'E', c_display_mode value 'D', c_http value '0', c_https value 'S', c_http_name(4) value 'HTTP', c_https_name(5) value 'HTTPS', c_browser(7) value 'BROWSER', c_run_ext value 'E', c_run_int value 'I', c_run_in_sclient_param(13) value 'sap-wd-run-sc', c_run_auto_detect(18) value 'sap-wd-auto-detect', c_config_param_1(17) value 'WDCONFIGURATIONID', c_config_param_2(15) value 'SAP-WD-CONFIGID'. * --- Screen Elements data: wdy_name type wdy_application_name, "Web-Dynpro-Anw Name wdy_text type bxmnodes-text, "Web-Dynpro-App Beschreibung wdy_config type wdy_config_id, pr_https type c, "Ankreuzfeld fur Protokoll rb_ext type c, "Radiobuttons fur Ausgabenverfahren rb_int type c, rb_browser type c, rb_smcl type c, rb_auto type c, wdy_url like bxmnodes-url, agr_name type agr_name. data param_lin type param_lin. data: i_param type wdy_prgn_name_values. * --- * Handling URL properties data: prop_tab type wdy_app_property_table, prop_lin type line of wdy_app_property_table, predef_prop_tab type wdy_app_prop_def_tab, predef_prop_lin type line of wdy_app_prop_def_tab, avail_prop_tab type table of wdy_param_f4_info, avail_prop_lin type wdy_param_f4_info, field_tab type table of dfies, field_lin type dfies. * Handling transaction screens data: application type rsstcd-para_value, https type rsstcd-para_value, startmode type rsstcd-para_value, wdconfigurationid type rsstcd-para_value, fscr_mode type c. data: gen_url type string, gen_text type string, fmode type c, no_reload type c, new_entry type c, ok_code(20) type c. "exit code * === Toolbar ========== * toolbar global data data: g_appl_type_prop_tab type wdy_pfcg_appl_type_props, g_appl_type_prop like line of g_appl_type_prop_tab, g_toolbar_test_mode type string, * controls for toolbar gr_container_toolbar type ref to cl_gui_custom_container, gr_toolbar type ref to cl_gui_toolbar. * === additional controls controls: param_cntrl type tableview using screen 0100. *----------------------------------------------------------------------* * CLASS cl_wdr_inplace_handler DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class cl_wdr_inplace_handler definition. public section. methods: on_wd_event for event wd_event of cl_gui_wdr_viewer importing action parameters. "#EC NEEDED endclass. "cl_myevent_handler DEFINITION *&---------------------------------------------------------------------* *& Class LCL_EVENT_RECEIVER *&---------------------------------------------------------------------* * Text *----------------------------------------------------------------------* class lcl_toolbar_event_receiver definition. public section. methods set_handler importing activation type wdy_boolean. private section. data: m_menu type ref to cl_ctmenu. methods function_select for event function_selected of cl_gui_toolbar importing fcode sender. methods dropdown for event dropdown_clicked of cl_gui_toolbar importing fcode posx posy sender. endclass. "LCL_TOOLBAR_EVENT_RECEIVER *----------------------------------------------------------------------* * CLASS lcl_toolbar_event_receiver_appl_type DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class lcl_toolbar_event_receiver_app definition. public section. methods on_button_info_changed for event button_info_changed of if_wdy_pfcg_application_type importing fcode icon text quickinfo. methods set_handler importing activation type wdy_boolean. endclass. "lcl_toolbar_event_receiver_appl_type DEFINITION * --- HTML Viewer data: gr_event_receiver type ref to lcl_toolbar_event_receiver, gr_event_receiver_app type ref to lcl_toolbar_event_receiver_app, wdr_html_viewer type ref to cl_gui_wdr_viewer, wdp_smartclient_viewer type ref to cl_gui_webdynpro_viewer, wdp_html_container type ref to cl_gui_custom_container, wdr_inplace_handler type ref to cl_wdr_inplace_handler. |
1.4.创建一个窗口200
1 2 3 4 5 6 7 |
PROCESS BEFORE OUTPUT. MODULE STATUS_0200. MODULE PBO_0200. * PROCESS AFTER INPUT. MODULE EXIT_DYNP_0200 AT EXIT-COMMAND. MODULE USER_COMMAND_0200. |
1.5.PBI,PBO
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 |
*----------------------------------------------------------------------* ***INCLUDE LWDY_PRGN_NODESO02 . *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Module STATUS_0200 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE status_0200 OUTPUT. SET PF-STATUS 'HTMLVIEW'. SET TITLEBAR 'HTMLVIEW' WITH gen_text. ENDMODULE. " STATUS_0200 OUTPUT *&---------------------------------------------------------------------* *& Module PBO_0200 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE pbo_0200 OUTPUT. IF no_reload IS INITIAL. IF wdr_html_viewer IS INITIAL. PERFORM initialize_viewer USING space. ENDIF. PERFORM show_url_in_viewer USING gen_url. ELSE. CLEAR no_reload. ENDIF. ENDMODULE. " PBO_0200 OUTPUT *&---------------------------------------------------------------------* *& Module PBO_0210 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE pbo_0210 OUTPUT. PERFORM initialize_smartclient_viewer USING space. ENDMODULE. " PBO_0210 OUTPUT *&---------------------------------------------------------------------* *& Module SET_TOOLBAR OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module SET_TOOLBAR output. perform set_toolbar. endmodule. " SET_TOOLBAR OUTPUT |
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 |
*----------------------------------------------------------------------* ***INCLUDE LWDY_PRGN_NODESI02 . *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Module EXIT_DYNP_0200 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE EXIT_DYNP_0200 INPUT. CASE ok_code. WHEN 'BACK' OR 'CANC' OR 'EXIT'. CLEAR ok_code. PERFORM leave_wdr_html_viewer. LEAVE TO SCREEN 0. ENDCASE. ENDMODULE. " EXIT_DYNP_0200 INPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_0200 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE USER_COMMAND_0200 INPUT. IF ok_code IS NOT INITIAL. CALL METHOD cl_gui_cfw=>dispatch. ELSE. no_reload = 'X'. ENDIF. CLEAR ok_code. ENDMODULE. " USER_COMMAND_0200 INPUT *&---------------------------------------------------------------------* *& Module EXIT_DYNP_0210 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE EXIT_DYNP_0210 INPUT. CASE ok_code. WHEN 'BACK' OR 'CANC' OR 'EXIT'. CLEAR ok_code. PERFORM leave_wdr_smartclient_viewer. LEAVE TO SCREEN 0. ENDCASE. ENDMODULE. " EXIT_DYNP_0210 INPUT |
2.在IE中打开URL
在上面的函数 中,internalmode EQ space AND smartclient NE space时就会用IE打了
3.用事务码打开Webdynpro
新建立 一个事务码,调用事务码WDYID,并传入APPLICATION = ZWDC_***(WDY的程序名),STARTMODE=BROWSER参数,
4.用事务码打开FIORI APP
新建立 一个事务码,调用事务码/UI2/SAPUI5_APP_FE,并传入UIAD参数,可参考标准事务码F*(比如F0862)