Uploaded by arbenn

Badi endroutine HTG

advertisement
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
© Copyright 2010 SAP AG. All rights reserved.
No part of this publication may be reproduced or
transmitted in any form or for any purpose without the
express permission of SAP AG. The information contained
herein may be changed without prior notice.
Some software products marketed by SAP AG and its
distributors contain proprietary software components of
other software vendors.
Microsoft, Windows, Outlook, and PowerPoint are
registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, OS/2, Parallel
Sysplex, 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 are
trademarks or registered trademarks of IBM Corporation.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader
are either trademarks or registered trademarks of Adobe
Systems Incorporated in the United States and/or other
countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered
trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame,
WinFrame, VideoFrame, and MultiWin are trademarks or
registered trademarks of Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or
registered trademarks of W3C®, World Wide Web
Consortium, 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 and
implemented by Netscape.
MaxDB is a trademark of MySQL AB, Sweden.
SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP
NetWeaver, and other SAP products and services
mentioned herein as well as their respective logos are
trademarks or registered trademarks of SAP AG in
Germany and in several other countries all over the world.
All other product and service names mentioned are the
trademarks of their respective companies. Data contained
in 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 affiliated
companies ("SAP Group") for informational purposes only,
without representation or warranty of any kind, and SAP
Group shall not be liable for errors or omissions with
respect to the materials. The only warranties for SAP
Group products and services are those that are set forth in
the express warranty statements accompanying such
products and services, if any. Nothing herein should be
construed as constituting an additional warranty.
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.
SAP NetWeaver “How-to” Guides 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 SAP NetWeaver. Should
you wish to receive additional information, clarification or
support, please refer to SAP Consulting.
Any software coding and/or code lines / strings (“Code”)
included in this documentation are only examples and are
not intended to be used in a productive system
environment. The Code is only intended better explain and
visualize the syntax and phrasing rules of certain coding.
SAP does not warrant the correctness and completeness of
the Code given herein, and SAP shall not be liable for
errors or damages caused by the usage of the Code, except
if such damages were caused by SAP intentionally or
grossly negligent.
Disclaimer
Some components of this product are based on Java™. Any
code change in these components may cause unpredictable
and severe malfunctions and is therefore expressively
prohibited, as is any decompilation of these components.
Any Java™ Source Code delivered with this product is only
to be used by SAP’s Support Services and may not be
modified or altered in any way.
Document History
Document Version
Description
1.00
First official release of this guide
Typographic Conventions
Icons
Type Style
Description
Icon
Example Text
Words or characters quoted
from the screen. These
include field names, screen
titles, pushbuttons labels,
menu names, menu paths,
and menu options.
Cross-references to other
documentation
Example text
Emphasized words or
phrases in body text, graphic
titles, and table titles
Example text
File and directory names and
their paths, messages,
names of variables and
parameters, source text, and
names of installation,
upgrade and database tools.
Example text
User entry texts. These are
words or characters that you
enter in the system exactly as
they appear in the
documentation.
<Example
text>
Variable user entry. Angle
brackets indicate that you
replace these words and
characters with appropriate
entries to make entries in the
system.
EXAMPLE TEXT
Keys on the keyboard, for
example, F2 or ENTER.
Description
Caution
Note or Important
Example
Recommendation or Tip
Table of Contents
1.
Business Scenario ..........................................................................................................1
2.
Background Information .................................................................................................1
3.
Prerequisites....................................................................................................................2
4.
Step-by-Step Procedure ..................................................................................................3
4.1
4.2
4.3
5.
Create the Start Routine BAdI Implementation ..........................................................3
Create the End Routine BAdI Implementation .........................................................13
Test the BAdI Implementations ............................................................................... 22
Appendix........................................................................................................................ 36
5.1
5.2
Source Code for Start Routine BAdI Implementation ............................................... 36
Source Code for End Routine BAdI Implementation ................................................ 40
How To... Use the Start & End Routine BAdI
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. Transformation
Files and Conversion files are used to aid in the manipulation of the imported data before it is written
to the database. As of BPC 7.5, transformation files now support the use of two new parameter
options, known as START_ROUTINE and END_ROUTINE. These parameters are used to trigger
BAdI implementations on the backend ABAP system, where the user is allow to write custom ABAP
code to process the data to specific requirements. The START_ROUTINE is called after the data has
been read from the source, and before the transformation or conversion file logic is applied to it. The
END_ROUTINE is called after all processing has been done, and just before the data is committed to
the database. In this guide, we will demonstrate how to implement both. For the START_ROUTINE
BAdI implementation, we will implement a check which will ensure that an imported property value
length is not greater than a certain length. For the END_ROUTINE BAdI implementation, we will
implement code which will retrieve a property value from a custom database table and updates the
BPC master data accordingly.
2.
Background Information
SAP Business Add-Ins (BAdIs) are one of the most important technologies used to adapt SAP
software 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 without
having to make core software modifications. As such, BAdI calls can be integrated into customer
applications (like BusinessObjects Planning and Consolidation, version for SAP NetWeaver for
example) to allow enhanced customization of standard application functionality.
This How-To Guide (HTG) describes the procedure for creating and configuring the Data Manager
Start Routine and End Routine BAdIs within BPC. The Step By Step section will outline the steps
needed in order to create the BAdI itself in addition to the configuration required within BPC to actually
execute the BAdI. The Appendix section contains the example ABAP code that goes along with this
guide’s Business Scenario. This code is only meant as an example and while it will perform the
actions described in this guide it may not match the exact needs of your own particular Business
Scenario – it is only intended to guide you in the creation of your own BAdI Implementation.
August 2010
1
How To... Use the Start & End Routine BAdI
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 Knowledge
Transfer -> SAP BusinessObjects EPM Solutions -> SAP BO PC 7.5, version for SAP
NetWeaver
Other EPM How-To Guides
http://wiki.sdn.sap.com/wiki/display/BPX/Enterprise+Performance+Management+%28EP
M%29+How-to+Guides
SAP Help Library – Business Add Ins
http://help.sap.com/saphelp_nw70/helpdata/en/8f/f2e540f8648431e10000000a1550b0/fr
ameset.htm
August 2010
2
How To... Use the Start & End Routine BAdI
4.
Step-by-Step Procedure
A BAdI implementation is the term used in the Enhancement Framework for an enhancement
implementation element. A BAdI implementation consists of a BAdI implementation class that
implements the BAdI interface. The BAdI implementation also contains a filter condition which is
specified in the BAdI definition. This filter condition can be used to execute the BAdI implementation at
runtime.
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. Enter
UJD_ROUTINE, and click “Display“.
August 2010
3
How To... Use the Start & End Routine BAdI
3. On the left side of the screen, expand the BAdI definition tree by clicking on the
should then see the following nodes.
icon. You
Interf
Interface
Filter
Implementations
4. Right-click on the “Implementations” node, and choose “Create BAdI Implementation”.
August 2010
4
How To... Use the Start & End Routine BAdI
5. In some cases, a developer may have already created an enhancement implementation for this
enhancement spot for a different BAdI definition. If an enhancement implementation already
exists, a dialog listing all implementations will be displayed. Click the “Create” button in the
lower 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 your
landscape, or click “Local Object” if you do not plan to transport this BAdI.
August 2010
5
How To... Use the Start & End Routine BAdI
8. If you are presented with this dialog, then select your enhancement implementation which was
just created in step 6, and click the green check. If there are no other previous
implementations, 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 as
ZCL_UJD_START_ROUTINE_EX.
10. Enter the name of a package name for transporting this BAdI to another system in your
landscape, or click “Local Object” if you do not plan to transport this BAdI.
August 2010
6
How To... Use the Start & End Routine BAdI
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 following
nodes below.
Implementing Class
Filter Values
August 2010
7
How To... Use the Start & End Routine BAdI
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.
August 2010
8
How To... Use the Start & End Routine BAdI
17. Enter the name of the BAdI implementation into the “Value 1” field. This is the value which will
be passed in the transformation file later on. In this example, we will use
ZUJ_START_ROUTINE_EX_IMP for consistancy, but this value could be anything as long as
this name and the name used in the transformation file are the same . Next set the drop down
box for “Comparator 1” to “=”. Finally click the “Green Check” to continue.
18. Finally, save and activate by clicking the appropriate buttons.
August 2010
9
How To... Use the Start & End Routine BAdI
19. In the following dialog, first click the “Select All” button, and then the “Green Check” button. All
objects should then be active.
20. Finally, the code which will be executed by the BAdI implementation can be inserted into the
implementing class. Double click on the “Implementing Class” node from the left side of the
screen.
21. Now double-click on the implementing class name.
August 2010
10
How To... Use the Start & End Routine BAdI
22. Due to forward navigation, the implementing class is displayed in the class builder tool. Click on
the “Change” icon. Then double-click on the RUNROUTINE method.
23. An empty method implementation will be shown. Notice, the method signature is displayed at
the top. If the method signature is not displayed, click the “Signature” button on the application
toolbar.
August 2010
11
How To... Use the Start & End Routine BAdI
24. Copy and paste the source code from Appendix 5.1 into the RUNROUTINE method. For the
Start Routine BAdI, the IR_DATA parameter contains the importing data in a comma delimited
format. In most cases, you will need to convert this comma delimited format to a structured
internal table in order to work with the data efficiently. This example code shows how to do this
conversion. Also, this code will check the value of the PROFIT_CENTER column and ensure
that its length is not greater than 10.
August 2010
12
How To... Use the Start & End Routine BAdI
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“.
August 2010
13
How To... Use the Start & End Routine BAdI
2. In the initial screen, enter the name of the corresponding enhancement spot. Enter
UJD_ROUTINE, and click “Display“.
3. On the left side of the screen, expand the BAdI definition tree by clicking on the
should then see the following nodes.
icon. You
Interf
Interface
Filter
Implementations
August 2010
14
How To... Use the Start & End Routine BAdI
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 as
ZCL_UJD_END_ROUTINE_EX.
August 2010
15
How To... Use the Start & End Routine BAdI
7. Enter the name of a package name for transporting this BAdI to another system in your
landscape, 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.
August 2010
16
How To... Use the Start & End Routine BAdI
9. Click on the icon next to the name of the BAdI Implementation. This will expose the following
nodes 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.
August 2010
17
How To... Use the Start & End Routine BAdI
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 will
be passed in the transformation file later on. In this example, we will use
ZUJ_END_ROUTINE_EX_IMP for consistancy, but this value could be anything as long as this
name and the name used in the transformation file are the same . Next set the drop down box
for “Comparator 1” to “=”. Finally click the “Green Check” to continue.
15. Finally, save and activate by clicking the appropriate buttons.
August 2010
18
How To... Use the Start & End Routine BAdI
16. In the following dialog, first click the “Select All” button, and then the “Green Check” button. All
objects should then be active.
17. Finally, the code which will be executed by the BAdI implementation can be inserted into the
implementing class. Double click on the “Implementing Class” node from the left side of the
screen.
18. Now double-click on the implementing class name.
August 2010
19
How To... Use the Start & End Routine BAdI
19. Due to forward navigation, the implementing class is displayed in the class builder tool. Click on
the “Change” icon. Then double-click on the RUNROUTINE method.
20. An empty method implementation will be shown. Notice, the method signature is displayed at
the top. If the method signature is not displayed, click the “Signature” button on the application
toolbar.
August 2010
20
How To... Use the Start & End Routine BAdI
21. Copy and paste the source code from Appendix 5.2 into the RUNROUTINE method. For the
End 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 comma
delimited format to a structured internal table. In this implementation, the value for ECC_CC will
come from a custom table ZECC_CC based on the ID value. Note: The ZECC_CC table will not
exist in your system, and is only used as an example in this guide. You will need to implement
your own data retrieval logic in that section of code.
August 2010
21
How To... Use the Start & End Routine BAdI
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 and
ECC_CC. This guide assumes that the reader knows how to add properties to dimensions, so that will
not 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, it
will reject the record. The ECC_CC value will be filled by the End Routine BAdI implementation by
retrieving the value from a custom “Z” table based on the ID field. Note: This “Z” table will not exist in
your system. It is only used as an example implementation. The source data could potentially come
from 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_CC
dimension. The PROFIT_CENTER property value length will be checked by the Start Routine BAdI
implementation, so in this case, we would expect the Austria record to be rejected as the value
50000200001 is 11 characters long. The ECC_CC property value is blank in the file, and will be filled
at runtime by the End Routine BAdI implementation. In this example, the value will be retrieved from a
custom table, ZECC_CC. Again, this table will not exist in your system. We should expect to see the
Spain record updated correctly.
August 2010
22
How To... Use the Start & End Routine BAdI
1. Go to the BPC Excel Client and log on to the application set. In this example, a copy of
APSHELL called APSHELL_HTG is used.
2. From the action pane, click “Mange Data”.
August 2010
23
How To... Use the Start & End Routine BAdI
3. Click “Maintain Transformations”.
4. Click “Create New Transformation”.
August 2010
24
How To... Use the Start & End Routine BAdI
5. Insert a new row into the transformation file under the *OPTIONS section. Enter the parameter
name STARTROUTINE and assign the value ZUJ_START_ROUTINE_EX_IMP. This is the
name 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 the
parameter 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.
August 2010
25
How To... Use the Start & End Routine BAdI
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.
August 2010
26
How To... Use the Start & End Routine BAdI
9. Close the transformation file and click on the “Manage Data” link from the action pane.
10. Click on “Run a Packaget”.
August 2010
27
How To... Use the Start & End Routine BAdI
11. Select “ImportMasterData”, and click “Run”.
August 2010
28
How To... Use the Start & End Routine BAdI
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 the
transformation file called “transformation_badi_example.xls” which you have just created.
Select the appropriate dimension and click “Finish”.
13. Click “Ok”.
August 2010
29
How To... Use the Start & End Routine BAdI
14. Click the “View Status” button.
August 2010
30
How To... Use the Start & End Routine BAdI
15. The package should now be running.
August 2010
31
How To... Use the Start & End Routine BAdI
16. Once the package is complete, you can check the results by selecting the package and clicking
the “Detail” button.
August 2010
32
How To... Use the Start & End Routine BAdI
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.
August 2010
33
How To... Use the Start & End Routine BAdI
18. Click on the Rejected Records node. The rejected Austria record shows here as well as the
reason why it was rejected.
August 2010
34
How To... Use the Start & End Routine BAdI
19. From the Admin Console, you can check to make sure that the records have been created
successfully. Spain has been added successfully.
August 2010
35
How To... Use the Start & End Routine BAdI
5.
5.1
Appendix
Source Code for Start Routine BAdI
Implementation
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>.
August 2010
36
How To... Use the Start & End Routine BAdI
* 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>.
August 2010
37
How To... Use the Start & End Routine BAdI
* 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`.
August 2010
38
How To... Use the Start & End Routine BAdI
<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.
August 2010
39
How To... Use the Start & End Routine BAdI
5.2
Source Code for End Routine BAdI
Implementation
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.
August 2010
40
How To... Use the Start & End Routine BAdI
* 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.
August 2010
41
www.sdn.sap.com/irj/sdn/howtoguides
Download