Sunteți pe pagina 1din 10

20 Uses for ABAP on BW Projects

by Ned Falk, Senior Education Consultant, SAP America Data Extraction,Reporting,InoCubes,!pdate and "ranser
Rules,DataSources,#pen $ub Ser%ice,A&AP,Aut'ori(ations,E%ent ) Process C'ains
BW reduces the need for ABAP for most reporting tasks, but most BW projects could benefit from having an
experienced ABAPer available. This is particularly true for data preparation and preprocessing functions. The
author shos ho an ABAP programmer ould be useful in !" different areas.
#f you ask a $#% hy his or her company implemented BW, the anser might include a desire to do aay ith
custom ABAP reports. #t&s true that BW can eliminate the need to create ABAP reports. #n addition, BW&s ne
Transformation 'ibrary, hich rites ABAP code for you, further reduces dependency on ABAP, as do alternatives
such as ()'*+%AP, ,ava, and external -T' tools. But does BW totally eliminate the need for ABAP coding.
/o. +o, don&t send the ABAP programmers home so 0uickly1
ABAP programmers ho are familiar ith BW ill be assets to most projects. 2oever, their focus, ith a fe
exceptions, ill move from report creation to data preparation and preprocessing functions. Figure 1 3belo4
shos areas ithin the standard BW architecture here you might use ABAP5
+ix places during extraction, including creating custom 6ata+ources, enhancing 6ata+ources, and data
selection in #nfoPackages
+ix places during staging, including currency*units of measure conversions, transfer routines, and update
rules
7our places during reporting, including generating system8entered variables and the report*report
interface
9ou also have four other opportunities in BW to use ABAP5 %pen 2ub +ervice transformations, building
authori:ation values, process chains, and virtual #nfo$ubes ith services.
Figure 1 !" ays to enhance your BW system ith ABAP
That&s a total of !" ays you can use ABAP to enhance the operation and utility of your BW system. This article
introduces you to each of them.
Six Ways to Enhance Data Extraction with ABAP
1. Create a custo DataSource for an !nfoSet "uery with the generic extractor# When no standard
application8specific extractor is available for a given 6ata+ource, you might have to create your on
using the generic extractor 3transaction code ;+%!4. 'ike all extractors, the generic extractor uses a
function module called by the +ervice AP# hen BW re0uests the data to be loaded. This function module
is ritten in ABAP code.
Although you can use ;+%! to build 6ata+ources based simply on tables or vies here no custom
ABAP code is needed, more sophisticated uses of the generic extractor might involve custom ABAP
code. %ne example might be hen you use #nfo+et <uery to feed the generic 6ata+ource. This 0uery8
riting tool has been included in the Basis layer of all +AP products 3under one name or another4 for
many years. #t collects data in memory and is used as a =source> for user ad hoc 0ueries 3mostly in ;*?4.
#nstead of using the #nfo+et <uery to report against data in ;*?, the BW team uses the data collected by
the #nfo+et as a feed for a generic 6ata+ource. 9ou have many options for filling the #nfo+et. %ne option
is by means of ABAP code, in hich your code indirectly serves as the extractor program.
#f you have BW ?.x, you ould use this option only if you have existing #nfo+et data from ;*? that already
uses ABAP as the source. BW ?." offers a ne method, described belo, for using ABAP directly via
transaction code ;+%!.
2. Create a custo DataSource $irect%y using transaction co$e &S'2. As of ;elease ?."B, you can
use the generic extractor tool to create custom 6ata+ources, complete ith your on ABAP8coded
function module, but in a more direct ay than hen using the #nfo+et 0uery. With ?."B, ;+%! has an
option to base a 6ata+ource directly on a custom8ritten ABAP function module, as shon in Figure 2.
All you need is an extract structure and an ABAP program to fill it and you have yourself a 6ata+ource. #f
extraction is more complicated than just a vie or a table, this is the preferred ay to use your on ABAP
code as the extractor function module in BW ?.x.
3. Enhance a DataSource an$ associate$ extractor function o$u%e. +AP8delivered 6ata+ources don&t
necessarily contain all the information that your re0uirement demands. #n many cases, you must add
fields to the 6ata+ource&s extract structure and then fill them via a customer exit. +AP provides customer
exits for transactional data 3-(#T@+AP';+AP@""A4, master data 3-(#T@+AP';+AP@""!4, text
3-(#T@+AP';+AP@"""?4, and hierarchies 3-(#T@+AP';+AP@""AB4. #t&s up to you, hoever, to rite
the simple ABAP code needed to look up the fields added to the delivered extract structure.
4. Se%ect fi%es fro f%at(fi%e DataSources. When loading flat files, the BW #nfoPackage must kno the file
name and the location of the file. +ometimes a file that is on the serverCfor example, Current@)th@+ales
Cis reloaded ith the data you loaded last month by mistake. This mistake is difficult to catch, and BW
does not kno the file contains old data. People are fired over problems like this1
An ABAP program can help here. %n the -xternal 6ata screen 3Figure )4 in the #nfoPackage, you can
place a routine to dynamically determine the file name to load. $ombined ith naming conventions
agreed to by the legacy team, this routine makes it easy to catch this type of mistake. The ABAP routine
determines the file name based on the +AP8delivered variable for =current system month,> so that a file to
load in 6ecember is +A'-+@A!, and the folloing month 3,anuary4 it ould be +A'-+@"A. #f the #T
group does not get a file on the server ith this exact name, the load fails, forcing an investigation and
avoiding a serious mistake.
5. Deterine $ata se%ection in an !nfoPac*age. #n some cases, not all the data from a 6ata+ource is
needed in BW. 7or example, it might be old and unchanged from the previous load. Also, the BW
implementation might not be designed to support the hole corporation, and it is necessary to extract
only limited organi:ation8specific data to BW.
9ou can select specific data by clicking on the Se%ection tab of the #nfoPackage. This selection can be
dynamic 3change ith each #nfoPackage load4 or fixed 3only company code A""" for year ADDD4. #f you
ant it to be dynamicCfor example, to extract only the current fiscal periodCthen to options exist5
variables or an ABAP routine to fill in the value of the selected data at extraction time. 9ou could use
+AP8supplied variables for determining the current month, but hen determining other characteristic
values ith more complex logic, you ould need your custom ABAP code.
6. Deterine autoatic $e%etion of sii%ar %oa$s. #t might be necessary to load 7-B@!"""@7#@6ATA on
7ebruary AE, !""", and again on 7ebruary !F, !""". #f this is done ithout forethought, you risk double8
counting data from 7ebruary A to AE. 9ou must make sure you delete the load on the AEth from the data
target for the load on the !Fth to avoid double8counting. BW contains simple logic that can be activated to
determine if a prior load ith similar selections should be deleted. The settings for the checking logic are
located under the Data +argets tab. The simple checks, such as Are the !nfoPac*age se%ections the
sae, and Was the origina% info -ac*age %oa$e$ in the sae wee*, can be set ith delivered
checkboxes. 7or more complex logic to determine overlap or duplicate loads, you can use ABAP code. #f
a =duplicate> is detected, then the system automatically deletes these prior load re0uests to avoid double8
counting the records.
Figure 2 $reate a custom 6ata+ource directly from ;+"!
Figure ) Place an ABAP routine to identify the file name to be loaded
Six Ways to Enhance Data Staging with ABAP
6ata staging is the manipulating and cleansing of data after it arrives in BW. 6ata staging includes the transfer and
update rules. 9ou could substitute =ABAP> here for the ord =rules,> as in transfer ABAP and update ABAP. These
data manipulations are for the most part ritten for you by +AP BW. $omplex look8ups or derivations are not
ritten for you. #n these cases, ho are you going to call. 9ou guessed it5 an ABAP programmer1 The ABAP code
needed in data manipulation is normally simple.
Figure . Transfer procedures 3all types4
1. Write co-%ex %ogic for transfer -roce$ures. The transfer procedures clean the incoming transfer
structure fields and rite the clean data to the communication structure 3knon less technically as the
#nfo+ource4. These procedures can be accessed from either the 6ata+ource or the #nfo+ource overvie
trees, as the transfer rules are the =glue> connecting the dirty 6ata+ource to the clean #nfo+ource. The
procedures can be as simple as a field8for8field move or can involve complex logic. But hat if field
lengths or types are different. What if you needed a complex look8up in to or three tables to derive the
proper value. 7or this and more complex logic, you need to rite ABAP code or use BW ?."&s
Transformation 'ibrary to create the code for you. 3+ee Figure ..4
2. +ransfer routines. Transfer routines are similar to transfer procedures, as both are part of the transfer
rules that perform cleansing functions in the data flo. The main difference is ho they are created and
hen they are applied. Transfer procedures are maintained on the +ransfer &u%es section of the
#nfo+ource, hile transfer routines are maintained on the #nfo%bject&s /enera% tab. #f a transformation
should take place for every occurrence of an #nfo%bject, regardless of hat #nfo+ource is being loaded,
the transformation logic 3ritten using ABAP4 can be maintained directly on the #nfo%bject. This means
less ork, since rules need be maintained only once and take effect during all cleansing transformations
associated ith the #nfo%bject. #f transfer procedures and routines are both applied, the logic 3ABAP4 on
the #nfo%bject 3transfer routines4 is executed before the logic 3ABAP4 on the transfer rules.
3. U-$ate ru%es in genera%. Gpdate rules allo the manipulation of the clean data for the purposes of
summari:ing or customi:ing data for a specific reporting purpose. The targets of the manipulated
#nfo+ource data include %6+ objects, #nfo$ubes, and 3as of BW ?."4 master data 3text and attributes4.
Gpdate rules provide automatic determination of date8based mapping 3e.g., "A*"A*!""? H W--I
"A*!""?4 and can even automatically generate the code for simple look8ups of master data attributes.
2oever, if your manipulation re0uirements fall outside of these more basic tasks, you can use the
Transformation 'ibrary or directly rite ABAP for complex logic.
4. &eturn a ta0%e 1ersus a recor$. #n standard updating logic, one record in the #nfo+ource is loaded as
one record in the #nfo$ube. #n some cases, it is necessary to create a table 3more than one record4 to be
loaded to the #nfo$ube for each incoming record in the #nfo+ource. Business examples of this might be
legacy sales order data missing the detail for a specific sales rep. The business rule might be to assign
one8fifth of the sale to each of five sales reps. The business rule 3ritten in ABAP4 ould then split the
single sales order into five smaller records, each ith one8fifth of the amount.
5. Con1ert currency or units of easure. #n most cases, currency conversion logic is better handled
through the use of translation keys in the bottom section of the Gpdate ;ules screen. 2oever,
conversions from inches to meters or liters to gallons are not as conveniently performed. #n many cases,
this logic re0uires ABAP code. By selecting the Unit Ca%cu%ation in the &outine checkbox on the
Gpdate ;ule5 6etail screen 3Figure 24, you can code a =unit routine> ith ABAP to handle complex
manipulations of currency. 7or example5 ='ook at the date and the from*to currency, and then convert
based on a J"*?" eighted average for the high and lo rates.> +imilarly, you can convert gallons to
liters.
6. Create custo start routines for transfer an$ u-$ate ru%es. Transfer or update programs are
generated automatically hen you activate a transfer or update rule. +imple code for tasks like =move
corresponding fields> or =assign fixed values to #nfo%bjects> combines ith your custom code. #n this
combined program, individual records =flo> from memory8resident structures to the data targets
3#nfo$ubes, %6+s, and #nfo%bjects4. +ince the code is executed one record at a time, it can be inefficient
to process some tasks, especially ones that re0uire a table look8up on the database.
9ou can alleviate this potential bottleneck by creating a =start routine> 3see Figure 34, hich is custom
ABAP code that executes at the start of the transfer or update rule program. This custom code can, for
example, fill global variables or, more importantly, build a memory8resident version of the look8up tables
re0uired by the rest of the program. #f a rule is processing many records, and the building of the involved
look8up tables is not a long process, then you can reali:e dramatic improvements in performance.
Figure 2 Gpdate rules
Figure 3 +tart routine
Four Ways to Enhance BW &e-orting with ABAP
1. /enerate syste(entere$ 1aria0%es. )any reports can use system8entered variables, in hich the user
is not prompted for the value. The system determines the value in the background. These variables are
either delivered by +AP 3current month, for example4 or created on a custom basis. 7or the latter, a user
exit is available for ABAP code. The ABAP code is run at 0uery execution time and is used to determine
the variable values for this one 0uery run by a specific user at a specific time.
9our ABAP code, entered under the user exit shon in Figure 4, can perform look8ups or other complex
logic. The logic determines the values ithout asking the user to input them.
2. Po-u%ate 1irtua% *ey figures an$ characteristics. What happens if the data needed by a 0uery is not
derivable using formula functionality or must be looked up at execution. This might be because the data
or a reference needed by a calculation is unavailable in the BW target. The system provides a user exit to
process the data retrieved from the database on the ay to the user. An #nfo$ube that needs these run8
time created characteristics or key figures must contain a special =virtual> key figure or characteristic that
has no data in it, but is added to reports in the normal manner. The user exit&s job is to populate these
otherise blank #nfo%bjects hen the report is executed using custom ABAP code.
3. 5o$ify We0(0ase$ ta0%e an$ na1igation 0%oc* interfaces. 9ou probably kno ho BW orks in a
Web environment5 A Web template provides placeholders for tables and charts that are populated ith
data at the time the page is re0uested. The template is a simple page to create, hile the page that is
actually sent back by BW contains ,ava+cript and 2T)' surrounding the real table, hich by necessity is
complex. #t is good that you do not have to create this output yourself. #t is the responsibility of the +AP
Web Application +erver or the #K+ 3#nternet Kraphics +erver4.
But if someone designed the template one ay, someone else ill ant the output to look or behave
differently. Who are you going to call. #f you said an ABAPer, you ould be rong1 This time, you need
an ABAP %% 3object8oriented4 programmer. ABAP %% uses object8oriented techni0ues similar to those
of other modern languages such as ,ava and Lisual BA+#$. Working ith the ABAP %% programmer,
you can change the output generated for the table or the navigation block 3the central place here you
click on the report to drill don on a specific characteristic4. 9ou can add your on icon, for example, to
run a customer8specific process ith the data in a cell, or just have a mouse button do something
different for your Web page. #f you don&t have an ABAP %% programmer handy, a regular ABAPer
provided ith a hite paper shoing an example of hat you ant to do ill serve just fine.
4. &e-ort6re-ort interface. The report*report interface allos users to navigate from one BW 0uery 3on
#nfo$ube (, for example4 to another 0uery on #nfo$ube 9. #t also allos you to jump to ;*? or $;).
Although you ould probably not need ne ABAP code, you can use the report*report interface to run
any ABAP report on any my+AP system 3;*?, $;), BW, AP%, +-)4.
Figure 4 Gser exit8filled variables
Four A$$itiona% Ways to Enhance 7our BW Syste with ABAP
1. Perfor '-en 8u0 transforations. BW supplies the %pen 2ub +ervice to meet re0uirements for
getting information to third8party applications from BW. The data types, field names, and field lengths are
often not the same in BW as they are in the external application, or additional value manipulation is
necessary. 7or this, an ABAPer needs to code the custom logic for the manipulation in the ne
infrastructure called a BA6# 3Business Add8in4. BA6#s, based on ABAP %%, are the ne ay to
accomplish custom enhancements in a controlled ay. The old ay as called a =user exit.>
2. Bui%$ authori9ation 1a%ues. ABAP implemented through variables filled by a user exit can be used to
dynamically build authori:ation values hen the user logs in. This is sometimes an easy ay to maintain
many alloed values for a cost center range for a specific user.
3. Process chains. The process chain is a scheduling tool for various tasks in the data arehouse. #n
some cases, you can use ABAP code to schedule a job on the source system or run a small ABAP
program on ;*? to raise an event on BW. This event could then be used to start a process chain. A
business case for this could involve a transaction or ABAP code run on ;*? to indicate that +AP 7# is
done ith the month8close process. This ABAP program calls BW and raises an =event.> When this event
is raised, the process chain called =7# )onthly Process> starts.
4. :irtua% !nfoCu0e with ser1ices. Lirtual #nfo$ubes allo for the direct read of source data in real time.
9ou do not have to load the data into an #nfo$ubeM it is loaded into memory directly from the source hen
the report is run using standard BW 0uery and reporting tools. The three types of virtual #nfo$ubes are
+AP remote #nfo$ubes, general remote #nfo$ubes, and virtual #nfo$ubes ith services. +AP remote
#nfo$ubes use ;*? or $;) 6ata+ources 3and their associated extractors4 to read the data in real time,
hile general remote #nfo$ubes access data that is normally purchased 3e.g., /ielson4. Lirtual #nfo$ubes
ith services are used if the source is a custom table or group of tables. #n this case, custom ABAP
function modules 3services4 can be ritten to properly present the data from these tables to the BW 0uery
tools, making your table look like a BW #nfo$ube. This provides real8time data, not replicated data, from
your application to the user.

S-ar putea să vă placă și