47
SAP BOBJ Planning & Consolidation (BPC), version for Netweaver How-To Guide How To... Use Start & End Routine BAdIs Applicable Releases: SAP BusinessObjects Planning and Consolidation 7.5 , version for NetWeaver, SP00 and higher. Version 1.0 August 2010

How to... Use Start & End Routine

Embed Size (px)

Citation preview

Page 1: How to... Use Start & End Routine

SAP BOBJ Planning &Consolidation (BPC),version for NetweaverHow-To Guide

How To... Use Start & End RoutineBAdIs

Applicable Releases:

SAP BusinessObjects Planning and Consolidation 7.5 , version forNetWeaver, SP00 and higher.

Version 1.0

August 2010

Page 2: How to... Use Start & End Routine

© Copyright 2010 SAP AG. All rights reserved.

No part of this publication may be reproduced ortransmitted in any form or for any purpose without theexpress permission of SAP AG. The information containedherein may be changed without prior notice.

Some software products marketed by SAP AG and itsdistributors contain proprietary software components ofother software vendors.

Microsoft, Windows, Outlook, and PowerPoint areregistered trademarks of Microsoft Corporation.

IBM, DB2, DB2 Universal Database, OS/2, ParallelSysplex, MVS/ESA, AIX, S/390, AS/400, OS/390,OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP,Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix,i5/OS, POWER, POWER5, OpenPower and PowerPC aretrademarks or registered trademarks of IBM Corporation.

Adobe, the Adobe logo, Acrobat, PostScript, and Readerare either trademarks or registered trademarks of AdobeSystems Incorporated in the United States and/or othercountries.

Oracle is a registered trademark of Oracle Corporation.

UNIX, X/Open, OSF/1, and Motif are registeredtrademarks of the Open Group.

Citrix, ICA, Program Neighborhood, MetaFrame,WinFrame, VideoFrame, and MultiWin are trademarks orregistered trademarks of Citrix Systems, Inc.

HTML, XML, XHTML and W3C are trademarks orregistered trademarks of W3C®, World Wide WebConsortium, Massachusetts Institute of Technology.

Java is a registered trademark of Sun Microsystems, Inc.

JavaScript is a registered trademark of Sun Microsystems,Inc., used under license for technology invented andimplemented by Netscape.

MaxDB is a trademark of MySQL AB, Sweden.

SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAPNetWeaver, and other SAP products and servicesmentioned herein as well as their respective logos aretrademarks or registered trademarks of SAP AG inGermany and in several other countries all over the world.All other product and service names mentioned are thetrademarks of their respective companies. Data containedin this document serves informational purposes only.National product specifications may vary.

These materials are subject to change without notice.These materials are provided by SAP AG and its affiliatedcompanies ("SAP Group") for informational purposes only,without representation or warranty of any kind, and SAPGroup shall not be liable for errors or omissions withrespect to the materials. The only warranties for SAPGroup products and services are those that are set forth inthe express warranty statements accompanying suchproducts and services, if any. Nothing herein should beconstrued as constituting an additional warranty.

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

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

SAP does not warrant the accuracy or completeness of theinformation, text, graphics, links or other items containedwithin these materials. SAP has no control over theinformation that you may access through the use of hotlinks contained in these materials and does not endorseyour use of third party web pages nor provide any warrantywhatsoever relating to third party web pages.

SAP NetWeaver “How-to” Guides are intended to simplifythe product implementation. While specific productfeatures and procedures typically are explained in apractical business context, it is not implied that thosefeatures and procedures are the only approach in solving aspecific business problem using SAP NetWeaver. Shouldyou wish to receive additional information, clarification orsupport, please refer to SAP Consulting.

Any software coding and/or code lines / strings (“Code”)included in this documentation are only examples and arenot intended to be used in a productive systemenvironment. The Code is only intended better explain andvisualize the syntax and phrasing rules of certain coding.SAP does not warrant the correctness and completeness ofthe Code given herein, and SAP shall not be liable forerrors or damages caused by the usage of the Code, exceptif such damages were caused by SAP intentionally orgrossly negligent.

Disclaimer

Some components of this product are based on Java™. Anycode change in these components may cause unpredictableand severe malfunctions and is therefore expressivelyprohibited, as is any decompilation of these components.

Any Java™ Source Code delivered with this product is onlyto be used by SAP’s Support Services and may not bemodified or altered in any way.

Page 3: How to... Use Start & End Routine

Document HistoryDocument Version Description

1.00 First official release of this guide

Page 4: How to... Use Start & End Routine

Typographic ConventionsType Style Description

Example Text Words or characters quotedfrom the screen. Theseinclude field names, screentitles, pushbuttons labels,menu names, menu paths,and menu options.Cross-references to otherdocumentation

Example text Emphasized words orphrases in body text, graphictitles, and table titles

Example text File and directory names andtheir paths, messages,names of variables andparameters, source text, andnames of installation,upgrade and database tools.

Example text User entry texts. These arewords or characters that youenter in the system exactly asthey appear in thedocumentation.

<Exampletext>

Variable user entry. Anglebrackets indicate that youreplace these words andcharacters with appropriateentries to make entries in thesystem.

EXAMPLE TEXT Keys on the keyboard, forexample, F2 or ENTER.

IconsIcon Description

Caution

Note or Important

Example

Recommendation or Tip

Page 5: How to... Use Start & End Routine

Table of Contents

1. Business Scenario ..........................................................................................................1

2. Background Information .................................................................................................1

3. Prerequisites....................................................................................................................2

4. Step-by-Step Procedure ..................................................................................................34.1 Create the Start Routine BAdI Implementation ..........................................................34.2 Create the End Routine BAdI Implementation ......................................................... 134.3 Test the BAdI Implementations ............................................................................... 22

5. Appendix ........................................................................................................................ 365.1 Source Code for Start Routine BAdI Implementation ............................................... 365.2 Source Code for End Routine BAdI Implementation ................................................ 40

Page 6: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 1

1. Business Scenario

SAP Business Objects Planning and Consolidation, version for Netweaver (herein referred to as“BPC”) Data Manager is designed to help the user to move data into and out of BPC. TransformationFiles and Conversion files are used to aid in the manipulation of the imported data before it is writtento the database. As of BPC 7.5, transformation files now support the use of two new parameteroptions, known as START_ROUTINE and END_ROUTINE. These parameters are used to triggerBAdI implementations on the backend ABAP system, where the user is allow to write custom ABAPcode to process the data to specific requirements. The START_ROUTINE is called after the data hasbeen read from the source, and before the transformation or conversion file logic is applied to it. TheEND_ROUTINE is called after all processing has been done, and just before the data is committed tothe database. In this guide, we will demonstrate how to implement both. For the START_ROUTINEBAdI implementation, we will implement a check which will ensure that an imported property valuelength is not greater than a certain length. For the END_ROUTINE BAdI implementation, we willimplement code which will retrieve a property value from a custom database table and updates theBPC master data accordingly.

2. Background Information

SAP Business Add-Ins (BAdIs) are one of the most important technologies used to adapt SAPsoftware to specific requirements. As of Release 7.0 of the SAP NetWeaver Application Server ABAP,BAdIs are part of the Enhancement Framework, where they represent explicit enhancement options.BAdIs are the basis for Object Plug-Ins that can enhance the functions in ABAP programs withouthaving to make core software modifications. As such, BAdI calls can be integrated into customerapplications (like BusinessObjects Planning and Consolidation, version for SAP NetWeaver forexample) to allow enhanced customization of standard application functionality.

This How-To Guide (HTG) describes the procedure for creating and configuring the Data ManagerStart Routine and End Routine BAdIs within BPC. The Step By Step section will outline the stepsneeded in order to create the BAdI itself in addition to the configuration required within BPC to actuallyexecute the BAdI. The Appendix section contains the example ABAP code that goes along with thisguide’s Business Scenario. This code is only meant as an example and while it will perform theactions described in this guide it may not match the exact needs of your own particular BusinessScenario – it is only intended to guide you in the creation of your own BAdI Implementation.

Page 7: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 2

3. Prerequisites

Required/recommended expertise or prior knowledge SAP BusinessObjects Planning and Consolidation 7.5, version for SAP NetWeaver, SP00 and

higher ABAP programming skills Access to SAP NetWeaver transaction codes: SE20, SE18, SE19, SE38, SE80, SE24, STMS

Additional Documentation RKT Online Knowledge Product

http://service.sap.com/rkt On the left hand side, navigate to SAP Ramp-Up KnowledgeTransfer -> SAP BusinessObjects EPM Solutions -> SAP BO PC 7.5, version for SAPNetWeaver

Other EPM How-To Guideshttp://wiki.sdn.sap.com/wiki/display/BPX/Enterprise+Performance+Management+%28EPM%29+How-to+Guides

SAP Help Library – Business Add Inshttp://help.sap.com/saphelp_nw70/helpdata/en/8f/f2e540f8648431e10000000a1550b0/frameset.htm

Page 8: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 3

4. Step-by-Step Procedure

A BAdI implementation is the term used in the Enhancement Framework for an enhancementimplementation element. A BAdI implementation consists of a BAdI implementation class thatimplements the BAdI interface. The BAdI implementation also contains a filter condition which isspecified in the BAdI definition. This filter condition can be used to execute the BAdI implementation atruntime.

4.1 Create the Start Routine BAdI Implementation...1

1. Log on to the NetWeaver system via SAPgui. Enter transaction SE18 and press “Enter“.

2. In the initial screen, enter the name of the corresponding enhancement spot. EnterUJD_ROUTINE, and click “Display“.

Page 9: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 4

3. On the left side of the screen, expand the BAdI definition tree by clicking on the icon. Youshould then see the following nodes.

Interf

Interface Filter Implementations

4. Right-click on the “Implementations” node, and choose “Create BAdI Implementation”.

Page 10: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 5

5. In some cases, a developer may have already created an enhancement implementation for thisenhancement spot for a different BAdI definition. If an enhancement implementation alreadyexists, a dialog listing all implementations will be displayed. Click the “Create” button in thelower right hand corner. If this dialog is not displayed, continue to step 6.

6. In this dialog, enter the name of the enhancement implementation and the short description.Name it as ZUJ_DM_ROUTINE_EX. Then click the green check to continue.

7. Enter the name of a package name for transporting this BAdI to another system in yourlandscape, or click “Local Object” if you do not plan to transport this BAdI.

Page 11: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 6

8. If you are presented with this dialog, then select your enhancement implementation which wasjust created in step 6, and click the green check. If there are no other previousimplementations, go directly to the dialog box shown in step 9.

9. In this dialog, enter the name of the BAdI Implementation as ZUJ_START_ROUTINE_EX_IMP,and enter the description. Also, enter the name of the implementing class asZCL_UJD_START_ROUTINE_EX.

10. Enter the name of a package name for transporting this BAdI to another system in yourlandscape, or click “Local Object” if you do not plan to transport this BAdI.

Page 12: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 7

11. The BAdI Implementation will then be saved. Notice it is not yet active.

12. Click on the icon next to the name of the BAdI Implementation. This will expose the followingnodes below.

Implementing Class Filter Values

Page 13: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 8

13. Double Click on the “Filter Val.” Node.

14. Click the “Change” icon.

15. Click on the “Combination” button from the filter values screen.

16. Next double click on the BADIIMPL_NAME line of the combination.

Page 14: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 9

17. Enter the name of the BAdI implementation into the “Value 1” field. This is the value which willbe passed in the transformation file later on. In this example, we will useZUJ_START_ROUTINE_EX_IMP for consistancy, but this value could be anything as long asthis name and the name used in the transformation file are the same . Next set the drop downbox for “Comparator 1” to “=”. Finally click the “Green Check” to continue.

18. Finally, save and activate by clicking the appropriate buttons.

Page 15: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 10

19. In the following dialog, first click the “Select All” button, and then the “Green Check” button. Allobjects should then be active.

20. Finally, the code which will be executed by the BAdI implementation can be inserted into theimplementing class. Double click on the “Implementing Class” node from the left side of thescreen.

21. Now double-click on the implementing class name.

Page 16: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 11

22. Due to forward navigation, the implementing class is displayed in the class builder tool. Click onthe “Change” icon. Then double-click on the RUNROUTINE method.

23. An empty method implementation will be shown. Notice, the method signature is displayed atthe top. If the method signature is not displayed, click the “Signature” button on the applicationtoolbar.

Page 17: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 12

24. Copy and paste the source code from Appendix 5.1 into the RUNROUTINE method. For theStart Routine BAdI, the IR_DATA parameter contains the importing data in a comma delimitedformat. In most cases, you will need to convert this comma delimited format to a structuredinternal table in order to work with the data efficiently. This example code shows how to do thisconversion. Also, this code will check the value of the PROFIT_CENTER column and ensurethat its length is not greater than 10.

Page 18: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 13

25. Save and activate the class by clicking the appropriate buttons.

4.2 Create the End Routine BAdI Implementation...1

1. Once again, log on to the NetWeaver system via SAPgui. Enter transaction SE18 and press“Enter“.

Page 19: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 14

2. In the initial screen, enter the name of the corresponding enhancement spot. EnterUJD_ROUTINE, and click “Display“.

3. On the left side of the screen, expand the BAdI definition tree by clicking on the icon. Youshould then see the following nodes.

Interf

Interface Filter Implementations

Page 20: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 15

4. Right-click on the “Implementations” node, and choose “Create BAdI Implementation”.

5. Select the enhancement implementation which was created in section 4.1

6. In this dialog, enter the name of the BAdI Implementation as ZUJ_END_ROUTINE_EX_IMP,and enter the description. Also, enter the name of the implementing class asZCL_UJD_END_ROUTINE_EX.

Page 21: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 16

7. Enter the name of a package name for transporting this BAdI to another system in yourlandscape, or click “Local Object” if you do not plan to transport this BAdI.

8. The BAdI Implementation will then be saved. Notice it is not yet active.

Page 22: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 17

9. Click on the icon next to the name of the BAdI Implementation. This will expose the followingnodes below.

Implementing Class Filter Values

10. Double Click on the “Filter Val.” Node.

11. Click the “Change” icon.

12. Click on the “Combination” button from the filter values screen.

Page 23: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 18

13. Next double click on the BADIIMPL_NAME line of the combination.

14. Enter the name of the BAdI implementation into the “Value 1” field. This is the value which willbe passed in the transformation file later on. In this example, we will useZUJ_END_ROUTINE_EX_IMP for consistancy, but this value could be anything as long as thisname and the name used in the transformation file are the same . Next set the drop down boxfor “Comparator 1” to “=”. Finally click the “Green Check” to continue.

15. Finally, save and activate by clicking the appropriate buttons.

Page 24: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 19

16. In the following dialog, first click the “Select All” button, and then the “Green Check” button. Allobjects should then be active.

17. Finally, the code which will be executed by the BAdI implementation can be inserted into theimplementing class. Double click on the “Implementing Class” node from the left side of thescreen.

18. Now double-click on the implementing class name.

Page 25: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 20

19. Due to forward navigation, the implementing class is displayed in the class builder tool. Click onthe “Change” icon. Then double-click on the RUNROUTINE method.

20. An empty method implementation will be shown. Notice, the method signature is displayed atthe top. If the method signature is not displayed, click the “Signature” button on the applicationtoolbar.

Page 26: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 21

21. Copy and paste the source code from Appendix 5.2 into the RUNROUTINE method. For theEnd Routine BAdI, the IR_DATA parameter contains the importing data in a structured format.So, unlike the Start Routine BAdI, you do not have to worry about converting the commadelimited format to a structured internal table. In this implementation, the value for ECC_CC willcome from a custom table ZECC_CC based on the ID value. Note: The ZECC_CC table will notexist in your system, and is only used as an example in this guide. You will need to implementyour own data retrieval logic in that section of code.

Page 27: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 22

22. Save and activate the class by clicking the appropriate buttons.

4.3 Test the BAdI Implementations

In this example, the P_CC dimension has been modified to include properties, PROFIT_CENTER andECC_CC. This guide assumes that the reader knows how to add properties to dimensions, so that willnot be covered here. The screenshot below shows the newly created properties and their lengths.

The PROFIT_CENTER value length will be checked by the Start Routine BAdI, and if it is too long, itwill reject the record. The ECC_CC value will be filled by the End Routine BAdI implementation byretrieving the value from a custom “Z” table based on the ID field. Note: This “Z” table will not exist inyour system. It is only used as an example implementation. The source data could potentially comefrom a number of other sources.

We will use the upload file shown below. This file has already been uploaded to the BPC file service.We will attempt to load the “Spain” and “Austria” cost center dimension members into the P_CCdimension. The PROFIT_CENTER property value length will be checked by the Start Routine BAdIimplementation, so in this case, we would expect the Austria record to be rejected as the value50000200001 is 11 characters long. The ECC_CC property value is blank in the file, and will be filledat runtime by the End Routine BAdI implementation. In this example, the value will be retrieved from acustom table, ZECC_CC. Again, this table will not exist in your system. We should expect to see theSpain record updated correctly.

Page 28: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 23

1. Go to the BPC Excel Client and log on to the application set. In this example, a copy ofAPSHELL called APSHELL_HTG is used.

2. From the action pane, click “Mange Data”.

Page 29: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 24

3. Click “Maintain Transformations”.

4. Click “Create New Transformation”.

Page 30: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 25

5. Insert a new row into the transformation file under the *OPTIONS section. Enter the parametername STARTROUTINE and assign the value ZUJ_START_ROUTINE_EX_IMP. This is thename that you provided when defining the filter for the BAdI implementation.

6. Insert another new row into the transformation file under the *OPTIONS section. Enter theparameter name ENDROUTINE and assign the value ZUJ_END_ROUTINE_EX_IMP. Again,this is the name that you provided when defining the filter for the BAdI implementation.

Page 31: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 26

7. Validate and save the transformation file by clicking the link in the action pane.

8. Save the file as transformation_badi_example.xls in the example folder.

Page 32: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 27

9. Close the transformation file and click on the “Manage Data” link from the action pane.

10. Click on “Run a Packaget”.

Page 33: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 28

11. Select “ImportMasterData”, and click “Run”.

Page 34: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 29

12. In this dialog, select the import file containing the new master data, for example P_CC_Data.txt.Again, this file has already been uploaded to the BPC file service. Next, select thetransformation file called “transformation_badi_example.xls” which you have just created.Select the appropriate dimension and click “Finish”.

13. Click “Ok”.

Page 35: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 30

14. Click the “View Status” button.

Page 36: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 31

15. The package should now be running.

Page 37: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 32

16. Once the package is complete, you can check the results by selecting the package and clickingthe “Detail” button.

Page 38: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 33

17. The detail screen shows that the Start and End Routines has been called successfully. Also,notice that the error raised from the Start Routine shows up in this log.

Page 39: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 34

18. Click on the Rejected Records node. The rejected Austria record shows here as well as thereason why it was rejected.

Page 40: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 35

19. From the Admin Console, you can check to make sure that the records have been createdsuccessfully. Spain has been added successfully.

Page 41: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 36

5. Appendix

5.1 Source Code for Start Routine BAdIImplementation

METHOD if_ujd_routine~runroutine.

TYPE-POOLS: abap.

DATA: lt_components TYPE abap_component_tab.

DATA: lt_columns TYPE TABLE OF string.

DATA: lt_column_data TYPE TABLE OF string.

DATA: lt_message TYPE uj0_t_message.

DATA: lt_error_reason TYPE uj0_t_message.

DATA: lv_tabix TYPE sy-tabix.

DATA: lo_dataref TYPE REF TO data.

DATA: lo_struct_descr TYPE REF TO cl_abap_structdescr.

DATA: lo_field_type TYPE REF TO cl_abap_datadescr.

FIELD-SYMBOLS: <lt_data_im> TYPE STANDARD TABLE.

FIELD-SYMBOLS: <lt_data_ex> TYPE STANDARD TABLE.

FIELD-SYMBOLS: <lt_data_er> TYPE STANDARD TABLE.

FIELD-SYMBOLS: <ls_components> TYPE abap_componentdescr.

FIELD-SYMBOLS: <ls_columns> TYPE string.

FIELD-SYMBOLS: <ls_column_data> TYPE ANY.

FIELD-SYMBOLS: <ls_data> TYPE ANY.

FIELD-SYMBOLS: <ls_message> TYPE uj0_s_message.

FIELD-SYMBOLS: <lt_data_struct> TYPE STANDARD TABLE.

FIELD-SYMBOLS: <ls_data_struct> TYPE ANY.

FIELD-SYMBOLS: <lv_data_field> TYPE ANY.

FIELD-SYMBOLS: <lv_line> TYPE ANY.

FIELD-SYMBOLS: <lv_profit_center> TYPE string.

* Assign importing data reference to field symbol

ASSIGN ir_data->* TO <lt_data_im>.

Page 42: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 37

* Create work area for importing data

CREATE DATA lo_dataref LIKE LINE OF <lt_data_im>.

ASSIGN lo_dataref->* TO <ls_data>.

* Create new internal table for exporting data and

* error data.

CREATE DATA lo_dataref LIKE TABLE OF <ls_data>.

ASSIGN lo_dataref->* TO <lt_data_ex>.

CREATE DATA lo_dataref LIKE TABLE OF <ls_data>.

ASSIGN lo_dataref->* TO <lt_data_er>.

* Move header row to exporting table, and remove from importing

* Store column names in LT_COLUMNS

READ TABLE <lt_data_im> ASSIGNING <ls_data> INDEX 1.

IF sy-subrc = 0.

ASSIGN COMPONENT `LINE` OF STRUCTURE <ls_data> TO <lv_line>.

SPLIT <lv_line> AT `,` INTO TABLE lt_columns.

APPEND <ls_data> TO <lt_data_ex>.

DELETE <lt_data_im> INDEX 1.

ENDIF.

* Build internal table with true columns from header row.

lo_field_type ?=

cl_abap_datadescr=>describe_by_name( `UJ_LARGE_STRING` ).

LOOP AT lt_columns ASSIGNING <ls_columns>.

APPEND INITIAL LINE TO lt_components ASSIGNING <ls_components>.

<ls_components>-name = <ls_columns>.

<ls_components>-type = lo_field_type.

ENDLOOP.

* Use RTTS to describe the structure

lo_struct_descr =

cl_abap_structdescr=>create(

p_components = lt_components

p_strict = abap_false ).

* Create structure from describer

CREATE DATA lo_dataref TYPE HANDLE lo_struct_descr.

ASSIGN lo_dataref->* TO <ls_data_struct> .

* Create internal table from structure

CREATE DATA lo_dataref LIKE TABLE OF <ls_data_struct> .

ASSIGN lo_dataref->* TO <lt_data_struct>.

Page 43: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 38

* Fill new structured internal table with data from importing parameter

LOOP AT <lt_data_im> ASSIGNING <ls_data>.

APPEND INITIAL LINE TO <lt_data_struct> ASSIGNING <ls_data_struct>.

ASSIGN COMPONENT `LINE` OF STRUCTURE <ls_data> TO <lv_line>.

SPLIT <lv_line> AT `,` INTO TABLE lt_column_data.

LOOP AT lt_column_data ASSIGNING <ls_column_data>.

ASSIGN COMPONENT sy-tabix

OF STRUCTURE <ls_data_struct> TO <lv_data_field>.

IF sy-subrc <> 0.

CONTINUE.

ENDIF.

<lv_data_field> = <ls_column_data>.

ENDLOOP.

ENDLOOP.

* Now you have a internal table with true columns.

* Loop each imported record and read corresponding

* record from structured internal table and perform

* check on profit center column, length must not be > 10.

LOOP AT <lt_data_im> ASSIGNING <ls_data>.

lv_tabix = sy-tabix.

READ TABLE <lt_data_struct> ASSIGNING <ls_data_struct> INDEX lv_tabix.

IF sy-subrc <> 0.

CONTINUE.

ENDIF.

* Get value of profit center

ASSIGN COMPONENT `PROFIT_CENTER` OF

STRUCTURE <ls_data_struct> TO <lv_profit_center>.

IF sy-subrc <> 0 OR <lv_profit_center> IS INITIAL.

CONTINUE.

ENDIF.

* Check the length, if > 10, add to reject table

* otherwise add to exporting table.

IF STRLEN( <lv_profit_center> ) > 10.

APPEND <ls_data> TO <lt_data_er>.

APPEND INITIAL LINE TO lt_error_reason ASSIGNING <ls_message>.

<ls_message>-msgid = `00`.

Page 44: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 39

<ls_message>-msgty = `E`.

<ls_message>-msgno = `208`.

<ls_message>-msgv1 = `Profit Center value can not be > 10`.

<ls_message>-recno = lv_tabix + 1. " Account for removed header line

<ls_message>-message = cl_uj_utl_message=>get_message_text(

i_language = sy-langu

is_message = <ls_message> ).

ELSE.

APPEND <ls_data> TO <lt_data_ex>.

ENDIF.

ENDLOOP.

IF lt_error_reason IS NOT INITIAL.

APPEND INITIAL LINE TO lt_message ASSIGNING <ls_message>.

<ls_message>-msgid = `00`.

<ls_message>-msgty = `E`.

<ls_message>-msgno = `208`.

<ls_message>-msgv1

= `Error occured during Start Routine BAdI processing`.

<ls_message>-message = cl_uj_utl_message=>get_message_text(

i_language = sy-langu

is_message = <ls_message> ).

ENDIF.

* Exporting data to exporting data reference

et_message = lt_message.

et_error_reason = lt_error_reason.

GET REFERENCE OF <lt_data_ex> INTO er_data.

GET REFERENCE OF <lt_data_er> INTO er_error_data.

ENDMETHOD.

Page 45: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 40

5.2 Source Code for End Routine BAdIImplementation

METHOD if_ujd_routine~runroutine.

DATA: lo_dataref TYPE REF TO data.

FIELD-SYMBOLS: <lt_data_im> TYPE STANDARD TABLE.

FIELD-SYMBOLS: <lt_data_ex> TYPE STANDARD TABLE.

FIELD-SYMBOLS: <ls_data> TYPE ANY.

FIELD-SYMBOLS: <lv_id> TYPE string.

FIELD-SYMBOLS: <lv_ecc_cc> TYPE string.

* Assign importing data reference to field symbol

ASSIGN ir_data->* TO <lt_data_im>.

* Create work area for importing data

CREATE DATA lo_dataref LIKE LINE OF <lt_data_im>.

ASSIGN lo_dataref->* TO <ls_data>.

* Create new internal table for exporting data

CREATE DATA lo_dataref LIKE TABLE OF <ls_data>.

ASSIGN lo_dataref->* TO <lt_data_ex>.

* Get ECC_CC value from custom table or other datasource

LOOP AT <lt_data_im> ASSIGNING <ls_data>.

* Get ID value

ASSIGN COMPONENT `ID` OF STRUCTURE <ls_data> TO <lv_id>.

IF sy-subrc <> 0 OR <lv_id> IS INITIAL.

CONTINUE.

ENDIF.

* Get reference to ECC_CC field

ASSIGN COMPONENT `ECC_CC` OF STRUCTURE <ls_data> TO <lv_ecc_cc>.

IF sy-subrc <> 0.

CONTINUE.

ENDIF.

Page 46: How to... Use Start & End Routine

How To... Use the Start & End Routine BAdI

August 2010 41

* Get cost center value from custom table ZECC_CC per ID

* and fill field in structure, then append to exporting table

* This is just an example of what can be done here, this value

* could potentially come from many other sources, but to keep

* it simple, this HTG simply gets a value from a “Z” table. This

* “Z” table will not exist in your system, so you must implement

* your own data retrieval method here.

* select single cost_center

* into <lv_ecc_cc>

* from zecc_cc

* where id = <lv_id>.

APPEND <ls_data> TO <lt_data_ex>.

ENDLOOP.

* Exporting data to exporting data references

GET REFERENCE OF <lt_data_ex> INTO er_data.

ENDMETHOD.

Page 47: How to... Use Start & End Routine

www.sdn.sap.com/irj/sdn/howtoguides