Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Sometimes we need fork all MIMEs of a specific folder and its sub-folders to local, while as is often the case when you are making BSP/UI5 applications that there are nested folders in MIME repository and SE80 does not provide a batch download function for MIME objects.


This program will do the job by recursive call. What you need is to change the MIME folder path and local path as you require. To entirely copy to another folder in MIME repo you may refer to Copy Mime Folder in BSP as well.


UPDATE 20140122: Found a bug that when dealing with PNG file, we need to explicitly define the file_type upon calling GUI_download FM; otherwise the PNG file will be corrupted when it's larger than 20(pixels)*20. Code updated accordingly.




*&---------------------------------------------------------------------*
*& Report DOWNLOAD_MULTIPLE_MIME_OBJS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT DOWNLOAD_MULTIPLE_MIME_OBJS.
DATA o_mr_api TYPE REF TO IF_MR_API.
*DATA IS_FOLDER TYPE BOOLE_D.
DATA L_CURRENT TYPE XSTRING.
*DATA L_LOIO TYPE SKWF_IO.
*DATA LI_DATA TYPE BAPIDOCCONTENTAB.
DATA l_server_base_path TYPE STRING.
DATA l_local_file_full_name TYPE STRING.
DATA l_server_file_relative_name TYPE STRING.
*DATA l_file_path TYPE STRING.
*DATA l_full_path TYPE STRING.
DATA l_file_list TYPE STRING_TABLE.
DATA l_server_base_path_sum TYPE I.
TYPES : BEGIN OF TY_BINARY,
           BINARY_FIELD(1000) TYPE C,
         END OF TY_BINARY.
DATA : LI_DATA TYPE TABLE OF TY_BINARY WITH HEADER LINE.
FIELD-SYMBOLS:
  <list_item> TYPE STRING.
CLEAR o_mr_api.
if o_mr_api is initial.
  o_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).
endif.
l_server_base_path = '/SAP/BC/BSP/SAP/xxx'.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
CALL METHOD O_MR_API->FILE_LIST
  EXPORTING
  I_URL = l_server_base_path
  I_RECURSIVE_CALL = 'X'
* I_CHECK_AUTHORITY = 'X'
  IMPORTING
  E_FILES = l_file_list
  .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT l_file_list assigning <list_item>.
  call method o_mr_api->get
  exporting
  i_url = <list_item> "l_url
  importing
* e_is_folder = is_folder " 'C:\Documents and Settings\Desktop' "is_folder
  e_content = l_current
* e_loio = l_loio
  exceptions
  parameter_missing = 1
  error_occured = 2
  not_found = 3
  permission_failure = 4
  others = 5.
  call function 'SCMS_XSTRING_TO_BINARY'
  exporting
  buffer = l_current
* APPEND_TO_TABLE = ' '
* IMPORTING
* OUTPUT_LENGTH =
  tables
  binary_tab = li_data.
  l_server_base_path_sum = STRLEN( l_server_base_path ).
  l_server_file_relative_name = <list_item>+l_server_base_path_sum .
  l_local_file_full_name = 'C:\Yves\MIME_TEST\' && l_server_file_relative_name.
  call function 'GUI_DOWNLOAD'
  exporting
* BIN_FILESIZE =
  filename = l_local_file_full_name
filetype = 'BIN'
* IMPORTING
* FILELENGTH =
  tables
  data_tab = li_data
  .
ENDLOOP.
*data: l_guiobj type ref to cl_gui_frontend_services,
* l_uact type i.
*
* create object l_guiobj.
*
* call method l_guiobj->file_save_dialog
* exporting
* default_extension = 'PNG'
** default_file_name = 'AYNG.PDF'
** file_filter = v_filter
* changing
* filename = l_file_name
* path = l_file_path
* fullpath = l_full_path
* user_action = l_uact.
*
* if l_uact = l_guiobj->action_cancel.
* exit.
* endif.
*
* move l_full_path to l_file_name.
2 Comments