P. 1
Beginners Guide to Bi Abap

Beginners Guide to Bi Abap

|Views: 4|Likes:
Published by eug_n

More info:

Published by: eug_n on Jun 09, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

06/09/2012

pdf

text

original

Beginner's Guide to BI - ABAP

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: Sharayu Kumatkar

Company: L&T Infotech Created on: 09 December 2009

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.

SAP COMMUNITY NETWORK © 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 1

....................................................................................................... 14 Related Content ....................... 7 LOOP ................................... 19 SAP COMMUNITY NETWORK © 2009 SAP AG SDN ..........................................bpx....................................................................................................................... 4 Expert Routine ............ 9 I_STEP = 2 ......... 13 Appendix C: Sample Code ............................................................................................................................................................................. 9 I_STEP = 0 ....................................... 3 End Routine ....................................................................................................... 10 Tips & Tricks .................................................................................. 9 I_STEP = 1 .................................................................................................................................................................................................................................................................................................................OOPS Start and Characteristic Routine .........................................................................com | BOC ........................................................................... 7 SELECT ............................................................................ 3 Start Routine ............................................................................................................................................ 10 Debugging ............................................ 5 Characteristic Routine ........................................................................................................................................................................ 3 Important Note ..................... 8 Customer Exit Variable (BEx) ....................... 9 I_STEP = 3 .........................................................................................................................................................................................................................................com | BPX ............................ 3 Info Package Routine ............. 12 Appendix B: Sample code ............................................................................................................sap..........................Beginner's Guide to BI ..Splitting 60+ char string into multiple IO ................................................................................................................................................................................................. 18 Disclaimer and Liability Notice ................................ 6 Basic Coding Statements Required ......................................................................................................................................................................................................................... 9 Virtual Characteristic / Key Figure ...................................ABAP Table of Contents Different Routines Available in SAP BI ..................Remove Special Characters .............................................................................................................................................. 8 READ ...................................................................... 7 FIELD-SYMBOLS ......................................................................................................................................... 10 Appendix A: Sample Code ...........................................................sap............................ 8 SORT .....................................boc..............................................................................................................................................................................................com 2 .......sdn....................................................................................................sap..........................................................................................................................................

boc.sdn.Beginner's Guide to BI .e. You need to create a routine by clicking on the Routine button.ABAP Different Routines Available in SAP BI Info Package Routine Info Package routine is available with Info Package of Flat file Datasource. Write a code inside this routine to derive file name and assign it to variable p_filename. This routine enables us to give dynamic filename to IP. SAP COMMUNITY NETWORK © 2009 SAP AG SDN . Click on Start Routine button to create Start Routine. Give a name to routine. SOURCE_PACKAGE contains contents of source data. Start Routine Start Routine is available with Transformation. End Routine End Routine is available with Transformation. RESULT_PACKAGE has same structure as that of target Object.bpx.com | BPX . It is triggered before Transformation. It is triggered after Transformation.sap. RESULT_PACKAGE contains process data i.com 3 . processed via start routine and transformation. Generally Start routines are used for Filtering records or fetching global data to be used in Characteristic routine.sap.sap.com | BOC . SOURCE_PACKAGE has same structure as that of Source of the Transformation. Generally End user is used for updating data based on existing data. Click on End Routine button to create End Routine.

sap. fields populated in End routine wont be updated in the data target if no active rule exists for them in Transformation. SAP COMMUNITY NETWORK © 2009 SAP AG SDN . This problem does not occur for key figures if the aggregation summation was set in the transformation. This button is to update behaviour of fields in End Routines. As a result. Alternatively. This problem always occurs for characteristics.ABAP Important Note For support pack 16 and above you get one more button besides End Routine (once end routine is created).sap. The default setting for the pushbutton is that only the fields with active rules are updated in the transformation. You get two options once you select this button. One needs to make selection of proper option as it is mandatory.sdn.sap.com | BOC . If your system is below SP16 then you can implement note 1024816 to get above facility.com | BPX . you can define that all the fields should always be updated by selecting 2nd radio button.Beginner's Guide to BI .bpx. With this selection. Note: Data fields with the 'No transformation' rule type in the transformation are overwritten if the transformation contains an end routine.com 4 .boc. fields filled in the end routine are not lost if there is no other active rule.

SAP COMMUNITY NETWORK © 2009 SAP AG SDN . This is used generally for customizing rules. Expert Routine will trigger without any transformation Rule. key figures are updated by default with the aggregation behaviour Overwrite (MOVE).com | BPX .boc.bpx.ABAP Expert Routine To create an Expert routine go to Edit menu and select Expert Routine. SOURCE_PACKAGE has same structure as that of Source of the Transformation.sdn.Beginner's Guide to BI .sap. Note: If the target of the transformation is a Data Store Object.sap.sap. You can manipulate values from SOURCE_PACKAGE and append them in RESULT_PACKAGE.com | BOC .com 5 . All existing Rules will be deleted once you develop Expert Routine. RESULT_PACKAGE has same structure as that of target Object.

sdn.ABAP Characteristic Routine Characteristic Routine is inside Transformation. In Rule details of transformation select Routine to create a Characteristic Routine.boc. All global objects declared in Start Routine are available in Characteristic Routine. This routine will be triggered inside the Transformation based on the characteristic or key figure. which in turn will get assigned to InfoObject. If rule is for Characteristic.com | BOC . SAP COMMUNITY NETWORK © 2009 SAP AG SDN . Characteristic routine is executed after Start routine and before End Routine. Here you can do calculation of InfoObject value and assign value to variable Result.bpx.sap. then Characteristic transformation routine will trigger.sap.com | BPX .Beginner's Guide to BI . then key figure transformation routine will trigger.com 6 .sap. If rule is for key figure.

com 7 . 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.sap. … ENDLOOP. GE. GT.com | BPX .ABAP Basic Coding Statements Required SELECT Syntax : SELECT result FROM source INTO/APPENDING target [[FOR ALL ENTRIES IN <ITAB>] WHERE <COND>] [GROUP BY <GROUP>] [HAVING <GROUP COND>] [ORDER BY <SORT KEY>].sdn. LOOP Syntax : LOOP AT <ITAB> [INTO <WORK AREA>] [WHERE <COND>]. at the end of ITAB. Existing contents of ITAB remains unchanged.com | BOC . . The LOOP and ENDLOOP statements define a loop around internal table records. SAP COMMUNITY NETWORK © 2009 SAP AG SDN . >=. EQ. <>. Hashed Tables : The lines are processed in the sequence in which they were inserted in the table.Beginner's Guide to BI . You can either read all the lines or specify conditions <COND> to restrict which lines to be read. WHERE : The addition WHERE is used to restrict the number of records fetched by SELECT statement.sap.. OR LOOP AT <ITAB> [ASSIGNING <FIELD SYMBOL>] [WHERE <COND>]. Frequently used options of SELECT: 1. >.sap. The LOOP statement reads lines from internal table <ITAB> sequentially. NE. and in the sort sequence following use of the SORT statement. <. INTO clause refreshes ITAB contents and adds new records fetched by SELETC into ITAB. <.bpx.. LE BETWEEN LIKE IN IS NULL FOR ALL ENTRIES : If the addition FOR ALL ENTRIES is specified before WHERE clause. =. LT. SELECT will return records from database which are matching with the <ITAB> based on WHERE clause. The internal table <ITAB> must have a structured line type and the component comp must be compatible with the column col. then the fields from the internal table <ITAB> can be used as operands when comparing with relational operators. LE. INTO/ APPENDING : Addition INTO specifies where the records fetched by SELECT will get stored. 3. <=. The logical expression compares the content of columns in the database with the conditions provided in Where clause. Addition APPENDING will add records fetched by SELECT.boc. ENDLOOP. The statement block between LOOP and ENDLOOP is executed once for each line. Terms that can be used as Logical Expressions for a WHERE Condition are      2.

boc. SORT statement sorts an internal table <ITAB>.ABAP The INTO clause is used to move current loop’s record into Work Area. The output result determines when and where the row contents are read. ] } .com | BOC . FIELD-SYMBOLS Syntax : FIELD-SYMBOLS <FS> { typing | STRUCTURE struc DEFAULT dobj }. After its declaration. You have to specify the row by either naming values table_key for the table key. the table key can contain a maximum of 250 components.bpx. no additional Update or Modify statement is required. a field symbol is initial that is. SORT Syntax : SORT <ITAB> [STABLE] { { [ASCENDING|DESCENDING] [BY {comp1 [ASCENDING|DESCENDING] } {comp2 [ASCENDING|DESCENDING] } . This statement reads a row from internal table <ITAB>. a free condition free_key or an index.sap. READ Syntax : READ TABLE <ITAB> { table_key | free_key | index } result BINARY SEARCH. Field-Symbol acts as a pointer to the record. You have to assign a memory area to it (normally using the ASSIGN statement) before you can use it as an operand.com 8 .com | BPX . As standard. If no explicit sort key is entered using the BY addition. the internal table <ITAB> is sorted according to the table key.sdn.Beginner's Guide to BI . Prerequisite for using BINARY SEARCH is that <ITAB> must be sorted with the keys used in READ’s table key. The FIELD-SYMBOLS statement declares a field symbol <FS>. it does not reference a memory area. SAP COMMUNITY NETWORK © 2009 SAP AG SDN . In this case.sap. BINARY SEARCH clause makes READ statement a bit faster. The ASSIGNING clause is used to assign a field symbol to current loop’s record. Any changes made to field-symbol values are directly reflected in <<ITAB>.. numeric and byte-type components are sorted by their value and character-type components according to their binary representation code page.. Otherwise an exception/short dump will be triggered.sap.

LT <. I_STEP parameter from the Exit Function Module determines when customer exit code will be executed. Data records from BEx query are passed in I_T_VAR_RANGE internal table. Depending upon i_step values we can populate values in variable during different steps of BEx execution. This can be used to populate variable with some default values. I_STEP has values from 0-3. This step can be used to validate user input. Characteristic value Upper limit characteristic value for intervals/the node-InfoObject for hierarchy nodes.Beginner's Guide to BI . LE <=.sap. GT >. most commonly used values are explained below. Structure of this internal table is as follows: Field VNAM IOBJNM SIGN OPT LOW HIGH Description Variable name InfoObject name (I)ncluding or (E)xcluding Operators: EQ =.sdn. Triggering an exception here (RAISE) causes the variable screen to appear once more.com | BPX .sap. I_STEP = 1 When i_step has value 1 the enhancement call takes place directly before variable entry. Afterwards.boc. This step is only started up when the same variable is not input ready and could not be filled at I_STEP=1. the enhancement has been called via authorization check or from the monitor and not from variable screen. I_STEP = 0 When i_step has value 0. Coding for Customer Exit variable is done in EXIT_SAPLRRS0_001 Function Module.ABAP Customer Exit Variable (BEx) Customer Exit Variable created in BEx query provides means to do complex calculation (not possible with BEx) in ABAP.sap.com | BOC . GE >=. SAP COMMUNITY NETWORK © 2009 SAP AG SDN . BT Between. I_STEP = 3 When i_step has value 3 you can check the values of the variables.com 9 . I_STEP = 2 When i_step has value 2 the enhancement call takes place directly after variable entry. I_STEP=2 is also called again.bpx. CP and so on.

Put a hard coded break point (BREAK-POINT) in Start Routine/End Routine which you desire to debug. Tips & Tricks Debugging Following screenshots will explain how to debug code written in Start Routine or End Routine. But if you want virtual KF for large number of Query fields then opt for BADI method. SAP COMMUNITY NETWORK © 2009 SAP AG SDN . Choose processing mode as ‘Serially in the Dialog Process (for Debugging)’. For more details please refer to links provided in ‘Related Content’ section.sdn. Step 1.Beginner's Guide to BI . go to Execute tab.ABAP Virtual Characteristic / Key Figure There are two ways of developing Virtual Characteristics / Key figures.sap. One is using BADI and other is using CMOD & SE38. Step 2. If you are developing virtual KF for few Query fields then you should opt for SE38 method.bpx.sap.com 10 .boc.com | BPX . Open DTP of desired transformation.com | BOC .sap. as it is very easy to maintain.

SAP COMMUNITY NETWORK © 2009 SAP AG SDN .com | BOC . Click on change Breakpoints button in front of Transformation.com | BPX . Click on Simulate button to start debugging.sdn. Debugging will not actually load data into data target.com 11 .sap. Select ‘Before End Routine’ check box to debug End Routine.ABAP Step 3.bpx.sap.Beginner's Guide to BI . Select ‘Before Transformation’ check box to debug Start Routine.boc.sap. Step 4. instead it will simulate the code behavior for Data Loading.

--.Beginner's Guide to BI . Code for InfoObject 2 Characteristic routine: *Read 60-119 characters from the string and assign to Result MOVE SOURCE_FIELDS-STRING+60(60) TO RESULT.bpx. Code for InfoObject 1 Characteristic routine: *Read first 60 characters from the string and assign to Result MOVE SOURCE_FIELDS-STRING+0(60) TO RESULT. we need to split this string into two InfoObjects.sap.com | BPX .Code provided by Mr.sap.Splitting 60+ char string into multiple IO Consider an example of character string of 120 Characters fetched via Datasource.com 12 .boc.com | BOC .ABAP Appendix A: Sample Code . Following is the characteristic code routine for these InfoObjects.sap. Note: SAP String character numbering starts with 0.sdn. Kartik Ravi SAP COMMUNITY NETWORK © 2009 SAP AG SDN . As BI has character limit of 60 for an InfoObject.

sap. Result) till special characters are found in string WHILE RESULT CN '%&()"''*+.Remove Special Characters Most data loading related errors in BI are due to some special character in Datasource string.Code provided by Mr.-.sap. *Remove blank spaces from string by condensing it.boc.e. CONDENSE RESULT. *Convert string into Upper case TRANSLATE RESULT TO UPPER CASE.com | BOC . SAP COMMUNITY NETWORK © 2009 SAP AG SDN .sap. CONDENSE RESULT.bpx. RESULT(1) = ' '. *Replace special character found with none i.com | BPX . *Conditional loop on String (i.e. RESULT+SY-FDPOS(1) = ' '. IF RESULT(1) = '#'.com 13 .Beginner's Guide to BI .sdn./:. ENDIF. Code: * Assign source field to Result RESULT = SOURCE_FIELDS-ZZLIFEX. Following code is helpful in avoiding such errors by removing special characters from the string. ENDWHILE. --. remove special character * sy-fdpos -> Found location for search in byte-type and character-type data objects. *If first character of string is a space or special character ‘#’ then remove it.ABAP Appendix B: Sample code .<=>?_#~@!$^[]{}0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ '. Tej Trivedi Note: Instead of above code you can also use SF_SPECIALCHAR_DELETE Function module to remove these special characters.

OOPS Start and Characteristic Routine These days most of the clients are asking for OOPS programming in the routine.com | BOC .sap. which can be called from all the routines. The main purpose of OOPS is to obtain modularity in the code.sap. Step 1.bpx. Frequently used code is converted into a class method.sdn. Following is a step by step example of basic OOPS programming used for Start Routine and Characteristic Routine. Create a class using TCODE SE24 SAP COMMUNITY NETWORK © 2009 SAP AG SDN .Beginner's Guide to BI .com 14 .com | BPX .boc.ABAP Appendix C: Sample Code .sap.

com 15 .sdn.sap.boc. Assign parameters to the method by clicking on parameters button SAP COMMUNITY NETWORK © 2009 SAP AG SDN .ABAP Step 2.sap.bpx.Beginner's Guide to BI . Create a method inside this class Step 3.sap.com | BOC .com | BPX .

Write code inside method Step 5.ABAP Step 4. Define class instance in global are of Start Routine SAP COMMUNITY NETWORK © 2009 SAP AG SDN .Beginner's Guide to BI .sap.com 16 .com | BOC .sap.sap.sdn.boc.com | BPX .bpx.

sdn.sap.com | BOC . Call class method in Start Routine using above class object.sap.sap. Call class method in Characteristic Routine using above class object ---Code provided by Ms. pass appropriate parameters to the method Step 7.Beginner's Guide to BI .ABAP Step 6.bpx.com | BPX .boc. Kshitija Karadkhedkar SAP COMMUNITY NETWORK © 2009 SAP AG SDN . Create a class object in Start Routine using ‘CREATE OBJECT’ statement.com 17 .

bpx.sap.sap.sap.com | BPX .sap.Beginner's Guide to BI .sdn.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 SAP COMMUNITY NETWORK © 2009 SAP AG SDN .com 18 .boc.ABAP Related Content Customer Exits on help.com | BOC .

boc.com 19 . and anyone using these methods does so at his/her own risk.com | BOC . SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample. code or methods suggested in this document. You agree that you will not hold. or seek to hold.com | BPX .sap.ABAP Disclaimer and Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.bpx. SAP COMMUNITY NETWORK © 2009 SAP AG SDN . including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. SAP will not be held liable for any damages caused by using or misusing the information.sap.Beginner's Guide to BI .sdn.sap. SAP responsible or liable with respect to the content of this document.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->