Applies to:
This article is applicable to all SAP BI Consultants who are novice in ABAP Skills.
For more information, visit the Business Intelligence homepage.
Summary
Routines in SAP BI are essential part as they provide a level of customization in the development. This
document provides a basic understanding on how to write these routines. We have two approaches for this,
Simple ABAP and OOPS ABAP. This document covers both the methods.
After reading this document reader should be able to design and develop ABAP Code at different levels of
SAP BI. This document will enable reader to gain basic knowledge required to develop ABAP code in BI.
Author Bio
Sharayu Kumatkar is a BI & ABAP Certified Associate with four years of experience as a
Senior SAP Technical consultant with L&T Infotech.
Table of Contents
Different Routines Available in SAP BI ............................................................................................................... 3
Info Package Routine ...................................................................................................................................... 3
Start Routine ................................................................................................................................................... 3
End Routine .................................................................................................................................................... 3
Important Note ............................................................................................................................................................. 4
Expert Routine ................................................................................................................................................ 5
Characteristic Routine ..................................................................................................................................... 6
Basic Coding Statements Required .................................................................................................................... 7
SELECT .......................................................................................................................................................... 7
LOOP .............................................................................................................................................................. 7
FIELD-SYMBOLS ........................................................................................................................................... 8
READ .............................................................................................................................................................. 8
SORT .............................................................................................................................................................. 8
Customer Exit Variable (BEx) ............................................................................................................................. 9
I_STEP = 0 ...................................................................................................................................................... 9
I_STEP = 1 ...................................................................................................................................................... 9
I_STEP = 2 ...................................................................................................................................................... 9
I_STEP = 3 ...................................................................................................................................................... 9
Virtual Characteristic / Key Figure .................................................................................................................... 10
Tips & Tricks ..................................................................................................................................................... 10
Debugging ..................................................................................................................................................... 10
Appendix A: Sample Code - Splitting 60+ char string into multiple IO ............................................................. 12
Appendix B: Sample code - Remove Special Characters ................................................................................ 13
Appendix C: Sample Code - OOPS Start and Characteristic Routine ............................................................. 14
Related Content ................................................................................................................................................ 18
Disclaimer and Liability Notice .......................................................................................................................... 19
You need to create a routine by clicking on the Routine button. Give a name to routine. Write a code inside
this routine to derive file name and assign it to variable p_filename.
Start Routine
Start Routine is available with Transformation. It is triggered before Transformation. Generally Start routines
are used for Filtering records or fetching global data to be used in Characteristic routine.
Click on Start Routine button to create Start Routine. SOURCE_PACKAGE contains contents of source data.
SOURCE_PACKAGE has same structure as that of Source of the Transformation.
End Routine
End Routine is available with Transformation. It is triggered after Transformation. Generally End user is used
for updating data based on existing data.
Click on End Routine button to create End Routine. RESULT_PACKAGE contains process data i.e.
processed via start routine and transformation. RESULT_PACKAGE has same structure as that of target
Object.
Important Note
For support pack 16 and above you get one more button besides End Routine (once end routine is created).
This button is to update behaviour of fields in End Routines. You get two options once you select this button.
One needs to make selection of proper option as it is mandatory.
The default setting for the pushbutton is that only the fields with active rules are updated in the
transformation. With this selection, fields populated in End routine wont be updated in the data target if no
active rule exists for them in Transformation.
Alternatively, you can define that all the fields should always be updated by selecting 2nd radio button. As a
result, fields filled in the end routine are not lost if there is no other active rule.
Note: Data fields with the 'No transformation' rule type in the transformation are overwritten if the transformation contains
an end routine. This problem does not occur for key figures if the aggregation summation was set in the
transformation. This problem always occurs for characteristics. If your system is below SP16 then you can
implement note 1024816 to get above facility.
Expert Routine
To create an Expert routine go to Edit menu and select Expert Routine. Expert Routine will trigger without
any transformation Rule. All existing Rules will be deleted once you develop Expert Routine. This is used
generally for customizing rules.
SOURCE_PACKAGE has same structure as that of Source of the Transformation. RESULT_PACKAGE has
same structure as that of target Object. You can manipulate values from SOURCE_PACKAGE and append
them in RESULT_PACKAGE.
Note: If the target of the transformation is a Data Store Object, key figures are updated by default with the aggregation
behaviour Overwrite (MOVE).
Characteristic Routine
Characteristic Routine is inside Transformation. This routine will be triggered inside the Transformation
based on the characteristic or key figure. If rule is for Characteristic, then Characteristic transformation
routine will trigger. If rule is for key figure, then key figure transformation routine will trigger.
In Rule details of transformation select Routine to create a Characteristic Routine. Here you can do
calculation of InfoObject value and assign value to variable Result, which in turn will get assigned to
InfoObject. Characteristic routine is executed after Start routine and before End Routine. All global objects
declared in Start Routine are available in Characteristic Routine.
LOOP
Syntax : LOOP AT <ITAB> [INTO <WORK AREA>] [WHERE <COND>].
...
ENDLOOP.
OR
LOOP AT <ITAB> [ASSIGNING <FIELD SYMBOL>] [WHERE <COND>].
…
ENDLOOP.
The LOOP and ENDLOOP statements define a loop around internal table records. The LOOP statement
reads lines from internal table <ITAB> sequentially. You can either read all the lines or specify conditions
<COND> to restrict which lines to be read. The statement block between LOOP and ENDLOOP is executed
once for each line.
The sequence in which the lines are read depends on the table type:
Standard tables and sorted tables : The lines are read by ascending table index.
Hashed Tables : The lines are processed in the sequence in which they were inserted in the table, and in
the sort sequence following use of the SORT statement.
The INTO clause is used to move current loop’s record into Work Area. The ASSIGNING clause is used to
assign a field symbol to current loop’s record. Field-Symbol acts as a pointer to the record. Any changes
made to field-symbol values are directly reflected in <<ITAB>, no additional Update or Modify statement is
required.
FIELD-SYMBOLS
Syntax : FIELD-SYMBOLS <FS> { typing | STRUCTURE struc DEFAULT dobj }.
The FIELD-SYMBOLS statement declares a field symbol <FS>. After its declaration, a field symbol is initial -
that is, it does not reference a memory area. You have to assign a memory area to it (normally using the
ASSIGN statement) before you can use it as an operand. Otherwise an exception/short dump will be
triggered.
READ
Syntax : READ TABLE <ITAB> { table_key | free_key | index } result BINARY SEARCH.
This statement reads a row from internal table <ITAB>. You have to specify the row by either naming values
table_key for the table key, a free condition free_key or an index. The output result determines when and
where the row contents are read.
BINARY SEARCH clause makes READ statement a bit faster. Prerequisite for using BINARY SEARCH is
that <ITAB> must be sorted with the keys used in READ’s table key.
SORT
Syntax : SORT <ITAB> [STABLE]
{ { [ASCENDING|DESCENDING]
[BY {comp1 [ASCENDING|DESCENDING] }
{comp2 [ASCENDING|DESCENDING] }
... ] } .
SORT statement sorts an internal table <ITAB>. As standard, numeric and byte-type components are sorted
by their value and character-type components according to their binary representation code page. If no
explicit sort key is entered using the BY addition, the internal table <ITAB> is sorted according to the table
key. In this case, the table key can contain a maximum of 250 components.
Field Description
VNAM Variable name
IOBJNM InfoObject name
SIGN (I)ncluding or (E)xcluding
OPT Operators: EQ =, BT Between, LE <=, LT <, GE >=, GT >, CP
and so on.
LOW Characteristic value
HIGH Upper limit characteristic value for intervals/the node-InfoObject
for hierarchy nodes.
I_STEP parameter from the Exit Function Module determines when customer exit code will be executed.
Depending upon i_step values we can populate values in variable during different steps of BEx execution.
I_STEP has values from 0-3, most commonly used values are explained below.
I_STEP = 0
When i_step has value 0, the enhancement has been called via authorization check or from the monitor and
not from variable screen.
I_STEP = 1
When i_step has value 1 the enhancement call takes place directly before variable entry. This can be used to
populate variable with some default values.
I_STEP = 2
When i_step has value 2 the enhancement call takes place directly after variable entry. This step is only
started up when the same variable is not input ready and could not be filled at I_STEP=1. This step can be
used to validate user input.
I_STEP = 3
When i_step has value 3 you can check the values of the variables. Triggering an exception here (RAISE)
causes the variable screen to appear once more. Afterwards, I_STEP=2 is also called again.
Step 3. Click on change Breakpoints button in front of Transformation. Select ‘Before Transformation’ check
box to debug Start Routine. Select ‘Before End Routine’ check box to debug End Routine.
Step 4. Click on Simulate button to start debugging. Debugging will not actually load data into data target,
instead it will simulate the code behavior for Data Loading.
Note: Instead of above code you can also use SF_SPECIALCHAR_DELETE Function module to remove these special
characters.
Step 6. Create a class object in Start Routine using ‘CREATE OBJECT’ statement. Call class method in
Start Routine using above class object, pass appropriate parameters to the method
Step 7. Call class method in Characteristic Routine using above class object
Related Content
Customer Exits on help.sap.com
Dependencies for Variables of Type Customer Exit
Update Routines and Start Routines
Routines in Transformations
Creating Virtual Characteristic/Key Figures via CMOD and SE38
Creating Virtual Characteristic/Key Figures via BADI