Sie sind auf Seite 1von 7

www.SAPtips.

com SAPtipsJournal
Page 1

ABAP Programming In BW
By Arthur "Pat" Pesa, arthurpesa, inc.

Editor's Note: With all the talk mine the what’s, where’s and targets. Therefore, we will need to
about NetWeaver and SAP® Java how’s of ABAP programming in be specifically aware of how we
Connector and other hot tools, BW. These "tips" on ABAP and proceed with our data or record
you'd think ABAP was a thing of BW are written with BW version updates and where we decide to
the past. But not so, as BW 3.0 and R/3 4.6C in mind, but place ABAP programming that
expert Pat Pesa can attest. In most of them will apply to any will manage these updates. Hav-
this excellent "best of" article, versions of R/3 from 4.x and up, ing said that, we can now exam-
Pat shares the most valuable and any versions of BW from 2.0 ine what possibilities exist for
ABAP techniques he has used on and up. using ABAP to customize our BW
BW projects. He starts by environment.
addressing the key questions:
What are the uses of ABAP in What Can We Do With
BW? How is programming in In order to ABAP in BW?
BW different than programming As with anything, in SAP the
in R/3? What ABAP tools are understand how words and phrase "ABAP pro-
available in BW? Then, Pat digs gramming" routinely surface as
into some technical examples of topics and questions during
ABAP-BW in action. This arti- ABAP is used in BW, implementation. However,
cle provides technical managers between SAP R/3 and BW, there
with a handy overview of Pat's we should have a are distinct differences between
February/March 2004 Volume II Issue 1

ABAP-BW methodology, and how we can use ABAP program-


gives ABAP programmers a general understand- ming in these environments and
technical guide they can refer to what we can expect as an outcome
on their BW initiatives. ing of the of development. In order to
understand how ABAP is used in
BW, we should have a general
This article will focus on the infrastructure of BW. understanding of the infrastruc-
concepts and strategies that con- ture of BW. Generally speaking, in
stitute best practices regarding the BW, we are dealing with Objects
use of ABAP programming in BW. This article will begin with an that we connect with some type of
On each project I have been overview of the prospective configuration, such as the linking
involved with, the use of ABAP involvement of ABAP code, where of an ODS with an InfoCube, or
programming has had a profound we can find this code, and how the creation of source system def-
effect on our ability to model the best to include coding for specific initions and datasources. What we
SAPtipsJournal

correct business processes within areas without impacting other will NOT be doing on a general
BW. During the design and blue- functionality. Our examples for basis in BW is building screens
print stage, a core functional this article will include R/3 data- and multiple user exits in ABAP
process is the determination of the source modifications and the cre- to gain additional functionality.1
corresponding business logic ation of generic extractors in R/3 This is the distinct difference in
found in R/3 or legacy data sys- for use with BW. BW as it relates to R/3. So if we're
tems and how to accomplish the not using ABAP for user exits and
same logic in BW. Fortunately To get the ball rolling, I would screens, then how will we use
SAP® has provided several struc- like to start off with the following ABAP? In BW, we will use ABAP
tured paths to follow in order to considerations. Remember that in to transform our data as require-
implement this business logic. In SAP BW, most everything is inter- ments dictate, as well as provide
this article, I will lay the ground- connected, and we share a great additional processing during
work from which we can deter- deal of data amongst several data extraction and updates.
1 One thing to note: we are provided with one user exit in SAP R/3 that will enable the management of data being extracted and one user exit in BW that will enable the
management of data being queried.

SAPtips © 2004 Klee Associates, Inc.


www.SAPtips.com SAPtipsJournal
Page 2

Within the ABAP language are Technical Area Description


certain constructs that allow us BEx User Exit Allows the creation and population of variables and calculations for key
to get work done within this figures and variables on a runtime basis. This user exit is called each time
environment. In SAP, we will be BEx is executed.
using the ABAP Workbench to R/3 User Exit This user exit is found in R/3 under CMOD and contains additional pro-
create our code. This is true for gramming that is needed to fill field additions to extract structures. We can
each instance we are writing also create additional business logic against data prior to its transfer to
code, whether it is from within a BW.
transfer rule, update rule, or BW Transfer rules These rules are invoked as data is transferred from R/3 to BW, or from
start routine. It is important to within BW as export data sources and InfoSources are created.
understand the fundamental BW Update Rules These rules are invoked as data is being updated into data targets.
concepts of the ABAP workbench Whether ODS Objects or InfoCubes, each update results in the execution of
in order to proceed. First, we an Update Rule.
should be familiar with the con- BW Start Routines Start routines in BW Update Rules are used to manage whole subsets of
structs of programming, such as data. This is different than a simple update rule in that update rules are
understanding what a sub rou- data element specific.
tine does, how a function module
Figure 2: BW and R/3 ABAP Programming Options
works, etc. Also, we should
understand the different avenues
we may use in order to debug our Where Are We Able to Cre- between functional and technical
code. This last measure is of ate ABAP Programming in is often much more gray than the
extreme importance, since it will BW? distinction in R/3. To cite one
be necessary to debug code from An often-asked question prior to example: we can configure objects
February/March 2004 Volume II Issue 1

time to time in order to create the beginning of a BW project in BW, thus gaining a great deal of
what our requirements dictate. revolves around how much ABAP functionality, without writing an
For the purposes of this article, programming will be necessary. array of user exits as found in R/3.
we will assume that the reader Following the construct of a typi-
already has a grounding in these cal R/3-BW integration, one Let’s take a look at where we
basic ABAP concepts, including would assume that all ABAP are able to augment our BW
the ABAP Workbench. would be done by a team of pro- development with ABAP and
grammers and that the BW con- what that may mean to the sys-
Our approach to ABAP develop- sultants would furnish documen- tem performance. Generally,
ment in BW will follow the simple tation around the changes to be when adding code, we can
guidelines found in Figure 1. made. However, in BW, the line assume some type of run time
overhead in the form of process-
• Requirements ing time or memory impact.
However, when programmed in
o Programming actions in the form of pseudo-code or a high level flow of data
SAPtipsJournal

an expedient and concise man-


• Design – determining where our data resides and how we would want it transformed. ner, the overhead may be
insignificant. At this time, we
• Deciding where to place our code: within the transfer logic or update logic, or within the user should familiarize ourselves with
exit in R/3 or BW.
where BW will permit customer-
• Actual ABAP development and programming. provided ABAP programming.
• Unit testing within the ABAP Workbench.
Now let's look at the options
o Make sure the individual code performs what it is meant to do. found within BW that allow the
additional implementation of
o Debugging works well here, using breakpoints.
ABAP programming (see Figure 2).
• Integration testing
The list in Figure 2 represents
o In BW, this is usually accomplished via data extraction and/or loading.
the areas within BW that may
require ABAP expertise during a
Figure 1: Basic Guidelines for ABAP Programming in BW BW implementation. This list cov-

SAPtips © 2004 Klee Associates, Inc.


www.SAPtips.com SAPtipsJournal
Page 3

ers 99 percent of the Option 1 • Add fields to append structure for an existing extract structure.
examples of ABAP
development in BW. I • Add corresponding ABAP logic to fill these fields.
say that because Option 2 • Create a table or view that represents our data set.
there is always that • Use Transaction RSO2 to create a generic extractor.
one exception in
which a customiza- • Add code to function module or user exit to fill fields or modify data in
tion has been done structure during extraction.
outside this matrix.
Now that we have Figure 3: ABAP Programming Options in R/3 for BW
covered the what’s
and where’s of ABAP
programming in BW,
we can have a look at
User Exit Description
the how’s.
SAPLRSAU_001 Transactional data user exit
How Do We
SAPLRSAU_002 Master Data User exit
Manage Our
Programming SAPLRSAU_003 Optional
During the
Development SAPLRSAU_004 Optional
Phase?
Let’s start at the Figure 4: R/3 User Exit Examples in BW
February/March 2004 Volume II Issue 1

beginning. By the
beginning, I mean
the point on our BW
project where we first start look- A commonly overlooked step user exit we want to use. Using
ing in R/3 and figuring out what in adding fields to extract struc- transaction code CMOD, go to
we can modify prior to or during tures and filling them with data your BW project, i.e., "Z_BW".
extraction. As a rule of thumb, is actually making the newly This project will be found with-
the concept here will be as fol- added fields visible to the BW in the customer namespace.
lows. In R/3, we have access to target system. Once the fields are Once you have found the correct
the raw transactional data set we added to the extract structure project, choose "display compo-
will want to modify. We have sev- and you have saved and activat- nents" and hit F7. This will dis-
eral options here, but primarily, ed both the append structure play the BW user exit compo-
we can either modify an existing and the extract structure, you nents. You should find four user
data extractor or create a new will need to go to transaction exits. The configuration of these
SAPtipsJournal

customized extractor from the code RSA6 -> Post Processing user exits may differ from sys-
ground-up. Let’s look at the two Datasources and find the data- tem to system. Figure 4 con-
options in the table in Figure 3. source you modified. Double tains the descriptions of the
click on that datasource and four user exits found in a
Option 1 make sure you uncheck the CMOD BW Project.
This is the most straightforward "hide" check box for the added
modification in ABAP and is com- fields. Otherwise, these fields To provide an example, let's
monly employed to add data will not show up in the newly consider a standard-delivered
requirements that do not exist in replicated datasource in BW. data extractor found within
the standard extractor. We do this Logistics Cockpit. This extrac-
using the basic concept of append At this point, we can look at tor is responsible for extracting
structures for our additional how we can populate these purchase order item data found
fields. Once we have added our fields with data in the R/3-to- in R/3. For our example, let’s
fields and activated our extract BW user exit in R/3. To provide assume you have added several
structure, we will be able to see some background, I will briefly fields to the 2LIS_02_ITM
these fields in the user exit. mention how to navigate to the extract structure.

SAPtips © 2004 Klee Associates, Inc.


www.SAPtips.com SAPtipsJournal
Page 4

You now want to add your pro- case i_datasource.


gramming logic to fill these fields
and then re-initialize BW. You will when '2LIS_02_ITM'.
double click on SAPLRSAU_001 * begin of code add on 02/25/2003
and you will be taken to the cor- CLEAR i_mc02m_0itm.
rect include file for the top-level LOOP AT c_t_data INTO i_mc02m_0itm.
program SAPLRSAU_001. Once
there, you will double click on the
*06-06-2002 new-begin
include ZZRSAU01. This include * select single pspel from aufk into i_mc02m_0itm-zzposid
is where all your customer logic * where aufnr = ekkn-nplnr.
will be written. Let’s examine the *
structure of this include and lend SELECT SINGLE b~posid INTO i_mc02m_0itm-zzposid FROM aufk AS a
some insight into how and where INNER JOIN prps AS b ON a~pspel = b~pspnr
WHERE a~aufnr = i_mc02m_0itm-zznplnr.
to add our code within this
include. This include, or user exit, * SELECT SINGLE vornr FROM afvc INTO i_mc02m_0itm-zzvornr
is based on case logic, meaning we * WHERE aufpl = ekkn-aufpl
will use a case statement to deter- * AND aplzl = ekkn-aplzl.
mine where we will land within *06-06-2002 new-end
the exit during runtime. Please * SELECT SINGLE * FROM prps CLIENT SPECIFIED
refer to the structure found in Fig- * WHERE mandt = sy-mandt
ure 5 within the include. Note that * AND pspnr = ekkn-ps_psp_pnr.
you may have to create the case *
logic prior to adding your addi- * IF sy-subrc = 0.
* i_mc02m_0itm-posid = prps-posid.
February/March 2004 Volume II Issue 1

tional logic. * ENDIF.


MODIFY c_t_data FROM i_mc02m_0itm.
From this point, you will use CLEAR i_mc02m_0itm.
"when" statements to control ENDIF.
entry into your logic. An example
ENDLOOP.
would be Figure 6.
Figure 7: PO Account Assignment Programming Example
Once you begin extraction and
the extract structure has been
filled with the initial data from data to each record. In this user within the loop, you will add all
standard extracts, you will find exit, you will loop through each the new data elements to the
yourself within the When logic record and append the necessary actual extract structure and
and ready to begin to append data. Then, in the final step return to the next record. Loop
like this through each record
SAPtipsJournal

INCLUDE ZZRSAU01. until you are finished with each


CASE I_datasource. record in the initial extract struc-
ture. Figure 7 illustrates ABAP
***User managed code***
written to append account
ENDCASE. assignment data to a purchase
order item.
Figure 5: Case Logic Example
While the code in Figure 7 is not
INCLUDE ZZRSAU01. all-inclusive, it clearly illustrates
CASE I_datasource. how to integrate your ABAP pro-
gramming into the correct user exit.
WHEN ‘2LIS_02_ITM’.
Do Something….. Option 2
ENDCASE. Now let’s look at Option 2 (ref-
erence Figure 3). In Option 2, we
Figure 6: When Logic Example are going to create a generic data-

SAPtips © 2004 Klee Associates, Inc.


www.SAPtips.com SAPtipsJournal
Page 5

source using standard SAP R/3


• Create a view and use RSO2 to allow the system to create the code.
technical components. Much of
the actual extract code will be cre-
ated for our use; we will need only • Create structure that defines our extract and also create a function module that performs
to specify several aspects, such as the extract.
the extract structure and function
module. Or, we can use a view and
allow R/3 to generate everything Figure 8: Generic Extractor Options
for our use. Please keep in mind
that once we complete this step, ument number and MANDT 6. Input the view name, making
we can gain the same access as "client" to ensure that you sure the correct options are
illustrated in option 1 during will get only the records you checked for using a view
extraction. Before we get into want and not multiples on instead of an extract struc-
examples, let’s review our options the same record across ture/function module and
in creating a generic extractor clients. click the save button.
found in figure 8.
Now, taking into consideration 7. If you’re successful, you can
Creating a view in R/3 permits these tips on creating a view, we go to RSA3 and run the
easy definition of our extract can build our view so that it con- extract checker for you new
based on several tables. Here are tains the fields we have identified datasource.
several important considerations and want in the generic data
in creating a view in R/3: extract. 8. You should double check the
RSA3 output with the view
February/March 2004 Volume II Issue 1

1. When using multiple tables, 1. Calling transaction SE11 and definition as a unit test. This
you will have to provide the setting the radio button to will give you a preliminary
joins for the tables based on View, we input the Z****** fitness test for the generic
the keys found in each table. name for our view and click datasource.
If you don’t, then the system Create.
will make each field within Now let's consider the second
your view a key for the view. 2. When prompted for a devel- option in creating a generic data-
This will impact view per- opment class, input the cor- source. First, you will need to
formance during runtime. rect development class and define a structure that will serve
click save. This will bring us as an extract structure for your
2. You will have to include unit to the initial view definition program. In creating an extract
references for quantity and screen. structure please refer to the fol-
price data elements. You lowing rules:
should use the same reference 3. Begin by adding the fields
SAPtipsJournal

field found within the data ele- you need, supplying the base • Make sure you include units
ment itself. This reference field table names as well. You will for quantities and price data.
is simply added to the view. need to complete all the steps
required to finish the view. • Make sure you include the
3. You should consider using appropriate keys for the data
the top-level tables within 4. Once done and active, check you will be working with,
your view even in the event to see how many records your such as document numbers
you will not use fields from view returns and compare and/or item numbers.
these tables. For example, that number to the number
when creating a view from of records found in the base As for the extract function
"Material Plant data", table(s). module, you should plan on cre-
MARD, you should join the ating a simple function module
"Material Master general 5. Once you have your view and following the guidelines
data", MARA, document completely finished, you can found in the example function
number with the MARD doc- go to transaction RSO2. module RSAX_BIW_GET_DATA.

SAPtips © 2004 Klee Associates, Inc.


www.SAPtips.com SAPtipsJournal
Page 6

I have attempted to layout, in


logical order, the basic areas in
which ABAP is used, when it is
In the end, creating a appropriate to create customized
logic, and how to go about pro-
customized user gramming the environment to get
what you want out of R/3 and into
experience is really BW. Specifically, we covered the
relevant aspects of the R/3 envi-
ronment, such as the user exit
what it is all about. SAPLRSAU_001, and how to
implement basic modifications. We
looked at how the user exit works
and how it is called during run-
Following this example will time. We detailed the basic exam-
ensure compatibility creating the ples of creating generic extractors
generic extractor with the struc- using base tables in R/3 and in
ture/function module combina- views or function modules, and we
tion. In this article, we will not laid out specific tips regarding the
detail the creation of a function successful creation of these compo-
module based on nents and how they interact.
RSAX_BIW_GET_DATA, but I
will note that it will be relatively Remembering the many things
February/March 2004 Volume II Issue 1

simple to create a datasource that can be done in BW using


once the function module is com- ABAP is the key to successfully
plete. The extractor definition is addressing the requirements of
created in the same manner as the customized reporting. We have
first example using RSO2, but we furnished you with the basic con-
will specify our structure name as cepts and included examples of
well as the function module real situations and logic used in
instead of the view. Once it is production environments. It is
saved and active, it is ready. Also now up to your team to determine
remember that you may make how you may move your environ-
changes to the logic in both the ment to the next level.
function module itself or within
the user exit SAPLRSAU_001. Arthur "Pat" Pesa, arthurpesa,
inc. Pat is a senior independent
SAPtipsJournal

Conclusion consultant specializing in SAP


In the end, creating a cus- Business Warehouse and Applica-
tomized user experience is really tion Link Enabling. He has over
what it is all about, and it is up to nine years of SAP R/3 experience,
the development team to imple- specializing in ABAP/BAPI devel-
ment the correct changes within opment, Internet based order-pro-
the environment that make a pos- cessing systems, and Demand
itive user experience a reality. The Management integrations with
use of ABAP in the BW environ- third-party Demand Planning
ment is widespread and is impos- systems. Pat has spent the last
sible to cover in its entirety within three years as a Business Ware-
this article. However, it is most house consultant, specializing in
certainly possible to get a solid technical leadership roles and
grasp of the concepts required to solution design and development.
understand the what, when, and Pat's email address is
how of ABAP programming in BW. Arthur.Pesa@SAPtips.com. 

SAPtips © 2004 Klee Associates, Inc.


www.SAPtips.com SAPtipsJournal
Page 7

The information in our publications and on our Website is the copyrighted work of Klee Associates, Inc. and is owned by Klee Associates, Inc. NO WARRANTY:
This documentation is delivered as is, and Klee Associates, Inc. makes no warranty as to its accuracy or use. Any use of this documentation is at the risk of the user.
Although we make every good faith effort to ensure accuracy, this document may include technical or other inaccuracies or typographical errors. Klee Associates, Inc.
reserves the right to make changes without prior notice. NO AFFILIATION: Klee Associates, Inc. and this publication are not affiliated with or endorsed by SAP AG.
SAP AG software referenced on this site is furnished under license agreements between SAP AG and its customers and can be used only within the terms of such
agreements. SAP AG and mySAP are registered trademarks of SAP AG. All other product names used herein are trademarks or registered trademarks of their
respective owners.
February/March 2004 Volume II Issue 1
SAPtipsJournal

SAPtips © 2004 Klee Associates, Inc.

Das könnte Ihnen auch gefallen