27
7/25/2019 BW 'How-To' http://slidepdf.com/reader/full/bw-how-to- 1/27 SAP (SAP AG and SAP America, Inc.) 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 warranty 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 Consulting. How to… Load a Flat File into BW-BPS Using a Web Browser SEM-BPS / BW-BPS ASAP “How to…” Paper Applicable Release: SEM 3.1 / BW 3.5 or greater July 2005

BW 'How-To' 系列 一

Embed Size (px)

Citation preview

Page 1: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 1/27

SAP (SAP AG and SAP America, Inc.) 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 impliedwarranties 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 thatmay 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 thesematerials. SAP has no control over the information that you may access through the use of hot links contained in these materials anddoes not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages.

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

How to…

Load a Flat File into BW-BPSUsing a Web Browser

SEM-BPS / BW-BPS 

ASAP “How to…” Paper 

Applicable Release: SEM 3.1 / BW 3.5 or greater

July 2005

Page 2: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 2/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

1  BUSINESS SCENARIO ......................... ........................... ........................... ........................... ...2 

2  THE RESULT ........................... .......................... ........................... ........................... .................2 

3  THE STEP-BY-STEP SOLUTION..............................................................................................3 

4  START THE FILE UPLOAD ........................... ........................... ........................... ................... 10 

5  COMMENTS........................ ........................... ........................... ........................... ................... 12 

6  SUMMARY...............................................................................................................................12  

7  APPENDIX A: LOAD FUNCTION ....................... ........................... ........................... ............... 13 

8  APPENDIX B: INIT FUNCTION (WEB)....................................................................................14 

9  APPENDIX C: GLOBAL DATA (FILE STRUCTURE)......................... ........................... ..........20 

10  APPENDIX D: EXAMPLE FILE ....................... ........................... ........................... ............... 21 

11  APPENDIX E: BSP APPLICATION......................................................................................22 

Page 3: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 3/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

1 Business Scenario

This document describes a solution developed for BW-BPS that lets you prompt the end user for a

file name (or specify i t in a parameter group) and load the data directly from the file into BW-BPS.The purpose is to give the user an easy to use mechanism to load flat files using a web browser.

Note: There’s a similar “How-to” paper that describes a solution for loading data into BW-BPS forSAPGUI based front-ends (planning workbench or planning folders).

Version History

September 2003 Initial release of “How-to” paper.

November 2003 BW release (no functional changes).

December 2003 Chapter 8: Minor correction in INIT function module: Add message class UPF.

Chapter 11.2: Add include JS.HTM in layout.

August 2004 Chapter 11.4: Correction of BSP page required for BW 3.5 Support Pack 4.

July 2005 Chapter 4: Correction for session handling (logon/logoff). Use different startURL for the file upload.

2 The Result

The data of the flat file is loaded into BW-BPS and is ready to be processed further or be saved intothe underlying InfoCube.

Page 4: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 4/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

3 The Step-By-Step Solution

1.  Preliminary remarks The solution requires you to implement two ABAP

function modules as part of a function group. Thereforeyou need to have basic programming skills and theauthorizations to do the programming in your system.

2.  Create a new function group

Run transaction SE37. Then select Goto Function Groups Create Group.

Enter a group name, a description andsave it.

Select a package and save the definition

to a transport.

3.  Create function module A

In transaction SE37, create a functionmodule according to appendix A.

Adjust the IF-statement according toyour requirements in order to overwriteor add loaded to existing data. Note: You can make a copy of function

UPB_ALV_EXIT, which will provide you with thecorrect interface specification already.

Page 5: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 5/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

4.  Create function module B

In transaction SE37, create a functionmodule according to appendix B.

The combination of characteristics

values that is created at the end of thisfunction must be a subset of theplanning level.

Note: You can make a copy of functionUPB_ALV_EXIT_INIT, which will provide you with thecorrect interface specification already.

5.  Define the file structure in the globaldata of the function group

While you are editing the one of thefunction modules, select Goto Globaldata. Then maintain the file structure as

defined in the example in appendix C.

Adjust the file structure to yourrequirements. You must use thetechnical names of the characteristicsand key figures for a 1:1 field mapping.

You also need to change the typedefinitions to reflect the client andplanning area you are working on.

Page 6: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 6/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

6.  Save all and activate all programs

7.  Set up the planning framework

Define a planning level that includes allcharacteristics and key figures that youwant to load.

(It is possible to select morecharacteristics and key figures than arein the file. However they will remain

empty.)

Create a planning package thatcorresponds to the contents of the file.

Page 7: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 7/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

8.  Create a planning function

You can now create a planning functionof type “Exit function” for the givenplanning level.

Then specify the two function modules

A and B, which you implemented insteps 3 and 4.

Important: All fields of the level need to be included in the list of fields to bechanged.

Page 8: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 8/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

9.  Create a parameter group

There are no parameters for thefunction. Simply create an empty

parameter group.

10. Create a new web interface

Run transaction BPS_WB. Click on the“new” button and create a new webinterface containing just one page.

Note: The web interface is actually notused by the file upload. However, thefile upload web page will make use ofthe generated BSP application.

Page 9: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 9/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

11. Generate the web interface

Click on “Generate” (Edit Generate).Enter a description and generate theweb interface.

12. Add a new BSP page to the web

interface.

Run transaction SE80. In the repository browser, select the BSP application thatmatches the technical name of the webinterface (ZFILE).

13. Add a new BSP page

Right-click on “Page with Flow Logic”and select “Create”. Enter the pagename (ZFILE_UPLOAD.htm) and adescription.

Maintain the properties, layout, eventhandler, and page attributes according

to Appendix E.

In the event handler, adjust theplanning objects of the API callaccording to the planning area, level,package, function, and parameter groupthat you have specified in steps 7 to 9.

Page 10: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 10/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

14. Activate the BSP page

Check and activate the new BSP page.

Page 11: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 11/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

4 Start the File Upload

1.  Determine the start URL

In order to ensure correct sessionhandling (logon/logoff), the start URLneeds to point to the original webinterface. The file upload page is passedas a parameter to the web interface.

General format of the start URL:

http://<server>:<port>/sap/bc/bsp/sap/<web_interace>/<web_interface>.HTM?bps-page=<upload_pageHTM

If you follow the naming used in this how-to paper,then the URL would be:

http://<server>:<port>/sap/bc/bsp/sap/ZFILE/ZFIE.HTM?bps-page=ZFILE_UPLOAD.HTM

Note: Check the capitalization in SE80.

2.  Start the BSP application

Paste the URL into the address bar ofyour browser. Of course the URL can beassigned to a portals role or stored as alocal bookmark.

Note: The URL in the screen shots is just an example.

3.  Select the upload file and start theupload.

Either type in the file name or click the“Browse” button and select the file.

Then click on the “Upload” button.

The system will now read the file andstart the planning function to processthe file contents. The data will be storedin the BPS buffer (same as with anyother planning function).

Page 12: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 12/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

4.  Save the data

Click the “Save” button to store the datain BPS.

The system will display either a successor an error message.

5.  Exit the BSP application

If the data was successfully loaded andsaved, you click the “Exit” button torelease the locked data and make itavailable for further processing in BPS.

Page 13: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 13/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

5 Comments

•  The load function is solely based on internal values. For example, dates have to be loaded

in the YYYYMMDD format.

•  In the field mapping, pay extra attention to leading zeros as they are often not included infiles but required by InfoObjects.

•  You need to make assumptions regarding decimal notation and date/time formats. Eitherstick to one fixed format or foresee different conditions in the function module.

•  The field mapping is straightforward in the example (move-corresponding) since thetechnical names of the characteristics and key figures are used to define the fi le structure. Ofcourse, you can add more complex mapping rules in the LOOP-statement of the functionmodule A.

•  If the combination of characteristics values that is created at the end of function module B isNOT a subset of the planning level, you will get error “The generated data is not contained in

the selection condition.” (UPC 204).

•  All coding lines that need to be changed to match your configuration are marked by:“ <<<< ADJUST 

•  Do not re-generate the Web Interface! This would delete the new File Upload BSP page.

6 Summary

When implementing this exit planning function you need only few coding adjustments to fit to yourrequirements and setup of BW-BPS. The user gets a very easy to use function to load data from alocal flat f ile via a web browser into BW-BPS.

Page 14: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 14/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

7 Appendix A: Load Function

FUNCTION z_sem_bps_exit_file_load.*"--------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" REFERENCE(I_AREA) TYPE UPC_Y_AREA*" REFERENCE(I_PLEVEL) TYPE UPC_Y_PLEVEL*" REFERENCE(I_PACKAGE) TYPE UPC_Y_PACKAGE*" REFERENCE(I_METHOD) TYPE UPC_Y_METHOD*" REFERENCE(I_PARAM) TYPE UPC_Y_PARAM*" REFERENCE(IT_EXITP) TYPE UPF_YT_EXITP*" REFERENCE(ITO_CHASEL) TYPE UPC_YTO_CHASEL*" REFERENCE(ITO_CHA) TYPE UPC_YTO_CHA*" REFERENCE(ITO_KYF) TYPE UPC_YTO_KYF*" EXPORTING*" REFERENCE(ET_MESG) TYPE UPC_YT_MESG*" CHANGING

*" REFERENCE(XTH_DATA) TYPE HASHED TABLE*"--------------------------------------------------------------------

DATA: lt_data TYPE yt_data,ls_data TYPE ys_data.

DATA: ls_file TYPE ys_file.

* Has any data been loaded?CHECK NOT gt_file[] IS INITIAL.

* Overwrite existing data or add to existing data?* Change the IF depending on which alternative you requireIF 1 = 1. “ <<<< ADJUST REFRESH lt_data. " Delete and overwrite existing data

ELSE.lt_data = xth_data. " Keep existing data

ENDIF.

* Map and merge loaded dataLOOP AT gt_file INTO ls_file.CHECK sy-tabix > 1. " Skip first line with field namesCLEAR ls_data.MOVE-CORRESPONDING ls_file TO ls_data-s_chas. " Map characteristicsMOVE-CORRESPONDING ls_file TO ls_data-s_kyfs. " Map key figuresCOLLECT ls_data INTO lt_data.

ENDLOOP.

* Return loaded data to BPS

xth_data = lt_data.

* Clear temporary tableREFRESH gt_file.

ENDFUNCTION.

Page 15: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 15/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

8 Appendix B: Init Function (Web)

FUNCTION z_sem_bps_exit_file_web.*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" REFERENCE(I_AREA) TYPE UPC_Y_AREA*" REFERENCE(I_PLEVEL) TYPE UPC_Y_PLEVEL*" REFERENCE(I_PACKAGE) TYPE UPC_Y_PACKAGE*" REFERENCE(I_METHOD) TYPE UPC_Y_METHOD*" REFERENCE(I_PARAM) TYPE UPC_Y_PARAM*" REFERENCE(IT_EXITP) TYPE UPF_YT_EXITP*" REFERENCE(ITO_CHASEL) TYPE UPC_YTO_CHASEL*" REFERENCE(ITO_CHA) TYPE UPC_YTO_CHA*" REFERENCE(ITO_KYF) TYPE UPC_YTO_KYF*" EXPORTING*" REFERENCE(ETO_CHAS) TYPE ANY TABLE*" REFERENCE(ET_MESG) TYPE UPC_YT_MESG

*"----------------------------------------------------------------------

CONSTANTS:c_memory_id_file_upload TYPE memory_id VALUE 'Z_SEM_BPS_FILE_UPLOAD'.

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

REFRESH gt_file.

* Retrieve file content from memoryIMPORT content TO l_content FROM MEMORY ID c_memory_id_file_upload.IF sy-subrc <> 0 OR l_content IS INITIAL.

* No data loadedMESSAGE e001(upf) INTO l_dummy WITH 'No data in file'. “<<<CHANGECLEAR ls_mesg.MOVE-CORRESPONDING syst TO ls_mesg.APPEND ls_mesg TO et_mesg.

EXIT.ENDIF.FREE MEMORY ID c_memory_id_file_upload.

TRY.* Convert file content into structured table* TAB-delimited file

PERFORM gui_char_convTABLES gt_file " data tableUSING l_content " file contents

Page 16: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 16/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

'X' " has_field_separator'X' " read_by_linespace " dat_modespace " codepage'X' " ignore_cerr'#' " replacement

CHANGING l_filelen. " file length

CATCH cx_root.MESSAGE e001(upf) INTO l_dummy WITH 'Data conversion error.'.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_convTABLES par_data_tabUSING par_file_contents TYPE string

value(par_has_field_separator) TYPE cvalue(par_read_by_line) TYPE cvalue(par_dat_mode) TYPE cvalue(par_encoding) TYPE abap_encodingvalue(par_ignore_cerr) TYPE abap_boolvalue(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.

Page 17: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 17/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

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.

* DATA: conv TYPE REF TO cl_abap_conv_in_ce,* prc_encoding(20) TYPE c.** prc_encoding = par_encoding.

CLASS cl_abap_char_utilities DEFINITION LOAD.

" Determine decimal delimiterCLEAR strtemp.WRITE npacked TO strtemp(10).SEARCH strtemp FOR ','.IF sy-subrc EQ 0.strdecimal = ','.

ELSE.strdecimal = '.'.

ENDIF.

" Determine date formatWRITE 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: strhexdata TYPE xstring.* CLEAR strhexdata.** strhexdata = par_file_contents.*** Check if BOM exists and remove it. Set codepage if available* DATA: prc_hexdata_length TYPE i VALUE 0.* DATA: prc_bom_encoding TYPE abap_encoding.** prc_hexdata_length = xstrlen( strhexdata ).* IF prc_hexdata_length >= 2.** DATA: prc_bom2(2) TYPE x.* MOVE strhexdata(2) TO prc_bom2.** IF prc_bom2 = cl_abap_char_utilities=>byte_order_mark_little.* prc_bom_encoding = '4103'.* SHIFT strhexdata LEFT BY 2 PLACES IN BYTE MODE.* ELSE.* IF prc_bom2 = cl_abap_char_utilities=>byte_order_mark_big.* prc_bom_encoding = '4102'.

Page 18: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 18/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

* SHIFT strhexdata LEFT BY 2 PLACES IN BYTE MODE.* ELSE.* IF prc_hexdata_length >= 3.** DATA: prc_bom3(3) TYPE x.* MOVE strhexdata(3) TO prc_bom3.*

* IF prc_bom3 = cl_abap_char_utilities=>byte_order_mark_utf8.* prc_bom_encoding = '4110'.* SHIFT strhexdata LEFT BY 3 PLACES IN BYTE MODE.* ENDIF.** ENDIF.* ENDIF.* ENDIF.** ENDIF.** IF prc_encoding IS INITIAL.* prc_encoding = prc_bom_encoding.* ENDIF.** IF prc_encoding IS INITIAL.* DATA cp(4) TYPE c.* CALL 'CUR_LCL' ID 'GUICP' FIELD cp.* prc_encoding = cp.* ENDIF.** IF NOT prc_encoding IS INITIAL.* TRY.* CALL METHOD cl_abap_conv_in_ce=>create* EXPORTING* encoding = prc_encoding** ENDIAN =* replacement = par_replacement_char* ignore_cerr = par_ignore_cerr

* input = strhexdata* RECEIVING* conv = conv.* CATCH cx_parameter_invalid_range.* RAISE unknown_error.* CATCH cx_sy_codepage_converter_init.* RAISE unknown_error.* ENDTRY.* ELSE.* RAISE unknown_error.* ENDIF.** DATA: prc_strinput TYPE string.* TRY.* CALL METHOD conv->read* IMPORTING* data = prc_strinput* len = par_filesize.* CATCH cx_sy_conversion_codepage.* RAISE unknown_error.* CATCH cx_sy_codepage_converter_init.* RAISE unknown_error.* CATCH cx_parameter_invalid_type.* RAISE unknown_error.* CATCH cx_parameter_invalid_range.

Page 19: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 19/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

* RAISE unknown_error.* ENDTRY.

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 bufferIF 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/LFFIND 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_strinputMATCH OFFSET prc_position.

IF sy-subrc = 0.MOVE prc_strinput(prc_position) TO prc_dest_buffer.

Page 20: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 20/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

prc_position = prc_position + 1.SHIFT prc_strinput LEFT BY prc_position PLACES.

ELSE.* Check for CR

FIND cl_abap_char_utilities=>cr_lf(1) IN prc_strinputMATCH 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 saplsfesTABLES par_data_tabUSING par_has_field_separator

strdecimalstrdatformatpar_dat_mode

CHANGING prc_dest_buffer.ENDDO.

ENDFORM. " gui_char_conv

Page 21: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 21/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

9 Appendix C: Global Data (File Structure)

FUNCTION-POOL z_file.

TYPE-POOLS: abap.

* File structure:* The following type declaration defines the order and length of the fields* in the file that should be loaded into BW-BPS.* ADJUST >>>> TYPES: BEGIN OF ys_file,

0version(3),0fiscvarnt(2),0fiscyear(4),0company(6),0currency(5),0amount(25),

END OF ys_file.

* <<<< ADJUST 

* File data:* Global table to temporarily store loaded data.DATA: gt_file TYPE STANDARD TABLE OF ys_file WITH DEFAULT KEY.

* Type definitions:* Structures and tables that correspond to the planning area.* Note: Replace client number (800) and area (ZFILE) corresponding to your setup.* ADJUST >>>> TYPES: yth_data TYPE /1sem/_yth_data_800zfile,

yt_data TYPE /1sem/_yt_data_800zfile,ys_data TYPE /1sem/_ys_data_800zfile,yto_chas TYPE /1sem/_yto_chas_800zfile,ys_chas TYPE /1sem/_ys_chas_800zfile,ys_kyfs TYPE /1sem/_ys_kyfs_800zfile.

* <<<< ADJUST 

Page 22: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 22/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

10 Appendix D: Example File

Assumption for the example:

a) First line of the file contains field descriptions (maximum length in brackets)

b) Version field has leading zeros

c) Decimal point is used for amounts

d) Save the data as “Text (Tab delimited)”

Example file:

0version(3) 0fiscvarnt(2) 0fiscyear(4) 0company(6) 0currency(5) 0amount(25)

001 K4 2002 C1000 EUR 1234.56001 K4 2002 C2000 GBP 789.01

001 K4 2003 C1000 EUR 23.45

001 K4 2003 C2000 GBP 67.89

Page 23: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 23/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

11 Appendix E: BSP Application

Using transaction SE80, add a new BSP page to the existing BSP application that has been

generated for the web interface.

11.1 Properties

Property Value

Description BW-BPS File Upload

Mime Type text/html

Page Type Page with Flow Logic

Status Stateful from Now On

Lifetime Request

Page 24: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 24/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

11.2 Layout

<%@page language="abap" %> <%@extension name="bsp" prefix="bsp" %> <%@include file="checkbrowser.htm" %> 

<%@include file="js.htm" %> <html><head><link type="text/css" href="<%= cstyle %>" rel="stylesheet"><meta http-equiv="Pragma" content="no-cache"><title>BW-BPS File Upload</title></head><body id="sem_upwb-page_body" class="sapBdy"><table CELLSPACING='1' class=""><TR><TD><span class="sapTxtH2" title="">BW-BPS File Upload</span></TD></TR><TR><TD><form method="post" enctype="multipart/form-data" >

<input type="file" name="file" size="80" method="post"><br><input type="submit" name="OnInputProcessing(submitButton)" value="Upload"

class="sapBtnStd">&nbsp;<input type="submit" name="OnInputProcessing(saveButton)" value="Save" clas

s="sapBtnStd"><%" Remove the HTML comments if you want a separate EXIT button

%> <!--

&nbsp;

<input type="submit" name="OnInputProcessing(exitButton)" value="Exit" class="sapBtnStd">-->

</form></TD></TR>

</table><%if message_count > 0.

%> <%= cl_upwb=>get_html_table(

abap_table = messagesvisible_fields = 'ICON&TEXT'title_field = 'DESCR'

id = 'msg_table'link_click = 'bpsOpenMsgLong-URI_PARAMS'footer_visible = ' 'header_visible = ' ' ). %> 

<%endif.

%> </form></body></html> 

Page 25: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 25/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

11.3 Event Handler: OnInitialization

* event handler for data retrieval

runtime->keep_context = 1.

11.4 Event Handler: OnInputProcessing

*----------------------------------------------------------------------* Definitions*----------------------------------------------------------------------

CONSTANTS:c_memory_id_file_upload TYPE memory_id VALUE 'Z_SEM_BPS_FILE_UPLOAD'.

DATA:lv_objname TYPE lxeobjname,lr_page TYPE REF TO if_http_entity,l_content_path TYPE string,l_content TYPE string,l_subrc TYPE sy-subrc,ls_bapiret TYPE bapiret2,lt_bapiret TYPE STANDARD TABLE OF bapiret2,ls_mesg TYPE upc_ys_mesg,lt_mesg TYPE upc_yt_mesg.

*----------------------------------------------------------------------* Event Handler: OnInputProcessing*----------------------------------------------------------------------

REFRESH lt_mesg.

CASE event_id.

*...SUBMIT.............................................................WHEN 'submitButton'.

lv_objname = request->get_form_field( 'file' ).lr_page = request->get_multipart( 1 ).l_content_path = lr_page->get_header_field( '~content_filename' ).l_content = lr_page->get_cdata( ).

IF l_content IS NOT INITIAL.

* Export file contents to memoryEXPORT content FROM l_content TO MEMORY ID c_memory_id_file_upload.

* Optionally set the selection in the ad-hoc package* CALL FUNCTION 'API_SEMBPS_ADHOCPACKAGE_SET'...

* Execute planning functionCALL FUNCTION 'API_SEMBPS_FUNCTION_EXECUTE'EXPORTINGi_area = 'ZFILE' " <<<< ADJUST i_plevel = 'PL000001' " <<<< ADJUST 

Page 26: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 26/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

©©©©2005 SAP AG AND SAP AMERICA, INC.

i_package = '0-ADHOC' " <<<< ADJUST i_function = 'PF000003' " <<<< ADJUST i_param = 'PG000003' " <<<< ADJUST 

IMPORTINGe_subrc = l_subrc

TABLESetk_return = lt_bapiret.

* Add messages to logLOOP AT lt_bapiret INTO ls_bapiret.CLEAR ls_mesg.ls_mesg-msgty = ls_bapiret-type.ls_mesg-msgid = ls_bapiret-id.ls_mesg-msgno = ls_bapiret-number.ls_mesg-msgv1 = ls_bapiret-message_v1.ls_mesg-msgv2 = ls_bapiret-message_v2.ls_mesg-msgv3 = ls_bapiret-message_v3.ls_mesg-msgv4 = ls_bapiret-message_v4.APPEND ls_mesg TO lt_mesg.

ENDLOOP.

ENDIF. "data

*...SAVE & EXIT........................................................WHEN 'saveButton'.

* Save data to databaseCALL FUNCTION 'API_SEMBPS_POST'

IMPORTINGe_subrc = l_subrces_return = ls_bapiret.

* Add messages to logCLEAR ls_mesg.IF l_subrc = 0.

ls_mesg-msgty = 'I'.

ls_mesg-msgid = 'UPWB'.ls_mesg-msgno = '178'.

ELSE.ls_mesg-msgty = ls_bapiret-type.ls_mesg-msgid = ls_bapiret-id.ls_mesg-msgno = ls_bapiret-number.ls_mesg-msgv1 = ls_bapiret-message_v1.ls_mesg-msgv2 = ls_bapiret-message_v2.ls_mesg-msgv3 = ls_bapiret-message_v3.ls_mesg-msgv4 = ls_bapiret-message_v4.

ENDIF.APPEND ls_mesg TO lt_mesg.

*...EXIT...............................................................* Add the following line if you want a separate EXIT button* WHEN 'exitButton'.

* Release locksCALL FUNCTION 'API_SEMBPS_REFRESH'

IMPORTINGe_subrc = l_subrces_return = ls_bapiret.

* Add messages to logCLEAR ls_mesg.

Page 27: BW 'How-To' 系列 一

7/25/2019 BW 'How-To'

http://slidepdf.com/reader/full/bw-how-to- 27/27

HOW TO… LOAD A FLAT FILE INTO BW-BPS USING A WEB BROWSER 

IF l_subrc = 0.ls_mesg-msgty = 'I'.ls_mesg-msgid = 'UPWB'.ls_mesg-msgno = '001'.ls_mesg-msgv1 = 'Data has been unlocked.'.ls_mesg-msgv2 = 'It is now save to close this browser window.'.

ELSE.

ls_mesg-msgty = ls_bapiret-type.ls_mesg-msgid = ls_bapiret-id.ls_mesg-msgno = ls_bapiret-number.ls_mesg-msgv1 = ls_bapiret-message_v1.ls_mesg-msgv2 = ls_bapiret-message_v2.ls_mesg-msgv3 = ls_bapiret-message_v3.ls_mesg-msgv4 = ls_bapiret-message_v4.

ENDIF.APPEND ls_mesg TO lt_mesg.

ENDCASE. "event_id

* Message handlingIF lt_mesg IS INITIAL.

REFRESH messages.

ELSE.

* >>> BEGIN OF INSERT (as of BW 3.5 SP 4)* Set runtime environment for componentscl_upwb=>bsp_oninputprocessing(

event_id = event_idruntime = runtimenavigation = navigationpage = pagerequest = requestversion = 104 ).

* <<< END OF INSERT

* Prepare message for outputCALL FUNCTION 'UPWB_PREPARE_MESSAGES'EXPORTING

it_mesg = lt_mesgIMPORTING

et_mesg = messages.

ENDIF. "lt_mesg

DESCRIBE TABLE messages LINES message_count.

11.5 Page Attributes

Attribute Auto Typing Associated Type Description

messages Off TYPE UPWB_YT_MSG_TRAY Messages in Message Tray

message_count Off TYPE I Number of Messages