upload and download data from bps web layouts without using … · 2019. 11. 12. · upload and...

31
SDN Contribution © 2006 SAP AG 1 Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web Browser Within the Layout Applies to: This article applies to Netweaver 04, SAP BW 3.5, SEM-BW 4.0 Summary This article gives detailed description on how to implement and achieve upload and download from BPS Web layouts without using excel web component. Author(s): Praveen S Mayalur Company: Created on: 13 June 2006 Author Bio Praveen Mayalur is a SAP Technical Solution consultant with more than five years experience in various areas of SAP, currently involved in SAP Enterprise Portal, BPS implementations and their integrations with other systems

Upload: others

Post on 14-Aug-2021

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

SDN Contribution

© 2006 SAP AG 1

Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web Browser Within the Layout

Applies to:

This article applies to Netweaver 04, SAP BW 3.5, SEM-BW 4.0

Summary

This article gives detailed description on how to implement and achieve upload and download data into / from BPS Web layouts without using excel web component.

Author(s): Praveen S Mayalur

Company:

Created on: 13 June 2006

Author Bio

Praveen Mayalur is a SAP Technical Solution consultant with more than five years experience in various areas of SAP, currently involved in SAP Enterprise Portal, SAP BW & BPS implementations and their integrations with other systems

Page 2: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 2

Table of Contents

Background...................................................................................................................................... 3

Introduction ...................................................................................................................................... 3

Layout with Upload and Download Features in BPS Web Layout .................................................. 3

Detailed Procedure on ‘How To’...................................................................................................... 3

Upload BPS Data into web layout ................................................................................................... 4

Create Planning Functions........................................................................................................... 4

Create BSP Page......................................................................................................................... 6

Web Interface Builder................................................................................................................... 6

Download BPS Data into flat file...................................................................................................... 8

Create Planning Functions........................................................................................................... 8

Create BSP Page......................................................................................................................... 9

Web Interface Builder................................................................................................................. 10

How to Execute the Application..................................................................................................... 11

Related Content............................................................................................................................. 15

Disclaimer and Liability Notice....................................................................................................... 15

Appendix ........................................................................................................................................ 16

Appendix 1 - BSP PAGE - UPLOAD .HTM................................................................................ 16

Appendix 2 - BSP PAGE DOWNLOAD.HTM............................................................................. 19

Appendix 3 - FUNCTION Z_BPS_EXIT_FILE_SAVE_INIT....................................................... 23

Appendix 4 - FUNCTION Z_BPS_EXIT_FILE_SAVE. .............................................................. 24

Appendix 5 - FUNCTION Z_BPS_EXIT_FILE_WEB................................................................. 25

Appendix 6 - FUNCTION Z_BPS_EXIT_FILE_LOAD. .............................................................. 29

Appendix 7 - FUNCTION-POOL ZBPSGROUP ........................................................................ 31

Page 3: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 3

Background

Currently from BPS Web layout, data can be downloaded into the MS Excel only by using Excel web Component but sometimes requirement would be to display the Layout only in web format and requirement / need to download and upload the data into BPS web layout. Immediately after the upload, new values need to be reflected on the web layout.

Introduction

This article would provide step by step procedure how data can be uploaded into BPS Web Layout from flat file or downloaded to flat file from BPS Web Layout.

Layout with Upload and Download Features in BPS Web Layout

Detailed Procedure on ‘How To’.

Create four function modules

1. Z_BPS_EXIT_FILE_SAVE_INIT – Used in download planning function as FM initialization

2. Z_BPS_EXIT_FILE_SAVE - Used in download planning function as FM

3. Z_BPS_EXIT_FILE_WEB – Used in upload planning function as FM Initialization

4. Z_BPS_EXIT_FILE_LOAD – Used in Upload planning function as FM

Code for all these function modules are given in the appendix 3, 4, 5, 6.

Page 4: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 4

Upload BPS Data into web layout

Create Planning Functions 1. Select the Planning Areas Æ Planning Level Æ Planning Package Æ Create a Planning function

making use of exit functions.

Enter Planning Function name and Description, select the exit function and click on green check mark.

Page 5: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 5

2. Specify the created ‘Z_BPS_EXIT_FILE_WEB‘ in the FM Initialization & ‘Z_BPS_EXIT_FILE_LOAD’ in the Function Module field. Add all the fields in field list area to Fields to be changed area.

3. Right click on the Planning function created and Create an empty Parameter Group for upload

planning function

4. Create Download planning function and specify ‘Z_BPS_EXIT_FILE_SAVE_INIT’ in FM initialization and ‘Z_BPS_EXIT_FILE_SAVE’ in Function Module field.

5. Create an empty Parameter Group for Download planning function.

Page 6: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 6

Create BSP Page

Create a web page (upload.htm) in the same BSP application created for displaying BPS web layout.

1. Create a layout with <htmlb:fileUpload> for file upload, <htmlb:radioButton> for Append and overwrite, <htmlb:textView> for displaying the output messages.

2. In Event Handler - OnInputProcessing

a. Get the file name, append/overwrite selection from the layout.

b. Convert the read contents from the file using function ‘cl_abap_conv_in_ce ‘ and export the generated string to ABAP Memory

c. Export the selection (append/overwrite) to ABAP memory variable.

d. Raise error messages when there is no file, no data in the file.

e. Raise success message when contents are successfully exported to memory

<Code given in Appendix 1>

Web Interface Builder 1. Create a sub component (Text, Image, HTML) and Function button for Upload.

a. Make the property of the Text component as HTML Enabled and add <iframe> tag code into this text component to include custom created BSP page into the layout.

Select Edit Long Text

Page 7: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 7

Add the code in the text

<iframe id="Text38" border="true" name="BWQUERY" src="/sap/bw/mime/bex/icons/pixel.gif" width="580" height="65"></iframe> <script language="JavaScript" type="text/javascript"> var frame = document.getElementById( 'Text38' ); var url = '/sap/bc/bsp/sap/zbpsweblayout/upload.htm'; // set source attribute of iframe to new URL frame.src = url; </script>

b. Pass Planning area, level, package, function, parameter group to the created Function Button for upload button.

Page 8: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 8

After generating the web interface builder, Execute the BSP application and you would see

Click on Browse to read the tab delimited flat file. Then Click in Read File to read the contents and push them to memory. Click on Upload will actually call the planning function and update the layout with the values in the flat file.

Download BPS Data into flat file.

Create Planning Functions 1. Select the Planning Areas Æ Planning Level Æ Planning Package Æ Create a Planning function

making use of exit functions.

Enter Planning Function name and Description, select the exit function and click on green check mark.

2. Specify the created ‘Z_BPS_EXIT_FILE_SAVE_INIT in the FM Initialization & ‘Z_BPS_EXIT_FILE_SAVE’ in the Function Module field. Add all the fields in field list area to Fields to be changed area.

Page 9: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 9

3. Right click on the Planning function created and Create an empty Parameter Group for download planning function

Create BSP Page 1. Create a layout with <htmlb:button>. 2. In Event Handler – OnInputProcessing

a. Import the values from ABAP Memory variable which has values exported from the Planning function Save method.

b. Convert the string into Xstring using SCMS_STRING_TO_XSTRING passing mimetype as ‘APPLICATION/MSEXCEL’.

Page 10: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 10

c. Create a object for the class ‘cl_http_response’ and Using Functions ‘set_header_field’, ‘set_data’ download the data into excel.

Web Interface Builder 1. Create a sub component (Text, Image, HTML) and Function button for Upload.

a. Make the property of the Text component as HTML Enabled and add <iframe> tag code into this text component to include custom created BSP page into the layout.

Select Edit Long Text

Add the code in the text

<iframe id="Text42" name="BWDownload" src="/sap/bw/mime/bex/icons/pixel.gif" width="64" height="26"></iframe> <script language="JavaScript" type="text/javascript"> var frame = document.getElementById( 'Text42' ); var url = '/sap/bc/bsp/sap/z100upsbpslp001/download.htm'; // set source attribute of iframe to new URL frame.src = url;

</script>

b. Pass Planning area, level, package, function, parameter group to the created Function Button for download button.

Page 11: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 11

After generating the web interface builder, then it would be shown as below

How to Execute the Application

Upload

Layout with values before the upload.

Click on Browse to select the file from the local desktop

Select the file and

Page 12: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 12

click open

Choose the option “Append” to append values to existing records or “Overwrite” to overwrite existing values.

Click on Read File

Success Message is displayed after reading the file

Click on Upload Button

Records are uploaded successfully and Success message is seen at the bottom

Page 13: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 13

Flat File

Layout with updated values after the upload

Download

Click on Download then

Click on Save

Page 14: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 14

First Click Download and then click on save.

Open downloaded excel sheet

Page 15: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 15

Related Content

1. How To…Integrate BEx Web Applications into BPS Web Interface

2. BSP Programming: Handling Of Non-HTML Documents

3. BSP Download to Excel in Unicode Format

4. Forum Thread 1

5. Forum Thread 2

Disclaimer and Liability Notice

This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.

SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk.

SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.

Page 16: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 16

Appendix

Appendix 1 - BSP PAGE - UPLOAD .HTM

Layout

<%@page language="abap" %> <%@extension name="htmlb" prefix="htmlb" %> <htmlb:content design="design2003" > <htmlb:page title=" " > <htmlb:form id = "form1" doValidate = "true" encodingType = "multipart/form-data" > <htmlb:fileUpload id = "myUpload" onUpload = "HandleUpload" upload_text = "Read File" size = "80" /> <htmlb:radioButtonGroup id = "rbg" columnCount = "2" width = "25" > <htmlb:radioButton id = "append" text = "Append" checked = "TRUE" /> <htmlb:radioButton id = "overwrite" text = "Overwrite" /> </htmlb:radioButtonGroup> <htmlb:textView text = "<%= msg %>" design = "LABELSMALL" /> </htmlb:form> </htmlb:page> </htmlb:content>

Event Handler (OnInputProcessing)

* event handler for checking and processing user input and * for defining navigation DATA: fileupload TYPE REF TO cl_htmlb_fileupload, radiobuttongroup TYPE REF TO cl_htmlb_radiobuttongroup, conv TYPE REF TO cl_abap_conv_in_ce, display_type TYPE string, content_length TYPE string, file_content TYPE xstring , file_length TYPE string , file_mime_type TYPE string , file_name TYPE string , l_content TYPE string, l_subrc TYPE sy-subrc, len TYPE i. CONSTANTS: c_memory_id_file_upload TYPE memory_id VALUE 'Z_BPS_FILE_UPLOAD', c_memory_id_select TYPE memory_id VALUE 'Z_OVERWRITE_SELECT'. * Read Radiobutton Selection radiobuttongroup ?= cl_htmlb_manager=>get_data( request = request id = 'rbg' name = 'radioButtonGroup' ). display_type = radiobuttongroup->selection.

Page 17: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 17

* Export the selection to memory IF display_type = 'append'. EXPORT content FROM display_type TO MEMORY ID c_memory_id_select. ELSEIF display_type = 'overwrite'. EXPORT content FROM display_type TO MEMORY ID c_memory_id_select. ENDIF. * Read the file Contents fileupload ?= cl_htmlb_manager=>get_data( request = request id = 'myUpload' name = 'fileUpload' ). file_name = fileupload->file_name. file_mime_type = fileupload->file_content_type. file_length = fileupload->file_length. file_content = fileupload->file_content. conv = cl_abap_conv_in_ce=>create( input = file_content ). conv->read( IMPORTING data = l_content len = len ). IF file_name IS INITIAL. msg = 'Enter file name'. ELSE. IF l_content IS NOT INITIAL. EXPORT content FROM l_content TO MEMORY ID c_memory_id_file_upload. IF sy-subrc = 0. CONCATENATE 'File ' file_name ' Successfully read' INTO msg SEPARATED BY space. ENDIF. ELSE. CONCATENATE 'No data exists in file' file_name INTO msg SEPARATED BY space. ENDIF. ENDIF. * Export the contents into memory for further processing IF file_name IS INITIAL. msg = 'Enter file name'. ELSE. IF l_content IS NOT INITIAL. EXPORT content FROM l_content TO MEMORY ID c_memory_id_file_upload. IF sy-subrc = 0. CONCATENATE 'File ' file_name ' Successfully read' INTO msg SEPARATED BY space. ENDIF. ELSE. CONCATENATE 'No data exists in file' file_name INTO msg SEPARATED BY space. ENDIF. ENDIF.

Page Attributes:

Page 18: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 18

Page 19: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 19

Appendix 2 - BSP PAGE DOWNLOAD.HTM

Layout

<%@page language="abap" %> <%@extension name="htmlb" prefix="htmlb" %> <htmlb:content design="design2003" > <htmlb:page title=" " > <htmlb:form> <htmlb:button text = "Save File" onClick = "onClick" /> <script language="Javascript"> <% if not is_data is initial. %> alert("Either data is locked by others or download is not clicked. First click download then click save file"); <% clear: display_url, is_data. else. clear is_data. endif. %> <% IF display_url IS NOT INITIAL. %> window.open("<%= display_url%>").focus(); <% clear display_url. ENDIF. %> </script> </htmlb:form> </htmlb:page> </htmlb:content>

OnInputProcessing

* event handler for checking and processing user input and * for defining navigation TYPE-POOLS abap. TYPES: BEGIN OF ys_file, fiscyear(4), costcenter(10), acttype(6), emplgroup(1), column1(10), column2(10), column3(10), END OF ys_file. DATA: output TYPE string, xoutput TYPE xstring, event TYPE REF TO cl_htmlb_event, l_content TYPE string, cached_response TYPE REF TO cl_http_response, l_xls_len type i,

Page 20: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 20

lv_guid_32 type guid_32, gt_file TYPE STANDARD TABLE OF ys_file WITH DEFAULT KEY, wa TYPE ys_file. CONSTANTS c_export_bps TYPE memory_id VALUE 'EXPORT_TABLE_DATA. event = cl_htmlb_manager=>get_event( runtime->server->request ). IF event->name = 'button' AND event->event_type = 'click'. DATA: button_event TYPE REF TO cl_htmlb_event_button. button_event ?= event. IMPORT content TO gt_file FROM MEMORY ID c_export_bps. IF sy-subrc <> 0. is_data = 'X'. ENDIF. FREE MEMORY ID c_export_bps. LOOP AT gt_file INTO wa . IF sy-tabix = 1. CONCATENATE wa-fiscyear cl_abap_char_utilities=>horizontal_tab wa-costcenter cl_abap_char_utilities=>horizontal_tab wa-acttype cl_abap_char_utilities=>horizontal_tab 'EG' cl_abap_char_utilities=>horizontal_tab wa-column1 cl_abap_char_utilities=>horizontal_tab wa-column2 cl_abap_char_utilities=>horizontal_tab wa-column3 cl_abap_char_utilities=>cr_lf INTO output. ELSE. CONCATENATE output wa-fiscyear cl_abap_char_utilities=>horizontal_tab wa-costcenter cl_abap_char_utilities=>horizontal_tab wa-acttype cl_abap_char_utilities=>horizontal_tab wa-emplgroup cl_abap_char_utilities=>horizontal_tab wa-column1 cl_abap_char_utilities=>horizontal_tab wa-column2 cl_abap_char_utilities=>horizontal_tab wa-column3 cl_abap_char_utilities=>cr_lf INTO output. ENDIF. CLEAR wa. ENDLOOP. CALL FUNCTION 'SCMS_STRING_TO_XSTRING' EXPORTING

Page 21: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 21

text = output mimetype = 'APPLICATION/MSEXCEL' IMPORTING buffer = xoutput. CREATE OBJECT cached_response TYPE cl_http_response EXPORTING add_c_msg = 1. l_xls_len = XSTRLEN( xoutput ). cached_response->set_header_field( name = 'content-type' value = 'APPLICATION/MSEXCEL' ). * some Browsers have caching problems when loading Excel Format cached_response->delete_header_field( name = if_http_header_fields=>cache_control ). cached_response->delete_header_field( name = if_http_header_fields=>expires ). cached_response->delete_header_field( name = if_http_header_fields=>pragma ). * start Excel viewer either in the Browser or as a separate window cached_response->set_header_field( name = 'content-disposition' value = 'attachment;filename=File_Download.xls' ). cached_response->set_data( data = xoutput length = l_xls_len ). * navigation->response_complete( ). CALL METHOD cached_response->if_http_response~set_status EXPORTING code = 200 reason = 'OK'. CALL METHOD cached_response->if_http_response~server_cache_expire_rel EXPORTING expires_rel = 180. * CALL FUNCTION 'GUID_CREATE' IMPORTING ev_guid_32 = lv_guid_32. CONCATENATE runtime->application_url '/' lv_guid_32 'xls' INTO display_url. cl_http_server=>server_cache_upload( url = display_url response = cached_response ). RETURN. ENDIF.

Page 22: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 22

Page 23: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 23

Appendix 3 - FUNCTION Z_BPS_EXIT_FILE_SAVE_INIT. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(I_AREA) TYPE UPC_Y_AREA *" VALUE(I_PLEVEL) TYPE UPC_Y_PLEVEL OPTIONAL *" VALUE(I_PACKAGE) TYPE UPC_Y_PACKAGE OPTIONAL *" VALUE(I_METHOD) TYPE UPC_Y_METHOD OPTIONAL *" VALUE(I_PARAM) TYPE UPC_Y_PARAM OPTIONAL *" REFERENCE(IT_EXITP) TYPE UPF_YT_EXITP OPTIONAL *" REFERENCE(ITO_CHASEL) TYPE UPC_YTO_CHASEL OPTIONAL *" REFERENCE(ITO_CHA) TYPE UPC_YTO_CHA OPTIONAL *" REFERENCE(ITO_KYF) TYPE UPC_YTO_KYF OPTIONAL *" EXPORTING *" REFERENCE(ETO_CHAS) TYPE ANY TABLE *" REFERENCE(ET_MESG) TYPE UPC_YT_MESG *"---------------------------------------------------------------------- DATA: lto_chas TYPE yto_chas, ls_chas TYPE ys_chas, ls_mesg TYPE upc_ys_mesg, ls_chasel TYPE upc_ys_chasel, ls_charng TYPE upc_ys_charng. field-symbols <f> type any. * DATA: ls_file TYPE ys_file, * l_content TYPE string, * l_line TYPE string, * l_filelen TYPE i. * Create one dummy combination * If we don't do this, the upload won't work since the second function * will not be executed at all in case no transaction data exists so far. * The combination must be a subset of the planning level! CLEAR ls_chas. LOOP AT ito_chasel INTO ls_chasel. READ TABLE ls_chasel-t_charng INTO ls_charng INDEX 1. IF sy-subrc = 0. ASSIGN COMPONENT ls_chasel-chanm OF STRUCTURE ls_chas TO <f>. IF sy-subrc = 0. <f> = ls_charng-low. ENDIF. ENDIF. ENDLOOP. COLLECT ls_chas INTO lto_chas. eto_chas = lto_chas. ENDFUNCTION.

Page 24: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 24

Appendix 4 - FUNCTION Z_BPS_EXIT_FILE_SAVE. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(I_AREA) TYPE UPC_Y_AREA OPTIONAL *" VALUE(I_PLEVEL) TYPE UPC_Y_PLEVEL OPTIONAL *" VALUE(I_METHOD) TYPE UPC_Y_METHOD OPTIONAL *" VALUE(I_PARAM) TYPE UPC_Y_PARAM OPTIONAL *" VALUE(I_PACKAGE) TYPE UPC_Y_PACKAGE OPTIONAL *" REFERENCE(IT_EXITP) TYPE UPF_YT_EXITP OPTIONAL *" REFERENCE(ITO_CHASEL) TYPE UPC_YTO_CHASEL OPTIONAL *" REFERENCE(ITO_CHA) TYPE UPC_YTO_CHA OPTIONAL *" REFERENCE(ITO_KYF) TYPE UPC_YTO_KYF OPTIONAL *" EXPORTING *" REFERENCE(ET_MESG) TYPE UPC_YT_MESG *" CHANGING *" REFERENCE(XTH_DATA) TYPE HASHED TABLE *"---------------------------------------------------------------------- TYPE-POOLS abap. DATA: lt_data TYPE yt_data. lt_data = xth_data. REFRESH gt_file1. * Transfer data to be save into file structure LOOP AT lt_data INTO ls_data. CLEAR ls_file. MOVE-CORRESPONDING ls_data-s_chas TO ls_file. MOVE-CORRESPONDING ls_data-s_kyfs TO ls_file. APPEND ls_file TO gt_file1. CLEAR ls_data. ENDLOOP. SORT gt_file1. ls_file-0fiscyear = 'FYr'. ls_file-0costcenter = 'CostCtr'. ls_file-0acttype = 'Acttype'. ls_file-col1 = 'Col1'. ls_file-co12 = 'Col2'. ls_file-col3 = 'Col3'. INSERT ls_file INTO gt_file1 INDEX 1. EXPORT content FROM gt_file1 TO MEMORY ID 'EXPORT_TABLE_DATA. REFRESH gt_file1. ENDFUNCTION.

Page 25: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 25

Appendix 5 - FUNCTION Z_BPS_EXIT_FILE_WEB. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(I_AREA) TYPE UPC_Y_AREA *" VALUE(I_PLEVEL) TYPE UPC_Y_PLEVEL OPTIONAL *" VALUE(I_PACKAGE) TYPE UPC_Y_PACKAGE OPTIONAL *" VALUE(I_METHOD) TYPE UPC_Y_METHOD OPTIONAL *" VALUE(I_PARAM) TYPE UPC_Y_PARAM OPTIONAL *" REFERENCE(IT_EXITP) TYPE UPF_YT_EXITP OPTIONAL *" REFERENCE(ITO_CHASEL) TYPE UPC_YTO_CHASEL OPTIONAL *" REFERENCE(ITO_CHA) TYPE UPC_YTO_CHA OPTIONAL *" REFERENCE(ITO_KYF) TYPE UPC_YTO_KYF OPTIONAL *" EXPORTING *" REFERENCE(ETO_CHAS) TYPE ANY TABLE *" REFERENCE(ET_MESG) TYPE UPC_YT_MESG *"---------------------------------------------------------------------- DATA: lto_chas TYPE yto_chas, ls_chas TYPE ys_chas, ls_mesg TYPE upc_ys_mesg, ls_chasel TYPE upc_ys_chasel, ls_charng TYPE upc_ys_charng, l_select TYPE string, l_dummy(72) TYPE c. DATA: ls_file TYPE ys_file, l_content TYPE string, l_line TYPE string, l_filelen TYPE i. FIELD-SYMBOLS: <f> TYPE ANY. ASSIGN gt_file1 TO <fs>. IMPORT content TO l_content FROM MEMORY ID 'Z_BPS_FILE_UPLOAD'. IF sy-subrc <> 0 OR l_content IS INITIAL. * No data loaded MESSAGE e001(upf) INTO l_dummy WITH 'No data in file'. CLEAR ls_mesg. MOVE-CORRESPONDING syst TO ls_mesg. APPEND ls_mesg TO et_mesg. EXIT. ENDIF. FREE MEMORY ID v_upload. TRY. * Convert file content into structured table * TAB-delimited file PERFORM gui_char_conv TABLES <fs> " data table USING l_content " file contents 'X' " has_field_separator 'X' " read_by_line space " dat_mode space " codepage 'X' " ignore_cerr '#' " replacement CHANGING l_filelen. " file length CATCH cx_root. MESSAGE e001(upf) INTO l_dummy WITH 'Data conversion error.'.

Page 26: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 26

CLEAR ls_mesg. MOVE-CORRESPONDING syst TO ls_mesg. APPEND ls_mesg TO et_mesg. EXIT. ENDTRY. * Create one dummy combination * If we don't do this, the upload won't work since the second function * will not be executed at all in case no transaction data exists so far. * The combination must be a subset of the planning level! CLEAR ls_chas. LOOP AT ito_chasel INTO ls_chasel. READ TABLE ls_chasel-t_charng INTO ls_charng INDEX 1. IF sy-subrc = 0. ASSIGN COMPONENT ls_chasel-chanm OF STRUCTURE ls_chas TO <f>. IF sy-subrc = 0. <f> = ls_charng-low. ENDIF. ENDIF. ENDLOOP. COLLECT ls_chas INTO lto_chas. eto_chas = lto_chas. ENDFUNCTION. *&--------------------------------------------------------------------* *& Form gui_char_conv *&--------------------------------------------------------------------* * This routine is basically a copy of FORM gui_char_upload as * used in the function module GUI_UPLOAD. The difference is that * the file contents are passed as a parameter (STRING) instead * of being read from the front-end. *---------------------------------------------------------------------* FORM gui_char_conv TABLES par_data_tab USING par_file_contents TYPE string value(par_has_field_separator) TYPE c value(par_read_by_line) TYPE c value(par_dat_mode) TYPE c value(par_encoding) TYPE abap_encoding value(par_ignore_cerr) TYPE abap_bool value(par_replacement_char) TYPE abap_repl CHANGING par_filesize TYPE i. DATA: prc_error TYPE i VALUE 0, prc_position TYPE i VALUE 0. DATA: prc_dest_buffer TYPE string. DATA: strdecimal TYPE c, npacked TYPE p DECIMALS 2 VALUE 0, strtemp(10) TYPE c. DATA: strdatformat(10) TYPE c, ddate TYPE d VALUE '11112233', strfield(10) TYPE c, noffset TYPE i. CLASS cl_abap_char_utilities DEFINITION LOAD. " Determine decimal delimiter CLEAR strtemp. WRITE npacked TO strtemp(10). SEARCH strtemp FOR ','. IF sy-subrc EQ 0. strdecimal = ','. ELSE. strdecimal = '.'. ENDIF.

Page 27: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 27

" Determine date format WRITE ddate TO strfield DD/MM/YYYY. IF strfield CS '33'. ENDIF. noffset = sy-fdpos. CASE noffset. WHEN 0. strdatformat = 'DD.MM.YYYY'. WHEN 3. strdatformat = 'MM/DD/YYYY'. WHEN 8. strdatformat = 'YYYY/MM/DD'. ENDCASE. DATA: prc_strinput TYPE string. prc_strinput = par_file_contents. * If this upload should disregard CR/LF we need the * size of the first component and it must be * of a character type. IF par_read_by_line IS INITIAL. FIELD-SYMBOLS: <first_field> TYPE ANY. DATA: prc_data_type TYPE c VALUE space, prc_dest_data_length TYPE i VALUE 0. ASSIGN COMPONENT 1 OF STRUCTURE par_data_tab TO <first_field>. IF sy-subrc = 0. DESCRIBE FIELD <first_field> TYPE prc_data_type. IF prc_data_type <> 'C' AND prc_data_type <> 'g'. RAISE bad_data_format. ENDIF. DESCRIBE FIELD <first_field> LENGTH prc_dest_data_length IN CHARACTER MODE. IF sy-subrc <> 0. RAISE bad_data_format. ENDIF. ELSE. RAISE bad_data_format. ENDIF. ENDIF. DO. CLEAR prc_dest_buffer. DATA: prc_strinputlength TYPE i. prc_strinputlength = STRLEN( prc_strinput ). IF prc_strinputlength = 0. EXIT. ENDIF. * Find EOL in source buffer IF par_read_by_line IS NOT INITIAL. * Check if we have found a complete line and write it * to the data table. * Check for CR/LF FIND cl_abap_char_utilities=>cr_lf IN prc_strinput MATCH OFFSET prc_position. IF sy-subrc = 0. MOVE prc_strinput(prc_position) TO prc_dest_buffer. prc_position = prc_position + 2. SHIFT prc_strinput LEFT BY prc_position PLACES. ELSE. * Check for LF FIND cl_abap_char_utilities=>cr_lf+1(1) IN prc_strinput MATCH OFFSET prc_position. IF sy-subrc = 0. MOVE prc_strinput(prc_position) TO prc_dest_buffer. prc_position = prc_position + 1. SHIFT prc_strinput LEFT BY prc_position PLACES. ELSE.

Page 28: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 28

* Check for CR FIND cl_abap_char_utilities=>cr_lf(1) IN prc_strinput MATCH OFFSET prc_position. IF sy-subrc = 0. MOVE prc_strinput(prc_position) TO prc_dest_buffer. prc_position = prc_position + 1. SHIFT prc_strinput LEFT BY prc_position PLACES. ELSE. MOVE prc_strinput TO prc_dest_buffer. prc_strinput = ''. ENDIF. ENDIF. ENDIF. ELSE. * Check if the data read so far is longer than one line of the * data table. IF prc_dest_data_length > prc_strinputlength. prc_dest_data_length = prc_strinputlength. ENDIF. MOVE prc_strinput(prc_dest_data_length) TO prc_dest_buffer. SHIFT prc_strinput LEFT BY prc_dest_data_length PLACES. ENDIF. PERFORM write_line_to_data_tab IN PROGRAM saplsfes TABLES par_data_tab USING par_has_field_separator strdecimal strdatformat par_dat_mode CHANGING prc_dest_buffer. ENDDO. ENDFORM. " gui_char_conv

Page 29: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 29

Appendix 6 - FUNCTION Z_BPS_EXIT_FILE_LOAD. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(I_AREA) TYPE UPC_Y_AREA OPTIONAL *" VALUE(I_PLEVEL) TYPE UPC_Y_PLEVEL OPTIONAL *" VALUE(I_METHOD) TYPE UPC_Y_METHOD OPTIONAL *" VALUE(I_PARAM) TYPE UPC_Y_PARAM OPTIONAL *" VALUE(I_PACKAGE) TYPE UPC_Y_PACKAGE OPTIONAL *" REFERENCE(IT_EXITP) TYPE UPF_YT_EXITP OPTIONAL *" REFERENCE(ITO_CHASEL) TYPE UPC_YTO_CHASEL OPTIONAL *" REFERENCE(ITO_CHA) TYPE UPC_YTO_CHA OPTIONAL *" REFERENCE(ITO_KYF) TYPE UPC_YTO_KYF OPTIONAL *" EXPORTING *" REFERENCE(ET_MESG) TYPE UPC_YT_MESG *" CHANGING *" REFERENCE(XTH_DATA) TYPE HASHED TABLE *"---------------------------------------------------------------------- DATA: lt_bapiret TYPE STANDARD TABLE OF bapiret2, lt_data_cust TYPE STANDARD TABLE OF upc_ys_api_data, lt_row TYPE STANDARD TABLE OF upc_ys_api_row, lt_subrc TYPE sy-subrc, l_select type string. ASSIGN ls_file TO <wa> . IMPORT content TO l_select FROM MEMORY ID 'Z_BPS_FILE_UPLOAD'. CHECK NOT <fs> IS INITIAL. lt_data = xth_data. " Keep existing data * LOOP AT gt_file INTO ls_file. LOOP AT <fs> INTO <wa>. CHECK sy-tabix > 1. " Skip first line with field names CLEAR ls_data. ls_data-s_chas-0co_area = 'CONT'. MOVE-CORRESPONDING <wa> TO ls_data-s_chas. " Map characteristics MOVE-CORRESPONDING <wa> TO ls_data-s_kyfs. " Map key figures IF NOT ls_data-s_chas-0costcenter IS INITIAL. PERFORM add_leading_zeros USING ls_data-s_chas-0costcenter. ENDIF. IF l_select = 'append'. COLLECT ls_data INTO lt_data. ELSEIF l_select = 'overwrite'. MODIFY TABLE lt_data FROM ls_data. ENDIF. CLEAR <wa>. ENDLOOP. * Return loaded data to BPS xth_data = lt_data. * Refresh Memory FREE MEMORY ID v_select. * Clear temporary table REFRESH: <fs>, lt_data. ENDFUNCTION. *&---------------------------------------------------------------------*

Page 30: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 30

*& Form add_leading_zeros *&---------------------------------------------------------------------* * Add leading zeros for the variable. *----------------------------------------------------------------------* * -->P_INPUT Input Value *----------------------------------------------------------------------* FORM add_leading_zeros USING p_input. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = p_input IMPORTING output = p_input.

ENDFORM. "add_leading_zeros

Page 31: Upload and Download Data from BPS Web Layouts Without Using … · 2019. 11. 12. · Upload and Download Data from BPS Web Layouts Without Using the Excel Web Component from a Web

© 2006 SAP AG 31

Appendix 7 - FUNCTION-POOL ZBPSGROUP FUNCTION-POOL ZBPSGROUP TYPES: yth_data TYPE /1sem/_yth_data_100bpsaba02, yt_data TYPE /1sem/_yt_data_100bpsaba02, ys_data TYPE /1sem/_ys_data_100bpsaba02, yto_chas TYPE /1sem/_yto_chas_100bpsaba02, ys_chas TYPE /1sem/_ys_chas_100bpsaba02, ys_kyfs TYPE /1sem/_ys_index_100bpsaba02. TYPES: BEGIN OF ys_file, 0fiscyear(4), 0costcenter(10), 0acttype(6), 0emplgroup(1), Col1(10), Col2(10), Col3(10), END OF ys_file. DATA: lt_data TYPE yt_data, ls_data TYPE ys_data.

DATA: ls_file TYPE ys_file,

DATA: gt_file1 TYPE STANDARD TABLE OF ys_file WITH DEFAULT KEY.

FIELD-SYMBOLS: <fs> TYPE table,

<wa> TYPE ANY.