sap的代码备份一直是个头疼地事情,以前那种下载代码最终只能是txt或者html网页形式展示,倒是可以本地查看,但是换到其他系统想要复用就是件难事了。今天分享个按照请求打包下载sap对象的程序。
代码如下
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 |
*&---------------------------------------------------------------------* *& Report ZST_TRANS_DOWN *======================================================================* * Initial idea and first release by Igor Yaskevitch (IBS), 2003 * * Enhancements by Sergey Korolev, 2005 (Added F4 value * * requests, authority checks, TMS function usage) * *----------------------------------------------------------------------* * Function : This is a utility tool for downloading binary * * files of transport request to a Client PC * *======================================================================* REPORT zst_trans_down. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 1(35) text_999 FOR FIELD p_reqest. PARAMETERS: p_reqest TYPE trkorr OBLIGATORY. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 1(35) text_998 FOR FIELD p_folder. PARAMETERS: p_folder(255) TYPE c LOWER CASE. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 1(35) text_997 FOR FIELD p_sepr. PARAMETERS: p_sepr OBLIGATORY. SELECTION-SCREEN END OF LINE. *parameters: * p_reqest type trkorr obligatory, * p_folder(255) type c lower case, * p_sepr obligatory. DATA: folder TYPE string, retval LIKE TABLE OF ddshretval WITH HEADER LINE, fldvalue LIKE help_info-fldvalue, transdir TYPE text255, filename(255), trfile(20) TYPE c, * datatab TYPE TABLE OF text8192 WITH HEADER LINE, BEGIN OF datatab OCCURS 0, text(8192) TYPE x, END OF datatab, len TYPE i, flen TYPE i. TYPE-POOLS: sabc, stms, trwbo. INITIALIZATION. text_999 = '请求号'. text_998 = '选择文件夹'. text_997 = '文件路径符号'. CONCATENATE sy-sysid 'K*' INTO p_reqest. IF sy-opsys = 'Windows NT'. p_sepr = '\'. ELSE. p_sepr = '/'. ENDIF. * CALL FUNCTION 'WSAF_BUILD_SEPARATOR' * IMPORTING * separator = p_sepr * EXCEPTIONS * separator_not_maintained = 1 * wrong_call = 2 * wsaf_config_not_maintained = 3 * OTHERS = 4. * * IF sy-subrc NE 0. * MESSAGE s001(00) * WITH * 'Unable to find out the separator symbol for the system.'(011). * ENDIF. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_reqest. DATA: tt_system TYPE TABLE OF tmscsys WITH HEADER LINE, es_selected_request TYPE trwbo_request_header, es_selected_task TYPE trwbo_request_header, iv_organizer_type TYPE trwbo_calling_organizer, is_selection TYPE trwbo_selection. iv_organizer_type = 'W'. is_selection-reqstatus = 'R'. CALL FUNCTION 'TR_PRESENT_REQUESTS_SEL_POPUP' EXPORTING iv_organizer_type = iv_organizer_type is_selection = is_selection IMPORTING es_selected_request = es_selected_request es_selected_task = es_selected_task. p_reqest = es_selected_request-trkorr. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_folder. DATA: title TYPE string. title = '选择目标文件夹'(005)."'Select target folder CALL METHOD cl_gui_frontend_services=>directory_browse EXPORTING window_title = title CHANGING selected_folder = folder EXCEPTIONS cntl_error = 1 error_no_gui = 2 OTHERS = 3. CALL FUNCTION 'CONTROL_FLUSH' EXCEPTIONS cntl_system_error = 1 cntl_error = 2 OTHERS = 3. p_folder = folder. AT SELECTION-SCREEN ON p_reqest. DATA: request_info TYPE stms_wbo_request, request_infos TYPE stms_wbo_requests. REFRESH request_infos. CALL FUNCTION 'TMS_MGR_READ_TRANSPORT_REQUEST' EXPORTING iv_request = p_reqest iv_header_only = 'X' IMPORTING et_request_infos = request_infos EXCEPTIONS read_config_failed = 1 table_of_requests_is_empty = 2 system_not_available = 3 OTHERS = 4. 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 request_info. READ TABLE request_infos INTO request_info INDEX 1. IF sy-subrc NE 0 OR request_info-e070-trkorr IS INITIAL. MESSAGE e398(00) WITH '请求号'(006) p_reqest '未找到'(007)."Request not found ELSEIF request_info-e070-trstatus NE 'R'. MESSAGE e398(00) WITH '您必须释放请求'(008)"You must release request request_info-e070-trkorr '下载前'(009)."'before downloading ENDIF. START-OF-SELECTION. folder = p_folder. CONCATENATE p_reqest+3(7) '.' p_reqest(3) INTO trfile. CALL FUNCTION 'RSPO_R_SAPGPARAM' EXPORTING name = 'DIR_TRANS' IMPORTING value = transdir EXCEPTIONS error = 0 thers = 0. PERFORM copy_file USING 'cofiles' trfile. trfile(1) = 'R'. PERFORM copy_file USING 'data' trfile. trfile(1) = 'D'. PERFORM copy_file USING 'data' trfile. *---------------------------------------------------------------------* * FORM copy_file * *---------------------------------------------------------------------* * --> SUBDIR * * --> FNAME * *---------------------------------------------------------------------* FORM copy_file USING subdir fname. DATA: auth_filename TYPE authb-filename, gui_filename TYPE string. CONCATENATE transdir subdir fname INTO filename SEPARATED BY p_sepr. REFRESH datatab. CLEAR flen. auth_filename = filename. CALL FUNCTION 'AUTHORITY_CHECK_DATASET' EXPORTING activity = sabc_act_read filename = auth_filename EXCEPTIONS no_authority = 1 activity_unknown = 2 OTHERS = 3. IF sy-subrc <> 0. FORMAT COLOR COL_NEGATIVE. WRITE: / 'Read access denied. File'(001), filename. FORMAT COLOR OFF. EXIT. ENDIF. OPEN DATASET filename FOR INPUT IN BINARY MODE. IF sy-subrc NE 0. FORMAT COLOR COL_TOTAL. WRITE: / 'File open error'(010), filename. FORMAT COLOR OFF. EXIT. ENDIF. CLEAR flen. DATA: mlen TYPE i. mlen = 8192. DO. CLEAR len. READ DATASET filename INTO datatab MAXIMUM LENGTH mlen LENGTH len. flen = flen + len. IF len > 0. APPEND datatab. ENDIF. IF sy-subrc NE 0. EXIT. ENDIF. ENDDO. CLOSE DATASET filename. CONCATENATE p_folder '\' fname INTO gui_filename. CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING bin_filesize = flen filename = gui_filename filetype = 'BIN' CHANGING data_tab = datatab[] EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 24. IF sy-subrc = 0. WRITE: / 'File'(002), filename, 'downloaded. Length'(003), flen. ELSE. FORMAT COLOR COL_NEGATIVE. WRITE: / 'File download error. Filename:'(004), filename. FORMAT COLOR OFF. ENDIF. ENDFORM . |
注意事项
就是个SE38的程序。复制粘贴,直接运行。选择本地存储文件夹后给信任,下载请求到本地