19
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com © 2011 SAP AG 1 Role and Scope of ABAP in SAP BI Applies to: SAP NetWeaver BW. For more information, visit the EDW homepage Summary The document provides a detailed description of the usage of APAP in SAP BI. Author: Adlin Sundararaj & Kavita Srivastava Company: Accenture Services Pvt. Ltd. Created on: 10 March 2011 Author Bio Adlin Sundararaj is working as SAP-BI Consultant in Accenture Services Private Ltd and has experience of working on implementation and maintenance projects. Kavita Srivastava is working as SAP-BI Consultant in Accenture Services Private Ltd and has rich project experience in SAP-BI domain.

BI Routines

Embed Size (px)

Citation preview

Page 1: BI Routines

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 1

Role and Scope of ABAP in SAP BI

Applies to:

SAP NetWeaver BW. For more information, visit the EDW homepage

Summary

The document provides a detailed description of the usage of APAP in SAP BI.

Author: Adlin Sundararaj & Kavita Srivastava

Company: Accenture Services Pvt. Ltd.

Created on: 10 March 2011

Author Bio

Adlin Sundararaj is working as SAP-BI Consultant in Accenture Services Private Ltd and has experience of working on implementation and maintenance projects.

Kavita Srivastava is working as SAP-BI Consultant in Accenture Services Private Ltd and has rich project experience in SAP-BI domain.

Page 2: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 2

Table of Contents

Routines .............................................................................................................................................................. 3

Start Routine ................................................................................................................................................... 3

End Routine .................................................................................................................................................... 4

Expert Routine ................................................................................................................................................ 4

InfoPackage Routine ....................................................................................................................................... 5

Characteristic Routine ..................................................................................................................................... 5

ABAP in Process Chains .................................................................................................................................... 6

Customer Exit Variable (BEx) ............................................................................................................................. 9

Data Extraction ................................................................................................................................................. 10

Enhancing a Datasource in ECC/SRM using Tcode RSA6 .......................................................................... 10

Related Content ................................................................................................................................................ 18

Disclaimer and Liability Notice .......................................................................................................................... 19

Page 3: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 3

Routines

The different Routines Available in SAP BI are as follows:

Start Routine

End Routine

Expert Routine

InfoPackage Routine

Characteristic Routine

Start Routine

The start routine is run for each data package at the start of the transformation. The start routine has a table in the format of the source structure as input and output parameters. It is used to perform preliminary calculations and store these in a global data structure or in a table. This structure or table can be accessed from other routines. You can modify or delete data in the data package.

Click on Start Routine button (Circled in Red)to create Start Routine. SOURCE_PACKAGE contains contents of source data. SOURCE_PACKAGE has same structure as that of Source of the Transformation.

Page 4: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 4

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.

An end routine is a routine with a table in the target structure format as input and output parameters. You can use an end routine to postprocess data after transformation on a package-by-package basis. For example, you can delete records that are not to be updated, or perform data checks.

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.

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.

This type of routine is only intended for use in special cases. You can use the expert routine if there are not sufficient functions to perform a transformation. The expert routine should be used as an interim solution until the necessary functions are available in the standard routine.

You can use this to program the transformation yourself without using the available rule types. You must implement the message transfer to the monitor yourself. If you have already created transformation rules, the system deletes them once you have created an expert routine. 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.

Page 5: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 5

InfoPackage Routine

Info Package routine is available with Info Package of Flat file Datasource. This routine enables us to give dynamic filename to IP. To Create Routine for filename, click the button circled in red in the image below.

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.

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.

This routine is available as a rule type; you can define the routine as a transformation rule for a key figure or a characteristic. The input and output values depend on the selected field in the transformation rule

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.

Page 6: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 6

ABAP in Process Chains

Use the ABAP Program process type if you want to use a simple, independent program in a chain or if you want to use a program scheduled by a user or another program in the background. This allows you to schedule a program of your choice (ABAP report) in the process chain management, with or without program variants.

To add a ABAP Program process type:

Go to RSPC.

Click on the Process Types button circled in red below.

Here you can also see the ABAP Program process variant in the ‘General Services list’.

Drag and drop the variant into the process chain build pane.

You will get the following pop-up asking for the program name.

You can either use a pre-existing program by pressing

Alternatively, you can create a new program by pressing

In our example we will be using a pre-existing program ZTESTOSC.Press to confirm.

Page 7: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 7

You will see that the new ABAP Program process block has appeared. It is circled in red below.

Page 8: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 8

Now, Connect it to the process chain flow.

Page 9: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 9

Customer Exit Variable (BEx)

Customer Exit Variable created in BEx query provides means to do complex calculation (not possible with BEx) in ABAP. Coding for Customer Exit variable is done in EXIT_SAPLRRS0_001 Function Module. Data records from BEx query are passed in I_T_VAR_RANGE internal table. Structure of this internal table is as follows:

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.

Page 10: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 10

Data Extraction

Enhancing a Datasource in ECC/SRM using Tcode RSA6

The first step involves logging onto Tcode RSA6 and finding the relevant datasource which will then be enhanced as per the additional requirements.

Search for the required Datasource in the datasource list:

Page 11: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 11

Click on enhance extraction structure:

An append structure needs to be created which will contain all the enhanced fields along with their

metadata definition. Give a name to the append structure starting with ‘Z’:

Page 12: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 12

Define the structure with the fields:

Activate the append structure and save the datasource:

Page 13: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 13

Click on change datasource and unhide the new fields if required:

Post activation, one needs to write the exit code in the source system to populate the source fields.

The same is done through Tcode CMOD wherein you can then refer to the associated project and

log onto enhancement RSAP0001.

The following four exits exists and will be enhanced depending on the requirements:

• EXIT_SAPLRSAP_001 – Transaction data

• EXIT_SAPLRSAP_002 – Master Data Attributes

• EXIT_SAPLRSAP_003 – Master Data Text

• EXIT_SAPLRSAP_004 – Master Data Hierarchy

Tcode: CMOD:

Page 14: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 14

Enhancement for writing code for enhanced fields of datasource:

Different User Exits:

Page 15: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 15

The include as shown below will contain all the relevant code controls which define the field population. This is a generic include and the code piece needs to be controlled through datasource name as shown below in the sample code (screenshot). The existing fields along with their values are stored in the internal table

C_T_Data which is to be further modified to also include and populate values for the newly enhanced and added fields.

Further modularization can be done by creating datasource specific includes. The technique also helps in better readability of the code.

Page 16: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 16

Page 17: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 17

Once the changes are done & new fields are fetched, internal table C_T_Data needs to be modified accordingly. The modifications and the new fields population is then automatically transferred to the fields of the datasource. The same can then be validated by executing the datasource through Tcode RSA3.

Page 18: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 18

Related Content

http://wiki.sdn.sap.com/wiki/display/BI/ABAP+in+BW

ABAP Development for SAP NetWeaver BI – User Exits and BAdIs (2nd Edition)

http://forums.sdn.sap.com/thread.jspa?threadID=6021

For more information, visit the EDW homepage

Page 19: BI Routines

Role & Scope of ABAP in SAP BW/BI

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 19

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.

SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk.

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, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.