Fork me on GitHub

批量解压上传SAP Note

最近在做印度GST相关的东西,需要手动给系统实施上百个SAP Note,十分繁琐。

标准事务代码SNOTE只支持每次上传一个Note,逐个上传大量Note会很麻烦,为此摸索出一个批量解压上传的流程,下面是细节。

本文链接:https://www.cnblogs.com/hhelibeb/p/17548517.html

0,去SAP网站下载Note文件

1,准备好SAR文件,如 '0002407980_00.SAR',把所有SAR文件放到同一个目录下。

2,在相同目录内,放置SAPCAR.EXE解压程序。新建批处理程序xxx.bat,写入以下代码并运行:

@echo off
setlocal

for %%f in (*.SAR) do (
    SAPCAR -xvf "%%f"
)

for %%f in (*.ZIP) do (
    tar -xf "%%f"
)

endlocal

 

这是ChatGPT提供的代码,可以解压当前目录下的SAR文件,具体功能解释如下,

  • @echo off 命令用于关闭命令的回显,使输出更清晰。
  • setlocalendlocal命令用于限制变量的范围,防止它们影响到其他的脚本和环境。
  • for %%f in (*.SAR) do这一行是一个for循环,它会遍历当前目录中所有的.SAR文件。每次迭代中,%%f变量都会包含一个文件名。
  • SAPCAR -xvf "%%f"这一行调用SAPCAR命令,并将当前文件名作为参数。%%f将被替换为实际的文件名。
  • 同理,下一个for遍历目录中所有的.ZIP文件并解压。

(注意,旧版windows可能不支持tar,但这并不要紧,只需要手动全选ZIP文件并解压即可。)

3,步骤2完成后,目录中出现解压得到的TXT文件,可以用于上传。

4,登陆你希望实施Note的SAP系统,运行程序 ZSCWN_NOTES_UPLOAD,选择上文中存放Note的目录,选择全部TXT文件,上传。

如果Note数量多的话,需要耐心等待一段时间,直到程序运行结束。之后,进入事务代码SNOTE,就可以看到批量上传的全部Note已经被加载到SNOTE中。

 

ZSCWN_NOTES_UPLOAD 的作者是Frank Buchholz,原文:Report ZSCWN_NOTES_UPLOAD – Load multiple notes files into SNOTE

为了防止链接失效,在下面贴出代码,

  1 *&---------------------------------------------------------------------*
  2 *& Report  ZSCWN_NOTES_UPLOAD
  3 *& Load multiple notes files into SNOTE
  4 *&---------------------------------------------------------------------*
  5 *&
  6 *& Reference:
  7 *& Security Patch Process FAQ
  8 *& http://scn.sap.com/community/security/blog/2012/03/27/security-patch-process-faq#23_What_should_I_do_if_I_cannot_download_a_note_into_SNOTE
  9 *& 23. What should I do if I cannot download a note into SNOTE?
 10 *&
 11 *& Sometimes you run into trouble while downloading large notes in transaction SNOTE, like for the security note 1826162 from July 2013. (In addition this note requires another large note 1674132, too.)
 12 *&
 13 *& In such a case use the download basket to get the note:
 14 *&
 15 *& 1. Show the note on SMP, e.g. https://service.sap.com/sap/support/notes/1826162
 16 *& 2. Use the button "Download Corrections". You get a new window showing a log.
 17 *& 3. Repeat 1. and 2. for more notes, e.g. note 1826162 requires other note 1674132
 18 *& 4. Use the button "Download Basket" on the log window to show your basket
 19 *& 5. Click on every link for the selected notes to download the file via the internet browser (You could try to use the SAP Download Manager, however, this might not work as it uses the same interface like SNOTE.)
 20 *& 6. Un-zip the archive files which you have downloaded
 21 *& 7. In transaction SNOTE use the menu path Goto->Upload note to load the note(s) one by one
 22 *& 8. Implement the note as usual
 23 *&
 24 *& Another advantage is, that you can use the same files for uploading notes into several development systems
 25 *&
 26 *& 19.08.2013 Initial version based on function SCWN_NOTE_UPLOAD_INTERNAL which allows the upload of a single file
 27 *&
 28 *&---------------------------------------------------------------------*
 29 
 30 REPORT  ZSCWN_NOTES_UPLOAD.
 31 
 32 constants: c_program_version(15) type c value '19.08.2013'.
 33 
 34 selection-screen begin of line.
 35 selection-screen comment 1(32) T_PATH for field s_path.
 36 parameters: s_path type string LOWER CASE.
 37 selection-screen end of line.
 38 
 39 SELECTION-SCREEN COMMENT 1(60) ss_vers.
 40 
 41 *----------------------------------------------------------------------*
 42 
 43 INITIALIZATION.
 44 * Authorization check according to report SCWN_ENTRY_TREE (=SNOTE)
 45   CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
 46     EXPORTING
 47       tcode  = 'SNOTE'
 48     EXCEPTIONS
 49       ok     = 0
 50       not_ok = 1
 51       OTHERS = 2.
 52 
 53   IF sy-subrc <> 0.
 54 *     All messages raised from authority_check_tcode means:
 55 *     'This transaction can or should not be started.'
 56     MESSAGE i775(scwn) WITH 'SNOTE'.
 57     LEAVE PROGRAM.
 58   ENDIF.
 59 
 60   T_PATH  = 'Local path with text files'(000).
 61 
 62   concatenate 'Program version from'(000) c_program_version into SS_VERS
 63     SEPARATED BY SPACE.
 64 
 65 * Get default download path
 66   data l_UPLOAD_PATH type string.
 67   CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_UPLOAD_DOWNLOAD_PATH
 68     CHANGING
 69       UPLOAD_PATH                 = l_UPLOAD_PATH
 70       DOWNLOAD_PATH               = s_path
 71     EXCEPTIONS
 72       CNTL_ERROR                  = 1
 73       ERROR_NO_GUI                = 2
 74       NOT_SUPPORTED_BY_GUI        = 3
 75       GUI_UPLOAD_DOWNLOAD_PATH    = 4
 76       UPLOAD_DOWNLOAD_PATH_FAILED = 5
 77       others                      = 6.
 78   IF SY-SUBRC <> 0.
 79 * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
 80 *            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 81   ENDIF.
 82 
 83 *----------------------------------------------------------------------*
 84 
 85 START-OF-SELECTION.
 86 
 87   data: lv_file_filter    TYPE string,
 88         lv_filename       TYPE string,
 89         lv_file_table     TYPE filetable,
 90         lv_rc             TYPE i,
 91         lv_user_action    TYPE i,
 92         lv_file           TYPE LINE OF filetable,
 93         lv_title          TYPE string.
 94   data: lt_cont           LIKE cwbdata OCCURS 0,
 95         lv_FILELENGTH     type i.
 96 
 97 * dialog for file
 98   CLASS cl_gui_frontend_services DEFINITION LOAD.
 99 * Definition of file types see text elements of class CL_GUI_FRONTEND_SERVICES
100   lv_file_filter = cl_gui_frontend_services=>FILETYPE_TEXT.
101   lv_title = 'Upload SAP Note'(100).
102 
103 * Ask for list of files
104   CALL METHOD cl_gui_frontend_services=>file_open_dialog
105     EXPORTING
106       window_title      = lv_title
107       INITIAL_DIRECTORY = s_path
108 *     default_filename  =  lv_filename
109       file_filter       = lv_file_filter
110       multiselection    = 'X'
111     CHANGING
112       file_table        = lv_file_table
113       rc                = lv_rc
114       user_action       = lv_user_action
115     EXCEPTIONS
116       OTHERS            = 1.
117 
118   IF sy-subrc <> 0 OR lv_rc <= 0.
119     EXIT.
120   ENDIF.
121 
122   IF lv_user_action = cl_gui_frontend_services=>action_cancel.
123     MESSAGE s020(scwn).
124     EXIT.
125   ENDIF.
126 
127 * process files
128   data: lv_lines   type i,
129         lv_percent type i,
130         lv_message(132).
131   describe table lv_file_table lines lv_lines.
132   loop at lv_file_table into lv_filename.
133 
134     lv_percent = 100 * sy-tabix / lv_lines.
135     concatenate 'Read file'(002) lv_filename into lv_message SEPARATED BY space.
136     CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
137       EXPORTING
138         PERCENTAGE = lv_percent
139         TEXT       = lv_message.
140 
141 *   Read file
142     CALL FUNCTION 'GUI_UPLOAD'
143       EXPORTING
144         filename                = lv_filename
145         FILETYPE                = 'ASC'
146       IMPORTING
147         FILELENGTH              = lv_FILELENGTH
148       TABLES
149         data_tab                = lt_cont
150       EXCEPTIONS
151         file_open_error         = 1
152         file_read_error         = 2
153         no_batch                = 3
154         gui_refuse_filetransfer = 4
155         invalid_type            = 5
156         no_authority            = 6
157         unknown_error           = 7
158         bad_data_format         = 8
159         header_not_allowed      = 9
160         separator_not_allowed   = 10
161         header_too_long         = 11
162         unknown_dp_error        = 12
163         access_denied           = 13
164         dp_out_of_memory        = 14
165         disk_full               = 15
166         dp_timeout              = 16
167         OTHERS                  = 17.
168 
169     IF sy-subrc <> 0.
170       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
171               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
172     ENDIF.
173 
174 *   Process file
175     perform scwn_note_upload_internal
176       tables lt_cont.
177 
178   endloop.
179 
180   message 'Files loaded'(003) type 'S'.
181 
182 *FUNCTION scwn_note_upload_internal.
183 *"----------------------------------------------------------------------
184 *"*"Lokale Schnittstelle:
185 *"  EXCEPTIONS
186 *"      INCOMPATIBLE_VERSIONS
187 *"      CORRUPT_DATA_FILE
188 *"----------------------------------------------------------------------
189 constants: true type  BCWBN_BOOL value 'X',
190            false type BCWBN_BOOL value space.
191 *
192 FORM scwn_note_upload_internal
193     tables lt_cont. "       LIKE cwbdata OCCURS 0.
194 
195   FIELD-SYMBOLS: <ls_cwbnthead> TYPE cwbnthead.
196 
197   DATA: lv_cancel,
198         lv_filetype   LIKE rlgrap-filetype,
199 *        lt_cont       LIKE cwbdata OCCURS 0,
200         lt_cwbnthead  LIKE cwbnthead OCCURS 0,
201         lt_cwbntstxt  LIKE cwbntstxt OCCURS 0,
202         lt_cwbntdata  TYPE bcwbn_note_text OCCURS 0,
203         lt_cwbntvalid LIKE cwbntvalid OCCURS 0,
204         lt_cwbntci    LIKE cwbntci OCCURS 0,
205         lt_cwbntfixed LIKE cwbntfixed OCCURS 0,
206         lt_cwbntgattr LIKE cwbntgattr OCCURS 0,
207         lt_cwbcihead  LIKE cwbcihead OCCURS 0,
208         lt_cwbcidata  TYPE bcwbn_cinst_delta OCCURS 0,
209         lt_cwbcivalid LIKE cwbcivalid OCCURS 0,
210         lt_cwbciinvld LIKE cwbciinvld OCCURS 0,
211         lt_cwbcifixed LIKE cwbcifixed OCCURS 0,
212         lt_cwbcidpndc LIKE cwbcidpndc OCCURS 0,
213         lt_cwbciobj   LIKE cwbciobj OCCURS 0,
214         lt_cwbcmpnt   LIKE cwbcmpnt OCCURS 0,
215         lt_cwbcmtext  LIKE cwbcmtext OCCURS 0,
216         lt_cwbcmlast  LIKE cwbcmlast OCCURS 0,
217         lt_cwbdehead  LIKE cwbdehead OCCURS 0,
218         lt_cwbdeprdc  LIKE cwbdeprdc OCCURS 0,
219         lt_cwbdetrack LIKE cwbdetrack OCCURS 0,
220         lt_cwbdeequiv LIKE cwbdeequiv OCCURS 0,
221         lt_cwbcidata_ref TYPE cwb_deltas,
222 *        lv_file_filter   TYPE string,
223 *        lv_filename TYPE string,
224 *        lv_file_table TYPE filetable,
225 *        lv_rc TYPE i,
226 *        lv_user_action TYPE i,
227         lv_file TYPE LINE OF filetable,
228 *        lv_title TYPE string,
229         ls_note TYPE bcwbn_note,
230         lt_notes TYPE bcwbn_notes,
231         ls_cwbnthead LIKE cwbnthead.
232 
233   DATA: lv_data_bin        TYPE xstring,
234         lv_code_delta_bin  TYPE xstring,
235         lt_object_data_bin TYPE cwbci_t_objdelta,
236         ls_numm_versno     TYPE cwbntkeyvs.
237 
238 ** dialog for file
239 *  CLASS cl_gui_frontend_services DEFINITION LOAD.
240 *  lv_file_filter = cl_gui_frontend_services=>filetype_all.
241 *  lv_title = text-100.
242 *
243 *  CALL METHOD cl_gui_frontend_services=>file_open_dialog
244 *    EXPORTING
245 *      window_title     = lv_title
246 *      default_filename = lv_filename
247 *      file_filter      = lv_file_filter
248 *    CHANGING
249 *      file_table       = lv_file_table
250 *      rc               = lv_rc
251 *      user_action      = lv_user_action
252 *    EXCEPTIONS
253 *      OTHERS           = 1.
254 *
255 *  IF sy-subrc <> 0 OR lv_rc <= 0.
256 *    EXIT.
257 *  ENDIF.
258 *
259 *  IF lv_user_action = cl_gui_frontend_services=>action_cancel.
260 *    MESSAGE s020(scwn).
261 *    EXIT.
262 *  ENDIF.
263 *
264 ** upload file
265 *  READ TABLE lv_file_table INTO lv_file INDEX 1.
266 *  lv_filename = lv_file-filename.
267 *
268 *  CALL FUNCTION 'GUI_UPLOAD'
269 *    EXPORTING
270 *      filename                = lv_filename
271 *    TABLES
272 *      data_tab                = lt_cont_bin
273 *    EXCEPTIONS
274 *      file_open_error         = 1
275 *      file_read_error         = 2
276 *      no_batch                = 3
277 *      gui_refuse_filetransfer = 4
278 *      invalid_type            = 5
279 *      no_authority            = 6
280 *      unknown_error           = 7
281 *      bad_data_format         = 8
282 *      header_not_allowed      = 9
283 *      separator_not_allowed   = 10
284 *      header_too_long         = 11
285 *      unknown_dp_error        = 12
286 *      access_denied           = 13
287 *      dp_out_of_memory        = 14
288 *      disk_full               = 15
289 *      dp_timeout              = 16
290 *      OTHERS                  = 17.
291 *
292 *  IF sy-subrc <> 0.
293 *    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
294 *            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
295 *  ENDIF.
296 
297   CALL FUNCTION 'SCWN_NOTE_UNPACK'
298     IMPORTING
299       ev_data_bin           = lv_data_bin
300       ev_code_delta_bin     = lv_code_delta_bin
301       et_object_data_bin    = lt_object_data_bin
302     TABLES
303       tt_cont               = lt_cont
304     EXCEPTIONS
305       incompatible_versions = 1
306       corrupt_data_file     = 2
307       OTHERS                = 3.
308 
309   IF sy-subrc <> 0.
310     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
311             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
312   ENDIF.
313 
314   CALL FUNCTION 'SCWN_NOTE_UNPACK_XML'
315     EXPORTING
316       iv_data_bin           = lv_data_bin
317       iv_code_delta_bin     = lv_code_delta_bin
318       it_object_data_bin    = lt_object_data_bin
319     IMPORTING
320       et_cwbnthead          = lt_cwbnthead
321       et_cwbntstxt          = lt_cwbntstxt
322       et_cwbntdata          = lt_cwbntdata
323       et_cwbntvalid         = lt_cwbntvalid
324       et_cwbntci            = lt_cwbntci
325       et_cwbntfixed         = lt_cwbntfixed
326       et_cwbntgattr         = lt_cwbntgattr
327       et_cwbcihead          = lt_cwbcihead
328       et_cwbcidata          = lt_cwbcidata
329       et_cwbcidata_ref      = lt_cwbcidata_ref
330       et_cwbcivalid         = lt_cwbcivalid
331       et_cwbciinvld         = lt_cwbciinvld
332       et_cwbcifixed         = lt_cwbcifixed
333       et_cwbcidpndc         = lt_cwbcidpndc
334       et_cwbciobj           = lt_cwbciobj
335       et_cwbcmpnt           = lt_cwbcmpnt
336       et_cwbcmtext          = lt_cwbcmtext
337       et_cwbcmlast          = lt_cwbcmlast
338       et_cwbdehead          = lt_cwbdehead
339       et_cwbdeprdc          = lt_cwbdeprdc
340       et_cwbdetrack         = lt_cwbdetrack
341       et_cwbdeequiv         = lt_cwbdeequiv
342     EXCEPTIONS
343       corrupt_data_file     = 1
344       incompatible_versions = 2
345       OTHERS                = 3.
346   IF sy-subrc <> 0.
347     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
348             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
349             RAISING corrupt_data_file.
350   ENDIF.
351 
352 * store note
353   CALL FUNCTION 'SCWN_NOTE_STORE'
354     EXPORTING
355       it_cwbcmpnt      = lt_cwbcmpnt
356       it_cwbdetrack    = lt_cwbdetrack
357       it_cwbdehead     = lt_cwbdehead
358       it_cwbdeequiv    = lt_cwbdeequiv
359     TABLES
360       tt_cwbnthead     = lt_cwbnthead
361       tt_cwbntstxt     = lt_cwbntstxt
362       tt_cwbntdata     = lt_cwbntdata
363       tt_cwbntvalid    = lt_cwbntvalid
364       tt_cwbntci       = lt_cwbntci
365       tt_cwbntfixed    = lt_cwbntfixed
366       tt_cwbntgattr    = lt_cwbntgattr
367       tt_cwbcihead     = lt_cwbcihead
368       tt_cwbcidata     = lt_cwbcidata
369       tt_cwbcidata_ref = lt_cwbcidata_ref
370       tt_cwbcivalid    = lt_cwbcivalid
371       tt_cwbciinvld    = lt_cwbciinvld
372       tt_cwbcifixed    = lt_cwbcifixed
373       tt_cwbcidpndc    = lt_cwbcidpndc
374       tt_cwbciobj      = lt_cwbciobj
375     EXCEPTIONS
376       failure          = 1
377       OTHERS           = 2.
378 
379   IF sy-subrc <> 0.
380     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
381             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
382   ELSE.
383 *   store each stored note in download history
384     LOOP AT lt_cwbnthead ASSIGNING <ls_cwbnthead>.
385       ls_numm_versno-numm = <ls_cwbnthead>-numm.
386       ls_numm_versno-versno = <ls_cwbnthead>-versno.
387       CALL FUNCTION 'SCWN_NOTE_DOWNLOAD_HIST'
388         EXPORTING
389           is_note_version = ls_numm_versno
390           iv_mode_write   = true
391         EXCEPTIONS
392           OTHERS          = 1.
393       IF sy-subrc <> 0.
394         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
395                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
396       ENDIF.
397     ENDLOOP.
398   ENDIF.
399 
400 * update software component if necessary
401   CALL FUNCTION 'SCWN_UPDATE_SOFTWARE_COMPONENT'
402     TABLES
403       tt_cwbcmpnt   = lt_cwbcmpnt
404       tt_cwbcmtext  = lt_cwbcmtext
405       tt_cwbcmlast  = lt_cwbcmlast
406       tt_cwbdehead  = lt_cwbdehead
407       tt_cwbdeprdc  = lt_cwbdeprdc
408       tt_cwbdetrack = lt_cwbdetrack
409       tt_cwbdeequiv = lt_cwbdeequiv
410     EXCEPTIONS
411       failure       = 1
412       OTHERS        = 2.
413 
414   IF sy-subrc <> 0.
415     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
416             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
417   ENDIF.
418 
419 * classify notes
420   LOOP AT lt_cwbnthead INTO ls_cwbnthead.
421     ls_note-key-numm = ls_cwbnthead-numm.
422     ls_note-key-versno = ls_cwbnthead-versno.
423     APPEND ls_note TO lt_notes.
424   ENDLOOP.
425 
426   CALL FUNCTION 'SCWB_NOTES_CLASSIFY'
427     EXPORTING
428       it_notes        = lt_notes
429       iv_set_ntstatus = ' '.
430 
431 ENDFORM.
432 *ENDFUNCTION.
ZSCWN_NOTES_UPLOAD

 

posted @ 2023-07-12 18:33  氢氦  阅读(379)  评论(1编辑  收藏  举报