how to… mass upload documents to bwdocshare04.docshare.tips/files/17754/177543298.pdfhow to…...

30
SAP (SAP America, Inc. and SAP AG) assumes no responsibility for errors or omissions in these materials. These materials are provided “as is” without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within these materials. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third party web pages nor provide any w arranty whatsoever relating to third party web pages. mySAP BI “How-To” papers are intended to simplify the product implementation. While specific product features and procedures typically are explained in a practical business context, it is not implied that those features and procedures are the only approach in solving a specific business problem using mySAP BI. Should you wish to receive additional information, clarification or support, please refer to SAP Professional Services (Consulting/Remote Consulting). How to… Mass Upload Documents to BW BUSINESS I NFORMATION W AREHOUSE ASAP “How to…” Paper

Upload: doanhuong

Post on 18-May-2018

220 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

SAP (SAP America, Inc. and SAP AG) assumes no responsibility for errors or omissions in these materials.

These materials are provided “as is” without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.

SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials.

SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within these materials. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third party web pages nor provide any w arranty whatsoever relating to third party web pages.

mySAP BI “How -To” papers are intended to simplify the product implementation. While specific product features and procedures typically are explained in a practical business context, it is not implied that those features and procedures are the only approach in solving a specific business problem using mySAP BI. Should you wish to receive additional information, clarification or support, please refer to SAP Professional Services (Consulting/Remote Consulting).

How to…

Mass Upload Documents to BW

BUSINESS INFORMATION WAREHOUSE

ASAP “How to…” Paper

Page 2: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG TABLE OF CONTENTS

Applicable Releases: BW 3.0B Support Package 7 November 2002

Page 3: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 1

1 Business Scenario I - Transaction Documents

Your company would like to utilize the document integration functionality in BW 3.0B. There is a need to upload a large amount of transaction documents based on specific combinations of InfoObject values. This could be done manually for each individual document in the Administrator Workbench (RSA1 -> Documents -> Transaction data), however due to the high volume of documents you would like to have a more efficient and automated method to load them into BW. In this example, you would like to upload Acrobat Reader documents (.pdf format) for a combination of Country (0D_COUNTRY) and Calendar Month (0CALMONTH) InfoObject values.

2 The Result

An API is delivered with BW 3.0B SP7 to upload a large amount of transaction documents into the BW system. An ABAP program can be used to determine the combination of InfoObjects to be filled, locate the directory where the source documents are physically stored, choose the type of documents to be uploaded, and call the API to load the documents to the BW system. End users can then display the transaction documents from the Administrator Workbench, BEx Analyzer, and BW Web Applicatons.

The following files (.pdf) will be uploaded into the document storage repository:

Then they can be viewed in the BW Administrator Workbench, for example.

Page 4: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 2

3 The Step-By-Step Solution

1. Preliminary Remarks The attached ABAP program is designed to illustrate how documents can be uploaded for the specific business scenario described above. Enhancements to this program could be added to make it more flexible, for example a check box for the type of documents to be uploaded, it could be called in the background while loading date via the ABAP Program process type for Process Chains, etc.

2. In BW, goto transaction SE38. Enter a name for your Program (for example ZTRAN_DOC_UPLOAD) and then choose Create.

3. Enter a Title, and select Executable program as the Type. Choose Save.

Page 5: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 3

Maintain the text elements.

4. Add the attached ABAP code (in the next step) to the report. This can be done by selecting Utilities -> More utilities -> Upload/Download -> Upload... Then select the file you want to upload. Alternatively, you could copy and paste it below the Report name.

5. Copy the attached ABAP code to the program. Maintain the parameters that are highlighted in Red for your specific scenario.

DATA: l_s_chavl TYPE rsod_s_chanm_chavl. DATA: l_t_chavl TYPE TABLE OF rsod_s_chanm_chavl. DATA: l_s_excpt(5) TYPE C. DATA: l_t_data_tab_asc TYPE sdokcntascs. DATA: l_t_data_tab_bin TYPE sdokcntbins. DATA: rc TYPE sy-subrc. DATA: wa_dir(100). " like file_info. DATA: DAY(2) type C. DATA: l_s_content_info TYPE rsod_s_content_info. DATA: dir_tab TYPE STANDARD TABLE OF file_info. DATA: dir_entry(100). *DATA: p_path(40) type C . DATA: l_s_PERI like T009B-POPER. DATA: l_s_per(2) type C. TYPES: BEGIN OF fileinfostruc, country(10), fiscyear(6), fiscper(09), fiscper3(3),

Page 6: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 4

END OF fileinfostruc. TYPES: DATE type SY-DATUM. DATA: l_s_YEAR like T009B-BDATJ. DATA: fileinfo TYPE fileinfostruc. DATA: DATE type DATE. DATA: count TYPE i. DATA: len TYPE i. DATA: offset TYPE i. DATA: id TYPE i. DATA: filename TYPE string. DATA: thema type string. DATA: PFAD type C. DATA: dir TYPE string. DATA: descr TYPE sdok_descr. DATA: name TYPE skwf_urlp. DATA: l_t_return TYPE bapiret2. DATA: l_filelength type i. DATA: file_tab TYPE filetable, single_file TYPE filetable. DATA: file_line LIKE LINE OF file_tab. DATA: ls_path TYPE string. INTERFACE IF_RSOD_CONST LOAD. PARAMETER p_path(40) OBLIGATORY DEFAULT 'C:\'. * Display file selection dialog AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. PERFORM get_files. START-OF-SELECTION. PERFORM section_main. FORM get_files. dir = p_path. DATA: folder TYPE string. CALL METHOD cl_gui_frontend_services=>directory_browse EXPORTING * WINDOW_TITLE = initial_folder = 'C:\' CHANGING selected_folder = folder. * EXCEPTION * CNTL_ERROR = 1 * ERROR_NO_GUI = 2 * NOT_SUPPORTED_BY_GUI = 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. p_path = folder. *fetch all files from directory, use *.pdf as mask CALL METHOD cl_gui_frontend_services=>directory_list_files

Page 7: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 5

This section of the code selects all the specified files (.pdf) from the selected directory. The filter value could be changed to any of the supported document types.

EXPORTING directory = folder filter = '*.pdf' files_only = 'X' * DIRECTORIES_ONLY = CHANGING file_table = dir_tab count = count EXCEPTIONS cntl_error = 1 directory_list_files_failed = 2 wrong_parameter = 3 error_no_gui = 4 not_supported_by_gui = 5 OTHERS = 6. ENDFORM. "get_files *&--------------------------------------------------------------------* *& Form section_main *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* FORM section_main. LOOP AT dir_tab INTO dir_entry. * build filename TRANSLATE dir_entry TO UPPER CASE. CLEAR: filename. CONCATENATE p_path '\' dir_entry INTO filename. * call upload CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = filename filetype = 'BIN' * HAS_FIELD_SEPARATOR = ' ' * HEADER_LENGTH = 0 * READ_BY_LINE = 'X' * DAT_MODE = ' ' IMPORTING filelength = l_filelength TABLES data_tab = l_t_data_tab_bin EXCEPTIONS file_open_error = 1 file_read_error = 2 no_batch = 3 gui_refuse_filetransfer = 4 invalid_type = 5 no_authority = 6 unknown_error = 7 bad_data_format = 8 header_not_allowed = 9 separator_not_allowed = 10 header_too_long = 11 unknown_dp_error = 12 access_denied = 13 dp_out_of_memory = 14 disk_full = 15 dp_timeout = 16 OTHERS = 17.

Page 8: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 6

Enter the technical name for the characteristic and how to determine the characteristic value from the file name. In this example, the characteristic value for 0D_COUNTRY will be filled by the first two characters of the file name. 0CALMONTH will use six characters beginning with the fourth character.

The mime-type must be set for each document type. Since we are uploading .pdf files, we set this to ‘application/pdf’. Note: If the document is not a text file, you must also specify the size of the file in bytes

IF sy-subrc <> 0. WRITE: / text-002, sy-subrc, dir_entry. "Error in uploading File EXIT. ENDIF. * fill assignments for country, calmonth REFRESH l_t_chavl. l_s_chavl-chanm = '0D_COUNTRY'. l_s_chavl-chavl = dir_entry+0(2). APPEND l_s_chavl TO l_t_chavl. l_s_chavl-chanm = '0CALMONTH'. l_s_chavl-chavl = dir_entry+3(6). APPEND l_s_chavl TO l_t_chavl. * set mime-type l_s_content_info-mimetype = 'application/pdf'. l_s_content_info-file_name = filename. l_s_content_info-file_size = l_filelength. * set name and title name = dir_entry. CLEAR l_t_return. * upload document CALL FUNCTION 'RSOD_DOC_TRAN_CHANGE' EXPORTING * I_INFOPROV = * I_QUERY = * I_KYFNM = i_description = descr i_name = name * I_LANGU = SY-LANGU i_overwrite_mode = if_rsod_const=>mode_replace_phio i_with_content = 'X' i_s_content_info = l_s_content_info * I_WITH_URL = * I_URL = * I_COPY_URL_CONTENT = IMPORTING * E_NAME = e_s_return = l_t_return TABLES i_t_chavl = l_t_chavl i_t_file_content_ascii = l_t_data_tab_asc i_t_file_content_binary = l_t_data_tab_bin. IF l_t_return-type = 'E' OR l_t_return-type = 'W' OR l_t_return-type = 'A'. * error WRITE: / dir_entry(25), text-004, l_t_return-type, l_t_return-id, l_t_return-number. ELSE. * successfuly loaded WRITE: / dir_entry(25), text-003. ENDIF.

Page 9: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 7

in the FILE_SIZE field of the I_S_CONTENT_INFO parameters.

Examples of other mime-types: application/vnd.ms-excel application/vnd.ms-powerpoint application/msword text/plain

The API ‘RSOD_DOC_TRAN_CHANGE’ is called to upload the documents into the InfoProvider document class. A specific InfoProvider, Query, and Key Figure can be specified (optional), or can be left blank.

ENDLOOP. ENDFORM. "section_main

6. Execute the Report. Enter the name of the Program and then choose Execute (F8).

7. Find the path for the directory where the files are located (for example ‘C:\transaction docs’).

Page 10: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 8

8. Select the path for the directory from the selection window. Then choose Execute (F8).

9. A report is then displayed that shows the status of the document upload.

10. View the documents in the BW system. Goto the Administrator Workbench (transaction RSA1) -> Documents -> InfoProvider Data. Enter the values for the InfoObjects (for example 0calmonth and 0d_country).

Page 11: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 9

Then choose ‘Show me documents from...’.

Note: You can maintain the InfoObjects that are selectable by choosing the Settings icon.

11. The uploaded files are then displayed based on the selection criteria.

4 Business Scenario II – Master Data Documents

Your company would like to utilize the document integration functionality in BW 3.0B. There is a need to upload a large amount of master data documents based on a specific InfoObject and it’s associated values. This could be done manually for each individual document in the Administrator Workbench (RSA1 -> Documents -> Master data), however due to the high volume of documents you would like to have a more efficient and automated method to load them to BW. In this example, you would like to upload MS Word documents (.doc format) for Material (0MATERIAL).

5 The Result

An API is delivered with BW 3.0B to upload a large amount of master data documents into the BW system. An ABAP program can be used to determine the InfoObject to be filled, locate the directory where the source documents are physically stored, choose the type of documents to be uploaded, and call the API to load the documents to the BW system. End users can then display the master data documents from the Administrator Workbench, BEx Analyzer, and BW Web Applicatons.

The following files (.doc) will be uploaded into the document storage repository:

Page 12: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 10

Then they can be verified in the BW Administrator Workbench.

6 The Step-By-Step Solution

1. Preliminary Remarks The attached ABAP program is designed to illustrate how documents can be uploaded for the specific business scenario described above. Enhancements to this program could be added to make it more flexible, for example a check box for the type of documents to be uploaded, it could be called in the background while loading date via the ABAP Program process type for Process Chains, etc.

Page 13: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 11

2. In BW, goto transaction SE38. Enter a name for your Program (for example ZMAST_DOC_UPLOAD) and then choose Create.

3. Enter a Title, and select Executable program as the Type. Choose Save.

Maintain the text elements.

Page 14: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 12

4. Add the attached ABAP code (in the next step) to the report. This can be done by selecting Utilities -> More utilities -> Upload/Download -> Upload... Then select the file you want to upload. Alternatively, you could copy and paste it below the Report name.

5. Copy the attached ABAP code to the program. Maintain the parameters that are highlighted in Red for your specific scenario.

DATA: l_s_chavl TYPE rsod_s_chanm_chavl. DATA: l_t_chavl TYPE TABLE OF rsod_s_chanm_chavl. DATA: l_s_excpt(5) TYPE c. DATA: l_t_data_tab_asc TYPE sdokcntascs. DATA: l_t_data_tab_bin TYPE sdokcntbins. DATA: rc TYPE sy-subrc. DATA: wa_dir(100). " like file_info. DATA: day(2) TYPE c. DATA: l_s_content_info TYPE rsod_s_content_info. DATA: dir_tab TYPE STANDARD TABLE OF file_info. DATA: dir_entry(100). *DATA: p_path(40) type C . DATA: l_s_peri LIKE t009b-poper. DATA: l_s_per(2) TYPE c. TYPES: BEGIN OF fileinfostruc, material(18), END OF fileinfostruc. TYPES: date TYPE sy-datum. DATA: l_s_year LIKE t009b-bdatj. DATA: fileinfo TYPE fileinfostruc. DATA: date TYPE date. DATA: count TYPE i. DATA: len TYPE i. DATA: offset TYPE i. DATA: id TYPE i. DATA: filename TYPE string. DATA: thema TYPE string. DATA: pfad TYPE c. DATA: dir TYPE string. DATA: descr TYPE sdok_descr. DATA: name TYPE skwf_urlp.

Page 15: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 13

DATA: l_t_return TYPE bapiret2. DATA: l_filelength TYPE i. DATA: file_tab TYPE filetable, single_file TYPE filetable. DATA: file_line LIKE LINE OF file_tab. DATA: ls_path TYPE string. INTERFACE IF_RSOD_CONST LOAD. PARAMETER p_path(40) OBLIGATORY DEFAULT 'C:\'. * Display file selection dialog AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. PERFORM get_files. START-OF-SELECTION. PERFORM section_main. FORM get_files. dir = p_path. DATA: folder TYPE string. CALL METHOD cl_gui_frontend_services=>directory_browse EXPORTING * WINDOW_TITLE = initial_folder = 'C:\' CHANGING selected_folder = folder. * EXCEPTION * CNTL_ERROR = 1 * ERROR_NO_GUI = 2 * NOT_SUPPORTED_BY_GUI = 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. p_path = folder. *fetch all files from directory, use *.doc as mask CALL METHOD cl_gui_frontend_services=>directory_list_files EXPORTING directory = folder filter = '*.doc' files_only = 'X' * DIRECTORIES_ONLY = CHANGING file_table = dir_tab count = count EXCEPTIONS cntl_error = 1 directory_list_files_failed = 2 wrong_parameter = 3 error_no_gui = 4 not_supported_by_gui = 5 OTHERS = 6.

Page 16: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 14

This section of the code selects all the specified files (.doc) from the selected directory. The filter value could be changed to any of the supported document types.

ENDFORM. "get_files *&--------------------------------------------------------------------* *& Form section_main *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* FORM section_main. LOOP AT dir_tab INTO dir_entry. * Build filename TRANSLATE dir_entry TO UPPER CASE. CLEAR: filename. CONCATENATE p_path '\' dir_entry INTO filename. * call upload CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = filename filetype = 'BIN' * HAS_FIELD_SEPARATOR = ' ' * HEADER_LENGTH = 0 * READ_BY_LINE = 'X' * DAT_MODE = ' ' IMPORTING filelength = l_filelength TABLES data_tab = l_t_data_tab_bin EXCEPTIONS file_open_error = 1 file_read_error = 2 no_batch = 3 gui_refuse_filetransfer = 4 invalid_type = 5 no_authority = 6 unknown_error = 7 bad_data_format = 8 header_not_allowed = 9 separator_not_allowed = 10 header_too_long = 11 unknown_dp_error = 12 access_denied = 13 dp_out_of_memory = 14 disk_full = 15 dp_timeout = 16 OTHERS = 17. IF sy-subrc <> 0. WRITE: / text-002, sy-subrc, dir_entry. "Error in uploading File EXIT. ENDIF. * fill assignments for material len = strlen( dir_entry ) - 4. REFRESH l_t_chavl. l_s_chavl-chanm = '0MATERIAL'. l_s_chavl-chavl = dir_entry+0(len). CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' EXPORTING

Page 17: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 15

Enter the technical name for the characteristic and how to determine the characteristic value from the file name. In this example, the characteristic value for 0MATERIAL will be filled beginning with the first character of the file name. A conversion exit is called to convert the characteristic value into the correct format. This exit (MATN1) would be called by default during a master data load for 0MATERIAL. Note: Check transaction RSD1 -> General tab -> field Convers. Rout., to see if there is a conversion exit for your InfoObject .

The mime-type must be set for each document type. Since we are uploading .doc files, we set this to ‘application/msword’. Note: If the document is not a text file, you must also specify the size of the file in bytes in the FILE_SIZE field of the I_S_CONTENT_INFO parameters.

input = l_s_chavl-chavl IMPORTING output = l_s_chavl-chavl EXCEPTIONS length_error = 1 OTHERS = 2. APPEND l_s_chavl TO l_t_chavl. * set mime-type l_s_content_info-mimetype = 'application/msword'. l_s_content_info-file_name = dir_entry. l_s_content_info-file_size = l_filelength. * set name and title name = dir_entry. CLEAR l_t_return. * upload document CALL FUNCTION 'RSOD_DOC_MAST_CHANGE' EXPORTING i_chanm = l_s_chavl-chanm i_chavl = l_s_chavl-chavl * I_DOC_TYPE = i_description = descr i_name = name * I_LANGU = SY-LANGU i_overwrite_mode = if_rsod_const=>mode_replace_phio i_with_content = 'X' i_s_content_info = l_s_content_info * I_WITH_URL = * I_URL = * I_COPY_URL_CONTENT = IMPORTING * E_NAME = e_s_return = l_t_return TABLES i_t_file_content_ascii = l_t_data_tab_asc i_t_file_content_binary = l_t_data_tab_bin. IF l_t_return-type = 'E' OR l_t_return-type = 'W' OR l_t_return-type = 'A'. * error WRITE: / dir_entry(25), text-004, l_t_return-type, l_t_return-id, l_t_return-number. ELSE. * successfuly loaded WRITE: / dir_entry(25), text-003. ENDIF. ENDLOOP. ENDFORM. "section_main

Page 18: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 16

The API ‘RSOD_DOC_MAST_CHANGE’ is called to upload the documents into the Master Data document class.

6. Execute the Report. Enter the name of the Program and then choose Execute (F8).

Page 19: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 17

7. Find the path for the directory where the files are located (for example ‘C:\master_data_docs’).

8. Select the path for the directory from the selection window. Then choose Execute (F8).

Page 20: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 18

9. A report is then displayed that shows the status of the document upload.

10. View the documents in the BW system. Goto the Administrator Workbench (transaction RSA1) -> Documents -> Master Data. Enter the values for the InfoObject (for example 0material). Then choose ‘Show me documents from...’.

Note: You can maintain the InfoObjects that are selectable by choosing the Settings icon.

7 Summary

The two business scenarios described above cover the API’s for the Master Data and InfoProvider document classes. Additionally, there is a third API (RSOD_DOC_META_CHANGE) for creating Meta Data document s available. You can specify the contents of the documents and overwrite existing documents in a variety of ways. Please check the documentation for each function module for more information.

Page 21: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 19

8 Appendix *&---------------------------------------------------------------------* *& Report ZTRAN_DOC_UPLOAD * *& * *&---------------------------------------------------------------------* *& * *& * *&---------------------------------------------------------------------* * TEXT ELEMENTS * 001 Error in Reading Directory * 002 Error in uploading file * 003 successfully uploaded * 004 Error uploading to Document store REPORT ZTRAN_DOC_UPLOAD . DATA: l_s_chavl TYPE rsod_s_chanm_chavl. DATA: l_t_chavl TYPE TABLE OF rsod_s_chanm_chavl. DATA: l_s_excpt(5) TYPE C. DATA: l_t_data_tab_asc TYPE sdokcntascs. DATA: l_t_data_tab_bin TYPE sdokcntbins. DATA: rc TYPE sy-subrc. DATA: wa_dir(100). " like file_info. DATA: DAY(2) type C. DATA: l_s_content_info TYPE rsod_s_content_info. DATA: dir_tab TYPE STANDARD TABLE OF file_info. DATA: dir_entry(100). *DATA: p_path(40) type C . DATA: l_s_PERI like T009B-POPER. DATA: l_s_per(2) type C. TYPES: BEGIN OF fileinfostruc, country(10), fiscyear(6), fiscper(09), fiscper3(3), END OF fileinfostruc. TYPES: DATE type SY-DATUM. DATA: l_s_YEAR like T009B-BDATJ. DATA: fileinfo TYPE fileinfostruc. DATA: DATE type DATE. DATA: count TYPE i.

Page 22: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 20

DATA: len TYPE i. DATA: offset TYPE i. DATA: id TYPE i. DATA: filename TYPE string. DATA: thema type string. DATA: PFAD type C. DATA: dir TYPE string. DATA: descr TYPE sdok_descr. DATA: name TYPE skwf_urlp. DATA: l_t_return TYPE bapiret2. DATA: l_filelength type i. DATA: file_tab TYPE filetable, single_file TYPE filetable. DATA: file_line LIKE LINE OF file_tab. DATA: ls_path TYPE string. INTERFACE IF_RSOD_CONST LOAD. PARAMETER p_path(40) OBLIGATORY DEFAULT 'C:\'. * Display file selection dialog AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. PERFORM get_files. START-OF-SELECTION. PERFORM section_main. FORM get_files. dir = p_path. DATA: folder TYPE string. CALL METHOD cl_gui_frontend_services=>directory_browse EXPORTING * WINDOW_TITLE = initial_folder = 'C:\' CHANGING selected_folder = folder. * EXCEPTION * CNTL_ERROR = 1 * ERROR_NO_GUI = 2 * NOT_SUPPORTED_BY_GUI = 3 * others = 4 IF sy-subrc <> 0. * add your error message here * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

Page 23: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 21

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. p_path = folder. *fetch all files from directory, use *.pdf as mask CALL METHOD cl_gui_frontend_services=>directory_list_files EXPORTING directory = folder filter = '*.pdf' files_only = 'X' * DIRECTORIES_ONLY = CHANGING file_table = dir_tab count = count EXCEPTIONS cntl_error = 1 directory_list_files_failed = 2 wrong_parameter = 3 error_no_gui = 4 not_supported_by_gui = 5 OTHERS = 6. ENDFORM. "get_files *&--------------------------------------------------------------------* *& Form section_main *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* FORM section_main. LOOP AT dir_tab INTO dir_entry. * build filename TRANSLATE dir_entry TO UPPER CASE. CLEAR: filename. CONCATENATE p_path '\' dir_entry INTO filename. * call upload CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = filename filetype = 'BIN' * HAS_FIELD_SEPARATOR = ' ' * HEADER_LENGTH = 0 * READ_BY_LINE = 'X' * DAT_MODE = ' ' IMPORTING filelength = l_filelength TABLES

Page 24: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 22

data_tab = l_t_data_tab_bin EXCEPTIONS file_open_error = 1 file_read_error = 2 no_batch = 3 gui_refuse_filetransfer = 4 invalid_type = 5 no_authority = 6 unknown_error = 7 bad_data_format = 8 header_not_allowed = 9 separator_not_allowed = 10 header_too_long = 11 unknown_dp_error = 12 access_denied = 13 dp_out_of_memory = 14 disk_full = 15 dp_timeout = 16 OTHERS = 17. IF sy-subrc <> 0. WRITE: / text-002, sy-subrc, dir_entry. "Error in uploading File EXIT. ENDIF. * fill assignments for country, calmonth REFRESH l_t_chavl. l_s_chavl-chanm = '0D_COUNTRY'. l_s_chavl-chavl = dir_entry+0(2). APPEND l_s_chavl TO l_t_chavl. l_s_chavl-chanm = '0CALMONTH'. l_s_chavl-chavl = dir_entry+3(6). APPEND l_s_chavl TO l_t_chavl. * set mime-type l_s_content_info-mimetype = 'application/pdf'. l_s_content_info-file_name = filename. l_s_content_info-file_size = l_filelength. * set name and title name = dir_entry. CLEAR l_t_return. * upload document CALL FUNCTION 'RSOD_DOC_TRAN_CHANGE' EXPORTING * I_INFOPROV = * I_QUERY = * I_KYFNM = i_description = descr

Page 25: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 23

i_name = name * I_LANGU = SY-LANGU i_overwrite_mode = if_rsod_const=>mode_replace_phio i_with_content = 'X' i_s_content_info = l_s_content_info * I_WITH_URL = * I_URL = * I_COPY_URL_CONTENT = IMPORTING * E_NAME = e_s_return = l_t_return TABLES i_t_chavl = l_t_chavl i_t_file_content_ascii = l_t_data_tab_asc i_t_file_content_binary = l_t_data_tab_bin. IF l_t_return-type = 'E' OR l_t_return-type = 'W' OR l_t_return-type = 'A'. * error WRITE: / dir_entry(25), text-004, l_t_return-type, l_t_return-id, l_t_return-number. ELSE. * successfuly loaded WRITE: / dir_entry(25), text-003. ENDIF. ENDLOOP. ENDFORM. "section_main *&---------------------------------------------------------------------* *& Report ZMAST_DOC_UPLOAD * *& * *&---------------------------------------------------------------------* *& * *& * *&---------------------------------------------------------------------* * TEXT ELEMENTS * 001 Error reading file/directory * 002 Error uploading file * 003 Successfully Loaded REPORT zmast_doc_upload . DATA: l_s_chavl TYPE rsod_s_chanm_chavl. DATA: l_t_chavl TYPE TABLE OF rsod_s_chanm_chavl. DATA: l_s_excpt(5) TYPE c.

Page 26: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 24

DATA: l_t_data_tab_asc TYPE sdokcntascs. DATA: l_t_data_tab_bin TYPE sdokcntbins. DATA: rc TYPE sy-subrc. DATA: wa_dir(100). " like file_info. DATA: day(2) TYPE c. DATA: l_s_content_info TYPE rsod_s_content_info. DATA: dir_tab TYPE STANDARD TABLE OF file_info. DATA: dir_entry(100). *DATA: p_path(40) type C . DATA: l_s_peri LIKE t009b-poper. DATA: l_s_per(2) TYPE c. TYPES: BEGIN OF fileinfostruc, material(18), END OF fileinfostruc. TYPES: date TYPE sy-datum. DATA: l_s_year LIKE t009b-bdatj. DATA: fileinfo TYPE fileinfostruc. DATA: date TYPE date. DATA: count TYPE i. DATA: len TYPE i. DATA: offset TYPE i. DATA: id TYPE i. DATA: filename TYPE string. DATA: thema TYPE string. DATA: pfad TYPE c. DATA: dir TYPE string. DATA: descr TYPE sdok_descr. DATA: name TYPE skwf_urlp. DATA: l_t_return TYPE bapiret2. DATA: l_filelength TYPE i. DATA: file_tab TYPE filetable, single_file TYPE filetable. DATA: file_line LIKE LINE OF file_tab. DATA: ls_path TYPE string. INTERFACE IF_RSOD_CONST LOAD. PARAMETER p_path(40) OBLIGATORY DEFAULT 'C:\'.

Page 27: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 25

* Display file selection dialog AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. PERFORM get_files. START-OF-SELECTION. PERFORM section_main. FORM get_files. dir = p_path. DATA: folder TYPE string. CALL METHOD cl_gui_frontend_services=>directory_browse EXPORTING * WINDOW_TITLE = initial_folder = 'C:\' CHANGING selected_folder = folder. * EXCEPTION * CNTL_ERROR = 1 * ERROR_NO_GUI = 2 * NOT_SUPPORTED_BY_GUI = 3 * others = 4 IF sy-subrc <> 0. * add your error message here * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. p_path = folder. *fetch all files from directory, use *.doc as mask CALL METHOD cl_gui_frontend_services=>directory_list_files EXPORTING directory = folder filter = '*.doc' files_only = 'X' * DIRECTORIES_ONLY = CHANGING file_table = dir_tab count = count EXCEPTIONS cntl_error = 1 directory_list_files_failed = 2 wrong_parameter = 3 error_no_gui = 4

Page 28: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 26

not_supported_by_gui = 5 OTHERS = 6. ENDFORM. "get_files *&--------------------------------------------------------------------* *& Form section_main *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* FORM section_main. LOOP AT dir_tab INTO dir_entry. * Build filename TRANSLATE dir_entry TO UPPER CASE. CLEAR: filename. CONCATENATE p_path '\' dir_entry INTO filename. * call upload CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = filename filetype = 'BIN' * HAS_FIELD_SEPARATOR = ' ' * HEADER_LENGTH = 0 * READ_BY_LINE = 'X' * DAT_MODE = ' ' IMPORTING filelength = l_filelength TABLES data_tab = l_t_data_tab_bin EXCEPTIONS file_open_error = 1 file_read_error = 2 no_batch = 3 gui_refuse_filetransfer = 4 invalid_type = 5 no_authority = 6 unknown_error = 7 bad_data_format = 8 header_not_allowed = 9 separator_not_allowed = 10 header_too_long = 11 unknown_dp_error = 12 access_denied = 13 dp_out_of_memory = 14 disk_full = 15 dp_timeout = 16 OTHERS = 17.

Page 29: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 27

IF sy-subrc <> 0. WRITE: / text-002, sy-subrc, dir_entry. "Error in uploading File EXIT. ENDIF. * fill assignments for material len = strlen( dir_entry ) - 4. REFRESH l_t_chavl. l_s_chavl-chanm = '0MATERIAL'. l_s_chavl-chavl = dir_entry+0(len). CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' EXPORTING input = l_s_chavl-chavl IMPORTING output = l_s_chavl-chavl EXCEPTIONS length_error = 1 OTHERS = 2. APPEND l_s_chavl TO l_t_chavl. * set mime-type l_s_content_info-mimetype = 'application/msword'. l_s_content_info-file_name = dir_entry. l_s_content_info-file_size = l_filelength. * set name and title name = dir_entry. CLEAR l_t_return. * upload document CALL FUNCTION 'RSOD_DOC_MAST_CHANGE' EXPORTING i_chanm = l_s_chavl-chanm i_chavl = l_s_chavl-chavl * I_DOC_TYPE = i_description = descr i_name = name * I_LANGU = SY-LANGU i_overwrite_mode = if_rsod_const=>mode_replace_phio i_with_content = 'X' i_s_content_info = l_s_content_info * I_WITH_URL = * I_URL = * I_COPY_URL_CONTENT = IMPORTING * E_NAME = e_s_return = l_t_return TABLES i_t_file_content_ascii = l_t_data_tab_asc

Page 30: How to… Mass Upload Documents to BWdocshare04.docshare.tips/files/17754/177543298.pdfHOW TO… MASS UPLOAD DOCUMENTS TO BW Ó2002 SAP AMERICA, INC. AND SAP AG 1 1 Business Scenario

HOW TO… MASS UPLOAD DOCUMENTS TO BW

2002 SAP AMERICA, INC. AND SAP AG 28

i_t_file_content_binary = l_t_data_tab_bin. IF l_t_return-type = 'E' OR l_t_return-type = 'W' OR l_t_return-type = 'A'. * error WRITE: / dir_entry(25), text-004, l_t_return-type, l_t_return-id, l_t_return-number. ELSE. * successfuly loaded WRITE: / dir_entry(25), text-003. ENDIF. ENDLOOP. ENDFORM. "section_main