Vous êtes sur la page 1sur 14

ABAP Programming in BW

ABAP Programming in BW
ACS/Ver 1.0 Page 1 of 8
ABAP Programming in BW
Table of Contents
Purpose..........................................................................................................3
Objective........................................................................................................3
Scope............................................................................................................3
Common Impementation scenarios of A!AP Programming in !"..........................#
$sing %ie& S'mbos in (outines......................................................................10
)ifferences bet*een +ransfer/$p&ate (ues an& +ransformations .......................10
,ist of usefu SAP Stan&ar& Programs/%unction -o&ues/Casses..........................11
Optimi.ation consi&erations............................................................................1#
+ips for co&e c/anges.....................................................................................1#
Variants........................................................................................................1#
ACS/Ver 1.0 Page 0 of 8
ABAP Programming in BW
Purpose
The purpose of this document is to outline and define concepts and strategies that
constitute best practices regarding the use of ABAP programming in BW.
It is strongly suggested that all staff (both senior and new hires) follow this
document closely.
Objective
Obecti!e of this document is to de!elop programming process guidelines and
de!elopment standards considering the possibilities e"ist for using ABAP to
customi#e the BW en!ironment to transform the data as re$uirements dictate% as
well as pro!ide additional processing during e"traction and updates.
Scope
ABAP Programming Scope in BW and R/3 etractors
Tec!nical Area "escription
B# $ser #it Allows the creation and population of !ariables and
calculations for &ey figures and !ariables on a runtime basis.
This user e"it is called each time B'" is e"ecuted.
R/3 $ser #it This user e"it is found in ()* under +,O- and contains
additional programming that is needed to fill field additions to
e"tract structures. We can also create additional business
logic against data prior to its transfer to BW.
BW Transformation
Routines
Transformation routines are part of transformation rules
which are in!o&ed as data is transferred from ()* to BW
-ata targets% or from within BW from one infopro!ider to
another. Transformation rules are each infoobect specific.
BW Start Routines .tart routines in BW Transformations are used to manage
whole subsets of source data before Transformation rules are
triggered.
BW #nd Routines 'nd routines in BW Transformations are used to manage whole
subsets of resulting data from .tart routine and
Transformation (ules.
BW #pert Routines '"pert (outine is a new feature in BI /.0 which enables user
can define e"actly how the Transformation wor&s. '"pert
routines are used only in special scenarios. When an e"pert
routine is created then all transformations rules along with
start and end routines will get deleted. .ome times e"ert
routines impro!es the performance of data load e!en further.
BW "TP Routines -TP (outines are used to do some filtering and calculations on
the selection screen fields depending on the business
re$uirement.
ACS/Ver 1.0 Page 3 of 8
ABAP Programming in BW
BW %nfopac&age
Routines
Infopac&age le!el routines are used to in scenarios li&e if
source system need to be selected dynamically% selecting file
name dynamilcally and filtering data coming from source flat
file.
Common %mplementation scenarios of ABAP Programming in BW
1or BI /.0% in data staging% there are many aspects that we can write abap
code to deal with data.
'( %nfoPac&age Routine
The infopac&age routine gi!en below is an e"ample to create dynamic file name.
ACS/Ver 1.0 Page # of 8
ABAP Programming in BW
)( Start Routines
.tart routines are processed2
333After the data in written into the P.A
333Before the transformation is processed
Actually% we write ABAP code here is for data cleansing or data consolidation.
3( Transformation Rules
It is processed in the transformation and actually this routine is written for some
particular fields.
In the transformation% select the particular field and right clic& the rule detail% in the
rule type% choose 4(outine4.
ACS/Ver 1.0 Page 1 of 8
ABAP Programming in BW
*( #nd Routine
'nd (outine is processed after transformation% actually for data cleansing.
+( #pert Routine
ACS/Ver 1.0 Page 2 of 8
ABAP Programming in BW
This type of routine is only intended for use in special cases. 5ou can use the e"pert routine
if there are not sufficient functions to perform a transformation. The e"pert routine
should be used as an interim solution until the necessary functions are a!ailable in the
standard routine.
While writing routines% in order to dramatically impro!e performance% the following steps
should be ta&en2
6se Internal Tables of ,aster -ata (instead of direct read of physical P3Tables)
,a&e minimum .elect and (ead statements.
7ecessary .elect and (ead statements should be e"ecuted efficiently by using
(.ort 8 Binary .earch).
'"ample for the '"pert (outine
9:lobal .ection
T5P'.2
B':I7 O1 +6.TO,'(;-ATA%
+6.TO,'( <I=' )BI0)P+6.TO,'(3+6.TO,'(%
+6.T;+<A. <I=' )BI0)P+6.TO,'(3+6.T;+<A.%
.A<'.;O11 <I=' )BI0)0+6.TO,'(3.A<'.;O11%
'7- O1 +6.TO,'(;-ATA.T5P'.2
B':I7 O1 >+6.T.A<'.;-ATA%
>+6.T.A<'. <I=' )BI+)P>+6.T.A<'3>+6.T.A<'%
-I.T(;+?A7 <I=' )BI+)P>+6.T.A<'3-I.T(;+?A7%
.A<'.;:(P <I=' )BI+)P>+6.T.A<'3.A<'.;:(P%
'7- O1 +6.TO,'(;-ATA.
-ATA2
<I7';+6.TO,'(;-ATA T5P' +6.TO,'(;-ATA%
ACS/Ver 1.0 Page 3 of 8
ABAP Programming in BW
<I7';>+6.T.A<';-ATA T5P' >+6.T.A<';-ATA%
ITAB;+6.TO,'(;-ATA <I=' .O(T'- TAB<' O1 <I7';+6.TO,'(;-ATA%
ITAB;>+6.T.A<';-ATA <I=' .O(T'- TAB<' O1 <I7';>+6.T.A<';-ATA.
9Begin of '"pert (outine2
9,a&e the proper .elect .tatements before(@) looping on the -ataPac&age
9fill 0+6.TO,'( master data into Internal Table2
.'<'+T -I.TI7+T +6.TO,'( +6.T;+<A. .A<'.;O11
1(O, )BI0)P+6.TO,'(
I7TO +O(('.PO7-I7: 1I'<-. O1 TAB<' ITAB;+6.TO,'(;-ATA
W?'(' OBAB'(. 'C 4A4.
9fill >+6.T.A<' master data into Internal Table2
.'<'+T -I.TI7+T >+6.T.A<' -I.T(;+?A7 .A<'.;:(P
1(O, )BI0)P>+6.T.A<'
I7TO +O(('.PO7-I7: 1I'<-. O1 TAB<' ITAB;>+6.T.A<';-ATA
W?'(' OBAB'(. 'C 4A4.
9<oop on -ata Pac&age to ma&e proper assignments2
-ATA2
<I7';-ATA;PA+=A:' <I=' <I7' O1 -ATA;PA+=A:'.
<OOP AT -ATA;PA+=A:' I7TO <I7';-ATA;PA+=A:'.
9ma&e direct assignments for (esult 1ields2
ACS/Ver 1.0 Page 8 of 8
ABAP Programming in BW
('.6<T;1I'<-.3,AT'(IA< D <I7';-ATA;PA+=A:'3,AT'(IA<.
('.6<T;1I'<-.3+6.TO,'( D <I7';-ATA;PA+=A:'3+6.TO,'(.
('.6<T;1I'<-.3>+6.T.A<' D <I7';-ATA;PA+=A:'3>+6.T.A<'.
('.6<T;1I'<-.3+A<,O7T? D <I7';-ATA;PA+=A:'3+A<,O7T?.
9(ead the proper +6.TO,'( data from Internal Table using Binary .earch.
+<'A( <I7';+6.TO,'(;-ATA.
('A- ITAB;+6.TO,'(;-ATA WIT? ='5
+6.TO,'( D <I7';-ATA;PA+=A:'3+6.TO,'(
I7TO <I7';+6.TO,'(;-ATA BI7A(5 .'A(+?.
9Assign read !alues to (esult 1ields2
('.6<T;1I'<-.3+6.T;+<A. D <I7';-ATA;PA+=A:'3+6.T;+<A..
('.6<T;1I'<-.3.A<'.;O11 D <I7';-ATA;PA+=A:'3.A<'.;O11.
9(ead the proper >+6.T.A<' data from Internal Table using Binary .earch.
+<'A( <I7';>+6.T.A<';-ATA.
('A- ITAB;>+6.T.A<';-ATA WIT? ='5
>+6.T.A<' D <I7';-ATA;PA+=A:'3>+6.T.A<'
I7TO <I7';>+6.T.A<';-ATA BI7A(5 .'A(+?.
9Assign read !alues to (esult 1ields2
('.6<T;1I'<-.3-I.T(;+?A7 D <I7';-ATA;PA+=A:'3-I.T(;+?A7.
('.6<T;1I'<-.3.A<'.;:(P D <I7';-ATA;PA+=A:'3.A<'.;:(P.
ACS/Ver 1.0 Page 4 of 8
ABAP Programming in BW
APP'7- ('.6<T;1I'<-. TO ('.6<T;PA+=A:'.
'7-<OOP.
$sing ,ield S-mbols in Routines
1ield symbols are placeholders or symbolic names for other fields. They do not
physically reser!e space for a field% but point to its contents. A field symbol cam
point to any data obect. The data obect to which a field symbol points is assigned
to it after it has been declared in the program.
Whene!er you address a field symbol in a program% you are addressing the field that
is assigned to the field symbol. After successful assignment% there is no difference
in ABAP whether you reference the field symbol or the field itself. 5ou must assign
a field to a field symbol before you can address it in a program.
'"ample of using 1ield .ymbols in (outines.
"ifferences bet.een Transfer/$pdate Rules and Transformations
In BI /.0 en!ironment% transformation (formerly called 6pdate)Transfer rules)
re$uires obect oriented ABAP and here are some difference worth noting down
between Obect oriented ABAP and ABAP which would help you in wor&ing with BI
/.0.

BW *.E BI /.0
Internal Table -ATA2 B':I7 O1 I7T;'B'<7
O++6(. 0%
OI;'B'<7 <I='
)BI0)POI;'B'<73OI;'B'<7%
)BI+)>,'FP-:(P <I='
)BI0)POI;'B'<73)BI+)>,'F
P-:(P%
)BI+)>,POB'(7O <I='
)BI0)POI;'B'<73)BI+)>,PO
B'(7O%
)BI+)>,P6(.TAT <I='
)BI0)POI;'B'<73)BI+)>,P6
(.TAT%
)BI+)>,PO(<.O7 <I='
)BI0)POI;'B'<73)BI+)>,PO
(<.O7%
)BI+)>,BA<-;PO <I='
)BI0)POI;'B'<73)BI+)>,BA
It4s G step process in BI /.0. H
st
step
declare the structure and in G
nd
step
declare Internal table referring to the
abo!e structure
T5P'.2 B':I7 O1 I7T;'B'<7;.T(6%
OI;'B'<7 T5P'
)BI0)POI;'B'<73OI;'B'<7%
)BI+)>,'FP-:(P T5P'
)BI0)POI;'B'<73)BI+)>,'FP-:(P%
)BI+)>,POB'(7O T5P'
)BI0)POI;'B'<73)BI+)>,POB'(7O%
)BI+)>,P6(.TAT T5P'
)BI0)POI;'B'<73)BI+)>,P6(.TAT%
)BI+)>,PO(<.O7 T5P'
)BI0)POI;'B'<73)BI+)>,PO(<.O7%
)BI+)>,BA<-;PO T5P'
)BI0)POI;'B'<73)BI+)>,BA<-;PO%
'7- O1 I7T;'B'<7;.T(6.
ACS/Ver 1.0 Page 10 of 8
ABAP Programming in BW
<-;PO%
'7- O1 I7T;'B'<7.
-ATA2 I7T;'B'<7 T5P' TAB<' O1
I7T;'B'<7;.T(6.
(eading data from
Internal Table
('A- TAB<' I7T;'B'<7
I7TO WA;PO WIT? ='5
OI;'B'<7 D
-ATA;PA+=A:'3OI;'B'<7
BI7A(5 .'A(+?.
I1 .53.6B(+ D 0.
-ATA;PA+=A:'3)BI+)>,BA<
-;PO D
WA;PO3)BI+)>,BA<-;PO.
-ATA;PA+=A:'3)BI+)>,'FP
-:(P D
WA;PO3)BI+)>,'FP-:(P.
-ATA;PA+=A:'3)BI+)>,PO(
<.O7 D
WA;PO3)BI+)>,PO(<.O7.
-ATA;PA+=A:'3)BI+)>,P6(
.TAT D
WA;PO3)BI+)>,P6(.TAT.
H
st
define a Wor& area and read from
there.
WA;PO <I=' <I7' O1 I7T;'B'<7 I
Wor& Area
('A- TAB<' I7T;'B'<7 I7TO WA;PO
WIT? ='5
OI;'B'<7 D WA;-ATA;PA+=A:'3
OI;'B'<7 BI7A(5 .'A(+?.
I1 .53.6B(+ D 0.
WA;-ATA;PA+=A:'3)BI+)>,BA<-;PO
D WA;PO3)BI+)>,BA<-;PO.
WA;-ATA;PA+=A:'3)BI+)>,'FP-:(P
D WA;PO3)BI+)>,'FP-:(P.
WA;-ATA;PA+=A:'3)BI+)>,PO(<.O
7 D WA;PO3)BI+)>,PO(<.O7.
WA;-ATA;PA+=A:'3)BI+)>,P6(.TA
T D WA;PO3)BI+)>,P6(.TAT.
-ata Pac&age

-ata2 -ATA;PA+=A:' type table of
;ty;s;.+;H%
WA;-ATA;PA+=A:' <I=' <I7' O1
-ATA;PA+=A:'.
<oop .tatement <OOP AT -ATA;PA+=A:'. <OOP AT -ATA;PA+=A:' I7TO
WA;-ATA;PA+=A:'
/ist of useful SAP Standard Programs/,unction 0odules/Classes
Program name Description
RSCDS_NULLELIM Delete fact table rows where all Key Figure values are zero. See
Note 619826.
RSDG_CUBE_ACTIVATE Activatio of !fo"ubes
RSDG_CUBE_COP #a$e !fo"ube "o%ies
RSDG_CUBE_DELETE Delete !fo"ubes
RSDG_DODS_REPAIR Activatio of all &DS &b'ects with Navigatio Attributes
ACS/Ver 1.0 Page 11 of 8
ABAP Programming in BW
RSDG_ODSO_ACTIVATE Activatio of all &DS &b'ects
RSDG_IOB!_ACTIVATE Activatio of all !fo&b'ects
RSDG_IOB!_DELETE Deletio of !fo&b'ects
RSDG_IOB!_REORG (e%air !fo&b'ects
RSDG_IOB!_REORG_TE"TS (eorgaizatio of )e*ts for !fo&b'ects
RSDG_MPRO_ACTIVATE Activatig #ulti%rovi+ers
RSDG_MPRO_COP #a$e #ulti%rovi+er "o%ies
RSDG_MPRO_DELETE Deletig #ulti%rovi+ers
RS_COMSTRU_ACTIVATE_ALL Activate all iactive "o,,uicatio Structures
RS_TRANSTRU_ACTIVATE_ALL Activate )rasfer Structure
RSAU_UPDR_REACTIVATE_ALL Activate -%+ate (ules
RR#I_#IERARC#_ACTIVATE Activate .ierarchies
SAP_AGGREGATES_ACTIVATE_$I
LL
Activatig a+ Fillig the Aggregates of a !fo"ube
SAP_AGGREGATES_DEACTIVATE Deactivatig the Aggregates of a !fo"ube
RS_PERS_ACTIVATE Activatig /ersoalizatio i 0e*1!active are highlighte+2
RSSM_SET_REPAIR_$ULL_$LAG "overt Full (e3uests to (e%air Full (e3uests
SAP_IN$OCUBE_DESIGNS /rit a 4ist of "ubes i )he Syste, a+ )heir 4ayouts
SAP_ANAL%E_ALL_IN$OCUBES "reate D0 Statistics for all !fo"ubes
SAP_CREATE_E_$ACTTABLES "reate #issig 56Fact )ables for !fo"ubes a+ Aggregates
SAP_DROP_EMPT_$PARTITIONS 4ocate7(e,ove -use+ or 5,%ty %artitios of F6Fact )able
SAP_DROP_TMPTABLES (e,ove )e,%orary Database &b'ects
SAP_RSADMIN_MAINTAIN A++8 chage8 +elete (SAD#!N table etries
CUBE_SAMPLE_CREATE A fast way to %ut so,e 9sa,%le9 recor+s i a !fo"ube. No ee+
to use Flat files8 'ust eter the value i a A4:6;ri+ or let fill the
"ube with ra+o, value.
SAP_CONVERT_NORMAL_TRANS "overt 0asic "ube to )rasactioal "ube a+ the o%%osite way
arou+.
$&nction Mo'&(e Description )$&nction Gro&p RRM"*
RRM"_+OR,BOO,_DELETE Delete 0< <or$boo$s %er,aetly fro, (oles = Favorites
RRM"_+OR,BOO,_LIST_GET ;et list of all <or$boo$s
ACS/Ver 1.0 Page 10 of 8
ABAP Programming in BW
RRM"_+OR,BOO,_-UERIES_GET ;et list of 3ueries i a wor$boo$
RRM"_-UER_+#ERE_USED_GET 4ists where a 3uery has bee use+
RRM"_!UMP_TARGET_GET ;et list of all >u,% )argets
RRM"_!UMP_TARGET_DELETE Delete >u,% )argets
MONI_TIME_CONVERT -se+ for )i,e "oversios.
CONVERT_TO_LOCAL_CURRENC "overt Foreig "urrecy to 4ocal "urrecy.
CONVERT_TO_$OREIGN_CURRENC "overt 4ocal "urrecy to Foreig "urrecy.
TERM_TRANSLATE_TO_UPPER_CASE -se+ to covert all te*ts to -//5("AS5
UNIT_CONVERSION_SIMPLE -se+ to covert ay uit to aother uit. 1(ef. table ? )@@62
T%_GLOBAL_TO_LOCAL -se+ to covert ti,esta,% to local ti,e
$ISCPER_$ROM_CALMONT#_CALC "overt @"A4#&N). or @"A4DAA to Fiacial Aear or /erio+
RSA"_BI+_GET_DATA_SIMPLE ;eeric 5*tractio via Fuctio #o+ule
RSAU_READ_MASTER_DATA -se+ i Data )rasfor,atios to rea+ ,aster
+ata !fo&b'ects
RSDRI_IN$OPROV_READ
RSDRI_IN$OPROV_READ_DEMO
RSDRI_IN$OPROV_READ_R$C
-se+ to rea+ !focube or &DS +ata through (F"
DATE_COMPUTE_DA
DATE_TO_DA
(eturs a u,ber what +ay of the wee$ the +ate falls o.
DATE_GET_+EE, <ill retur a wee$ that the +ay is i.
RP_CALC_DATE_IN_INTERVAL A++7Subtract Aears7#oths7Days fro, a Date.
RP_LAST_DA_O$_T#E_MONT#S
SLS_MISC_GET_LAST_DA_O$_MONT
#
Deter,ie 4ast Day of the #oth.
RSARC#_DATE_CONVERT -se+ for Date "oversios. <e ca use i !fo /ac$age
routies.
RSPC_PROCESS_$INIS# )o trigger a evet i %rocess chai
DATE_CONVERT_TO_$ACTORDATE (eturs factory cale+ar +ate for a +ate
CONVERSION_E"IT_PDATE_OUTPUT "oversio 5*it for Do,ai ;0DA)? AAAA##DD 6B
DD7##7AAAA
CONVERSION_E"IT_ALP#A_INPUT "oversio e*it A4/.A8 e*teral6Biteral
CONVERSION_E"IT_ALP#A_OUTPUT "oversio e*it A4/.A8 iteral6Be*teral
RSPC_PROCESS_$INIS# Fiish a %rocess 1of a %rocess chai2
ACS/Ver 1.0 Page 13 of 8
ABAP Programming in BW
RSAOS_METADATA_UPLOAD -%loa+ of ,eta +ata fro, (7C
RSDMD_DEL_MASTER_DATA Deletio of ,aster +ata
RSPC_C#AIN_ACTIVATE_REMOTE )o activate a %rocess chai after tras%ort

C(ass CL_RSTRAN_STAT Description
D545)5D:5(S!&NDF(&#DD0
1Static #etho+2
For +eletig a trasfor,atios rule versio fro,
+atabase8 hel%ful if the trasfor,atio ,eta+ata are corru%te+.
Optimi1ation considerations
6se .'<'+T 9 with care. -o not use .'<'+T 9 when populating internal tables if
7OT all columns are re$uiredJ only select the necessary columns.
To reduce database access by repeated selections% itKs better to scan a table once
into the internal table and then read the internal table using statement
('A- TAB<' L BI7A(5 .'A(+?. But be careful and consider resource issues when
selecting into an internal table M balance between optimi#ation and memory
resources
A!oid ,OB'3+O(('.PO7-I7: statements. Instead use ,OB' statement and
mo!e fields indi!idually.
.tructure of internal table should match the order the fields are returned from the
select statement when selecting into an internal table thereby a!oiding usage of the
statement Ninto corresponding fieldsK.
A!oid nested selects if possible.
Be careful using N+?'+=K statements% consider to incorporate the selection criteria
into the select statement.
Tips for code c!anges
(emo!e obsolete commented out code as this will aid in program readability and
maintainability.
-ocument any change in program code with details li&e reason of change% date of
change% person responsible and also mar& the changed bloc& with begin and end of
bloc& tags.
2ariants
The -e!eloper is responsible for ensuring test !ariants are not transported to the
production instance.
ACS/Ver 1.0 Page 1# of 8

Vous aimerez peut-être aussi