You are on page 1of 30

How to Mass Upload Documents to BW

B USINESS I NFORMATION W AREHOUSE

ASAP How to Paper

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 M ASS UPLOAD DOCUMENTS TO BW

Applicable Releases: BW 3.0B Support Package 7 November 2002

2002 SAP AMERICA , I NC. AND SAP AG

TABLE OF CONTENTS

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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.

2002 SAP AMERICA , I NC. AND SAP AG

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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.

2002 SAP AMERICA , I NC. AND SAP AG

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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: DATA: DATA:

l_s_chavl TYPE rsod_s_chanm_chavl. l_t_chavl TYPE TABLE OF rsod_s_chanm_chavl. 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: DATA: DAY(2) type C. 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),

2002 SAP AMERICA , I NC. AND SAP AG

HOW TO M ASS UPLOAD DOCUMENTS TO BW


END OF fileinfostruc. TYPES: DATE type SY-DATUM. DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: l_s_YEAR like T009B-BDATJ. fileinfo TYPE fileinfostruc. DATE type DATE. count TYPE i. len TYPE i. offset TYPE i. id TYPE i. filename TYPE string. thema type string. PFAD type C. dir TYPE string. descr TYPE sdok_descr. name TYPE skwf_urlp. l_t_return TYPE bapiret2. 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 SYMSGV4. ENDIF. p_path = folder. *fetch all files from directory, use *.pdf as mask CALL METHOD cl_gui_frontend_services=>directory_list_files

2002 SAP AMERICA , I NC. AND SAP AG

HOW TO M ASS UPLOAD DOCUMENTS TO BW


EXPORTING directory filter files_only DIRECTORIES_ONLY CHANGING file_table count EXCEPTIONS cntl_error directory_list_files_failed wrong_parameter error_no_gui not_supported_by_gui OTHERS

= folder = '*.pdf' = 'X' = = dir_tab = count = = = = = = 1 2 3 4 5 6.

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.

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 filetype * HAS_FIELD_SEPARATOR * HEADER_LENGTH * READ_BY_LINE * DAT_MODE IMPORTING filelength TABLES data_tab l_t_data_tab_bin EXCEPTIONS file_open_error file_read_error no_batch gui_refuse_filetransfer invalid_type no_authority unknown_error bad_data_format header_not_allowed separator_not_allowed header_too_long unknown_dp_error access_denied dp_out_of_memory disk_full dp_timeout OTHERS

= = = = = =

filename 'BIN' ' ' 0 'X' ' '

= l_filelength = = = = = = = = = = = = = = = = = = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17.

2002 SAP AMERICA , I NC. AND SAP AG

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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_returntype, l_t_return-id, l_t_return-number. ELSE. * successfuly loaded WRITE: / dir_entry(25), text-003. ENDIF.

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

2002 SAP AMERICA , I NC. AND SAP AG

HOW TO M ASS UPLOAD DOCUMENTS TO BW

in the FILE_SIZE field of the I_S_CONTENT_INFO parameters.

ENDLOOP. ENDFORM.

"section_main

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. 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).

2002 SAP AMERICA , I NC. AND SAP AG

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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).

2002 SAP AMERICA , I NC. AND SAP AG

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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 its 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:

2002 SAP AMERICA , I NC. AND SAP AG

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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.

2002 SAP AMERICA , I NC. AND SAP AG

10

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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.

2002 SAP AMERICA , I NC. AND SAP AG

11

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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: DATA: DATA:

l_s_chavl TYPE rsod_s_chanm_chavl. l_t_chavl TYPE TABLE OF rsod_s_chanm_chavl. 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: DATA: DATA: day(2) TYPE c. l_s_content_info TYPE rsod_s_content_info. 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: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: l_s_year LIKE t009b-bdatj. fileinfo TYPE fileinfostruc. date TYPE date. count TYPE i. len TYPE i. offset TYPE i. id TYPE i. filename TYPE string. thema TYPE string. pfad TYPE c. dir TYPE string. descr TYPE sdok_descr. name TYPE skwf_urlp.

2002 SAP AMERICA , I NC. AND SAP AG

12

HOW TO M ASS UPLOAD DOCUMENTS TO BW


DATA: DATA: l_t_return TYPE bapiret2. 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 SYMSGV4. 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.

2002 SAP AMERICA , I NC. AND SAP AG

13

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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 filetype * HAS_FIELD_SEPARATOR * HEADER_LENGTH * READ_BY_LINE * DAT_MODE IMPORTING filelength l_filelength TABLES data_tab l_t_data_tab_bin EXCEPTIONS file_open_error file_read_error no_batch gui_refuse_filetransfer invalid_type no_authority unknown_error bad_data_format header_not_allowed separator_not_allowed header_too_long unknown_dp_error access_denied dp_out_of_memory disk_full dp_timeout OTHERS

= = = = = =

filename 'BIN' ' ' 0 'X' ' ' =

= = = = = = = = = = = = = = = = = = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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

2002 SAP AMERICA , I NC. AND SAP AG

14

HOW TO M ASS UPLOAD DOCUMENTS TO BW


input IMPORTING output EXCEPTIONS length_error OTHERS = l_s_chavl-chavl = l_s_chavl-chavl = 1 = 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_chavlchanm i_chavl = l_s_chavlchavl * 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_returntype, l_t_return-id, l_t_return-number. ELSE. * successfuly loaded WRITE: / dir_entry(25), text-003. ENDIF. ENDLOOP. ENDFORM. "section_main

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.

2002 SAP AMERICA , I NC. AND SAP AG

15

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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).

2002 SAP AMERICA , I NC. AND SAP AG

16

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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).

2002 SAP AMERICA , I NC. AND SAP AG

17

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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 APIs 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.

2002 SAP AMERICA , I NC. AND SAP AG

18

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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: DATA: DATA:

l_s_chavl TYPE rsod_s_chanm_chavl. l_t_chavl TYPE TABLE OF rsod_s_chanm_chavl. 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: DATA: DAY(2) type C. 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: DATA: DATA: DATA: l_s_YEAR like T009B-BDATJ. fileinfo TYPE fileinfostruc. DATE type DATE. count TYPE i.

2002 SAP AMERICA , I NC. AND SAP AG

19

HOW TO M ASS UPLOAD DOCUMENTS TO BW DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: len TYPE i. offset TYPE i. id TYPE i. filename TYPE string. thema type string. PFAD type C. dir TYPE string. descr TYPE sdok_descr. name TYPE skwf_urlp. l_t_return TYPE bapiret2. 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

2002 SAP AMERICA , I NC. AND SAP AG

20

HOW TO M ASS UPLOAD DOCUMENTS TO BW * 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 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

*&--------------------------------------------------------------------* *& 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 filetype * HAS_FIELD_SEPARATOR * HEADER_LENGTH * READ_BY_LINE * DAT_MODE IMPORTING filelength TABLES

= = = = = =

filename 'BIN' ' ' 0 'X' ' '

= l_filelength

2002 SAP AMERICA , I NC. AND SAP AG

21

HOW TO M ASS UPLOAD DOCUMENTS TO BW data_tab EXCEPTIONS file_open_error file_read_error no_batch gui_refuse_filetransfer invalid_type no_authority unknown_error bad_data_format header_not_allowed separator_not_allowed header_too_long unknown_dp_error access_denied dp_out_of_memory disk_full dp_timeout OTHERS = l_t_data_tab_bin = = = = = = = = = = = = = = = = = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17.

IF sy-subrc <> 0. WRITE: / text-002, sy-subrc, dir_entry. 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.

"Error in uploading File

* 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

2002 SAP AMERICA , I NC. AND SAP AG

22

HOW TO M ASS UPLOAD DOCUMENTS TO BW i_name I_LANGU i_overwrite_mode i_with_content i_s_content_info I_WITH_URL I_URL I_COPY_URL_CONTENT IMPORTING E_NAME e_s_return TABLES i_t_chavl i_t_file_content_ascii i_t_file_content_binary = = = = = = = = name SY-LANGU if_rsod_const=>mode_replace_phio 'X' l_s_content_info

* * * *

= = l_t_return = l_t_chavl = l_t_data_tab_asc = 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: DATA: DATA: l_s_chavl TYPE rsod_s_chanm_chavl. l_t_chavl TYPE TABLE OF rsod_s_chanm_chavl. l_s_excpt(5) TYPE c.

2002 SAP AMERICA , I NC. AND SAP AG

23

HOW TO M ASS UPLOAD DOCUMENTS TO BW

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: DATA: DATA: day(2) TYPE c. l_s_content_info TYPE rsod_s_content_info. 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: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: l_s_year LIKE t009b-bdatj. fileinfo TYPE fileinfostruc. date TYPE date. count TYPE i. len TYPE i. offset TYPE i. id TYPE i. filename TYPE string. thema TYPE string. pfad TYPE c. dir TYPE string. descr TYPE sdok_descr. name TYPE skwf_urlp. l_t_return TYPE bapiret2. 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:\'.

2002 SAP AMERICA , I NC. AND SAP AG

24

HOW TO M ASS UPLOAD DOCUMENTS TO BW

* 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

2002 SAP AMERICA , I NC. AND SAP AG

25

HOW TO M ASS UPLOAD DOCUMENTS TO BW not_supported_by_gui OTHERS ENDFORM. = 5 = 6. "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 filetype * HAS_FIELD_SEPARATOR * HEADER_LENGTH * READ_BY_LINE * DAT_MODE IMPORTING filelength TABLES data_tab EXCEPTIONS file_open_error file_read_error no_batch gui_refuse_filetransfer invalid_type no_authority unknown_error bad_data_format header_not_allowed separator_not_allowed header_too_long unknown_dp_error access_denied dp_out_of_memory disk_full dp_timeout OTHERS

= = = = = =

filename 'BIN' ' ' 0 'X' ' ' = l_filelength

= l_t_data_tab_bin = = = = = = = = = = = = = = = = = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17.

2002 SAP AMERICA , I NC. AND SAP AG

26

HOW TO M ASS UPLOAD DOCUMENTS TO BW IF sy-subrc <> 0. WRITE: / text-002, sy-subrc, dir_entry. 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

"Error in uploading File

2002 SAP AMERICA , I NC. AND SAP AG

27

HOW TO M ASS UPLOAD DOCUMENTS TO BW 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

2002 SAP AMERICA , I NC. AND SAP AG

28