程序执行截图:
代码如下:
1 *&---------------------------------------------------------------------* 2 *& Report Z3426004 3 *&---------------------------------------------------------------------* 4 *& 5 *&---------------------------------------------------------------------* 6 REPORT z3426004. 7 CONSTANTS:gv_pwd TYPE string VALUE 'chen123'. 8 DATA:gv_version TYPE r3state VALUE 'A'. 9 DATA:gv_suffix TYPE string VALUE '.chen'. 10 DATA:go_encry TYPE REF TO cl_hard_wired_encryptor, 11 go_zip TYPE REF TO cl_abap_zip. 12 DATA:gv_code TYPE reposrc-data, 13 gv_filename TYPE string. 14 DATA:BEGIN OF gt_code OCCURS 0, 15 progname TYPE progname, 16 code TYPE TABLE OF string, 17 END OF gt_code. 18 19 PARAMETERS:p_enprog RADIOBUTTON GROUP gp0 DEFAULT 'X' USER-COMMAND u1, 20 p_unprog RADIOBUTTON GROUP gp0. 21 SELECT-OPTIONS:s_prog FOR gt_code-progname DEFAULT 'Z3426003' OBLIGATORY. 22 PARAMETERS:p_file TYPE rlgrap-filename OBLIGATORY DEFAULT 'C:\', 23 p_test TYPE c AS CHECKBOX DEFAULT 'X', 24 p_encode TYPE c AS CHECKBOX DEFAULT 'X'. 25 26 AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. 27 PERFORM frm_file_search CHANGING p_file. 28 29 INITIALIZATION. 30 PERFORM frm_init. 31 32 START-OF-SELECTION. 33 CASE abap_true. 34 WHEN p_enprog. 35 PERFORM frm_check_prog. 36 PERFORM frm_check_filename. 37 PERFORM frm_create_data. 38 PERFORM frm_download_zip. 39 PERFORM frm_encrypt_prog. 40 WHEN p_unprog. 41 PERFORM frm_check_prog. 42 PERFORM frm_check_filename. 43 PERFORM frm_upload_zip. 44 PERFORM frm_install_prog. 45 WHEN OTHERS. 46 ENDCASE. 47 FORM frm_init. 48 DEFINE init_screen_text. 49 %_&1_%_app_%-text = &2. 50 END-OF-DEFINITION. 51 init_screen_text:p_enprog '下载并加密程序', 52 p_unprog '上载并解密程序', 53 s_prog '主程序', 54 p_file '文件路径', 55 p_test '测试运行', 56 p_encode '加密'. 57 CLEAR:gv_code. 58 CREATE OBJECT go_encry. 59 CREATE OBJECT go_zip. 60 ENDFORM. 61 62 FORM frm_check_prog. 63 DATA:lt_code TYPE TABLE OF reposrc-progname, 64 ls_code TYPE reposrc-progname. 65 DATA:lt_tmp TYPE TABLE OF reposrc-progname. 66 DATA:lt_tab TYPE TABLE OF reposrc-progname. 67 68 SELECT progname INTO TABLE @lt_code FROM reposrc WHERE progname IN @s_prog. 69 IF sy-subrc <> 0. 70 MESSAGE s000(db) WITH '程序不存在!'. 71 ENDIF. 72 73 LOOP AT lt_code INTO ls_code. 74 REFRESH:lt_tmp. 75 CALL FUNCTION 'GET_INCLUDETAB' "取包含程序 76 EXPORTING 77 progname = ls_code 78 TABLES 79 incltab = lt_tmp. 80 APPEND LINES OF lt_tmp TO lt_tab. 81 APPEND ls_code TO lt_tab. 82 ENDLOOP. 83 lt_code[] = lt_tab[]. 84 SORT:lt_code. 85 DELETE ADJACENT DUPLICATES FROM lt_code. 86 LOOP AT lt_code ASSIGNING FIELD-SYMBOL(<ls_code>). 87 gt_code-progname = <ls_code>. 88 APPEND gt_code. 89 ENDLOOP. 90 ENDFORM. 91 92 FORM frm_check_filename. 93 IF p_file IS INITIAL. 94 MESSAGE s000(db) WITH '文件路径不能为空!'. 95 ENDIF. 96 ENDFORM. 97 98 FORM frm_create_data. 99 DATA:lt_report TYPE string OCCURS 0 WITH HEADER LINE. 100 DATA:lv_prog TYPE sy-repid. 101 CALL FUNCTION 'RSS_PROGRAM_CREATE' 102 IMPORTING 103 e_program_name = lv_prog. 104 DO 10 TIMES. 105 DATA(lv_str) = `WRITE:ICON_RED_LIGHT,'请不要试图调整激活代码,否则代码丢失,后果自负!!!',/.`. 106 APPEND lv_str TO lt_report. 107 ENDDO. 108 lt_report = `REPORT ` && lv_prog && `.`. 109 INSERT lt_report INDEX 1. 110 DATA:lv_msg TYPE string, 111 lv_line TYPE string, 112 lv_word TYPE string. 113 SYNTAX-CHECK FOR lt_report MESSAGE lv_msg LINE lv_line WORD lv_word. 114 IF sy-subrc <> 0. 115 MESSAGE i888(sapapdocu) WITH lv_msg lv_line lv_word. 116 STOP. 117 ENDIF. 118 INSERT REPORT lv_prog FROM lt_report[] STATE gv_version. 119 CATCH SYSTEM-EXCEPTIONS OTHERS = 1. 120 * SUBMIT (lv_prog) AND RETURN. 121 ENDCATCH. 122 IF sy-subrc = 0. 123 SELECT SINGLE * INTO @DATA(ls_prog) FROM reposrc WHERE progname = @lv_prog. 124 gv_code = ls_prog-data. 125 ENDIF. 126 DELETE REPORT lv_prog STATE gv_version. 127 ENDFORM. 128 129 FORM frm_download_zip. 130 DATA:lv_filename TYPE string, 131 lv_string TYPE string, 132 lv_xstring TYPE xstring, 133 lv_size TYPE i, 134 lt_data TYPE STANDARD TABLE OF raw255, 135 lt_report TYPE string OCCURS 0 WITH HEADER LINE. 136 LOOP AT gt_code. 137 REFRESH:lt_report. 138 * DATA:lt_line TYPE text255 OCCURS 0 WITH HEADER LINE. 139 * CALL FUNCTION 'RPY_PROGRAM_READ' 140 * EXPORTING 141 ** LANGUAGE = SY-LANGU 142 * program_name = gt_code-progname 143 ** WITH_INCLUDELIST = 'X' 144 ** ONLY_SOURCE = ' ' 145 ** ONLY_TEXTS = ' ' 146 ** READ_LATEST_VERSION = ' ' 147 ** WITH_LOWERCASE = ' ' 148 ** IMPORTING 149 ** PROG_INF = 150 ** TABLES 151 ** INCLUDE_TAB = 152 ** SOURCE = 153 * source_extended = lt_line. 154 ** TEXTELEMENTS = 155 ** EXCEPTIONS 156 ** CANCELLED = 1 157 ** NOT_FOUND = 2 158 ** PERMISSION_ERROR = 3 159 ** OTHERS = 4 160 * . 161 162 163 READ REPORT gt_code-progname INTO lt_report STATE gv_version. 164 CLEAR:lv_string. 165 LOOP AT lt_report. 166 TRY. 167 IF p_encode = abap_true. 168 lt_report = lt_report && gv_pwd. 169 lt_report = go_encry->encrypt_string2string( the_string = lt_report ). 170 ENDIF. 171 lv_string = lv_string && lt_report && cl_abap_char_utilities=>cr_lf. 172 CATCH cx_root INTO DATA(lo_error). 173 ENDTRY. 174 ENDLOOP. 175 CLEAR:lv_xstring. 176 CALL FUNCTION 'SCMS_STRING_TO_XSTRING' 177 EXPORTING 178 text = lv_string 179 mimetype = 'text/html;chartset=gbk' 180 IMPORTING 181 buffer = lv_xstring 182 EXCEPTIONS 183 failed = 1 184 OTHERS = 2. 185 lv_filename = gt_code-progname && gv_suffix. 186 go_zip->add( name = lv_filename content = lv_xstring ). 187 188 lv_xstring = go_zip->save( ). 189 REFRESH:lt_data. 190 CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' 191 EXPORTING 192 buffer = lv_xstring 193 IMPORTING 194 output_length = lv_size 195 TABLES 196 binary_tab = lt_data. 197 ENDLOOP. 198 lv_filename = p_file. 199 CALL METHOD cl_gui_frontend_services=>gui_download 200 EXPORTING 201 bin_filesize = lv_size 202 filename = lv_filename 203 filetype = 'BIN' 204 CHANGING 205 data_tab = lt_data. 206 207 ENDFORM. 208 209 FORM frm_upload_zip. 210 DATA:lv_filename TYPE string, 211 lv_string TYPE string, 212 lv_xstring TYPE xstring, 213 lv_size TYPE i, 214 lt_data TYPE STANDARD TABLE OF raw255, 215 lt_report TYPE string OCCURS 0 WITH HEADER LINE. 216 REFRESH:gt_code. 217 lv_filename = p_file. 218 CALL METHOD cl_gui_frontend_services=>gui_upload 219 EXPORTING 220 filename = lv_filename 221 filetype = 'BIN' 222 IMPORTING 223 filelength = lv_size 224 CHANGING 225 data_tab = lt_data. 226 CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' 227 EXPORTING 228 input_length = lv_size 229 IMPORTING 230 buffer = lv_xstring 231 TABLES 232 binary_tab = lt_data. 233 234 go_zip->load( zip = lv_xstring ). 235 LOOP AT go_zip->files INTO DATA(ls_files). 236 CLEAR:lv_xstring. 237 go_zip->get( EXPORTING name = ls_files-name IMPORTING content = lv_xstring ). 238 REFRESH:lt_data. 239 CLEAR:lv_size. 240 241 CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' 242 EXPORTING 243 buffer = lv_xstring 244 IMPORTING 245 output_length = lv_size 246 TABLES 247 binary_tab = lt_data. 248 249 CALL FUNCTION 'SCMS_BINARY_TO_STRING' 250 EXPORTING 251 input_length = lv_size 252 mimetype = 'text/html;chartset=gbk' 253 * ENCODING = 254 IMPORTING 255 text_buffer = lv_string 256 TABLES 257 binary_tab = lt_data. 258 SPLIT lv_string AT cl_abap_char_utilities=>cr_lf INTO TABLE lt_report. 259 LOOP AT lt_report. 260 TRY. 261 IF p_encode = abap_true. 262 lt_report = go_encry->decrypt_string2string( the_string = lt_report ). 263 IF lt_report NA gv_pwd. 264 MESSAGE s000(db) WITH '压缩文件格式不正确,安装程序失败!'. 265 STOP. 266 ELSE. 267 REPLACE ALL OCCURRENCES OF gv_pwd IN lt_report WITH ''. 268 ENDIF. 269 ENDIF. 270 CATCH cx_root INTO DATA(lo_error). 271 IF lt_report NA gv_pwd. 272 MESSAGE s000(db) WITH '压缩文件格式不正确,安装程序失败!'. 273 STOP. 274 ENDIF. 275 ENDTRY. 276 MODIFY lt_report. 277 ENDLOOP. 278 REPLACE ALL OCCURRENCES OF gv_suffix IN ls_files-name WITH ''. 279 gt_code-progname = ls_files-name. 280 gt_code-code = lt_report[]. 281 APPEND gt_code. 282 ENDLOOP. 283 284 ENDFORM. 285 286 FORM frm_install_prog. 287 LOOP AT gt_code. 288 IF p_test = abap_false. 289 INSERT REPORT gt_code-progname FROM gt_code-code STATE gv_version. 290 ENDIF. 291 IF sy-subrc = 0. 292 WRITE:icon_green_light,sy-tabix,'程序:',gt_code-progname,'处理成功!',/. 293 ELSE. 294 WRITE:icon_red_light,sy-tabix,'程序:',gt_code-progname,'处理失败!',/. 295 ENDIF. 296 ENDLOOP. 297 ENDFORM. 298 299 FORM frm_encrypt_prog. 300 DATA:lv_str TYPE string, 301 lo_sql TYPE REF TO cl_sql_statement, 302 lx_sql TYPE REF TO cx_sql_exception, 303 lo_result TYPE REF TO cl_sql_result_set, 304 lv_uflag TYPE i VALUE 1, 305 lv_dbname TYPE dbcon_name, 306 lv_dbuser TYPE dbcon_uid, 307 lv_dbtab TYPE tabname. 308 DATA:e TYPE REF TO cx_root, 309 err_text TYPE string. 310 TRY . 311 lv_dbname = 'DEFAULT'. 312 SELECT SINGLE schemaname INTO lv_dbuser FROM db6navsyst WHERE sysid = sy-sysid. 313 lv_dbtab = 'REPOSRC'. 314 CREATE OBJECT lo_sql EXPORTING con_ref = cl_sql_connection=>get_connection( lv_dbname ). 315 lv_dbtab = lv_dbuser && `.` && lv_dbtab. 316 LOOP AT gt_code. 317 lv_str = `UPDATE ` && lv_dbtab && ` SET DATA = '` && gv_code && `' WHERE PROGNAME = '` && gt_code-progname && `'`. 318 IF p_test = abap_false. 319 lv_uflag = lo_sql->execute_update( lv_str ). 320 ENDIF. 321 IF lv_uflag = 1. 322 WRITE:icon_green_light,sy-tabix,'程序:',gt_code-progname,'处理成功!',/. 323 ELSE. 324 WRITE:icon_red_light,sy-tabix,'程序:',gt_code-progname,'处理失败!',/. 325 ENDIF. 326 ENDLOOP. 327 CATCH cx_root INTO e. 328 err_text = e->get_text( ). 329 WRITE:icon_red_light,err_text. 330 ENDTRY. 331 ENDFORM. 332 333 FORM frm_file_search CHANGING p_file. 334 * DATA:lv_filename TYPE string. 335 * CALL METHOD cl_salv_test_data=>select_file 336 * IMPORTING 337 * filename = lv_filename. 338 * p_file = lv_filename. 339 DATA: l_rc TYPE i, 340 l_filetable TYPE filetable. 341 IF p_unprog = abap_true. 342 CALL METHOD cl_gui_frontend_services=>file_open_dialog 343 EXPORTING 344 window_title = '请选择导入文件' 345 * file_filter = cl_gui_frontend_services=>filetype_excel 346 file_filter = '(*.ZIP)|*.ZIP|' 347 multiselection = space 348 CHANGING 349 file_table = l_filetable 350 rc = l_rc 351 EXCEPTIONS 352 file_open_dialog_failed = 1 353 cntl_error = 2 354 error_no_gui = 3 355 not_supported_by_gui = 4 356 OTHERS = 5. 357 358 IF sy-subrc = 0 AND l_rc = 1. 359 READ TABLE l_filetable INTO p_file INDEX 1. 360 ENDIF. 361 ENDIF. 362 IF p_enprog = abap_true. 363 DATA:lv_filename TYPE string, 364 lv_path TYPE string, 365 lv_fullfilepath TYPE string. 366 CALL METHOD cl_gui_frontend_services=>file_save_dialog 367 EXPORTING 368 window_title = '请选择保存文件' 369 * file_filter = cl_gui_frontend_services=>filetype_excel 370 file_filter = '(*.ZIP)|*.ZIP|' 371 CHANGING 372 filename = lv_filename 373 path = lv_path 374 fullpath = lv_fullfilepath 375 EXCEPTIONS 376 cntl_error = 1 377 error_no_gui = 2 378 not_supported_by_gui = 3 379 invalid_default_file_name = 4 380 OTHERS = 5. 381 p_file = lv_fullfilepath. 382 ENDIF. 383 ENDFORM.