return table%3a how to achieve this in sap bi 7.0.pdf

20
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 1 Return Table How to Achieve this in SAP BI 7.0. Applies to: SAP BI 7.0.For more information, visit the Business Intelligence homepage . Summary This paper is about the return table of BW 3.5. Then in particular the paper focuses on how the concept of return table is achieved in BI 7.0. The paper explains the concept using a simple scenario. The paper gives different approaches to achieve the concept. The paper also gives the sample code and results at the end of each approach for the scenario. Author: Vamsi Kiran Talluri Company: Tata Consultancy Services Ltd. Created on: 27 October 2009 Author Bio The author works for Tata Consultancy Services Ltd. His expertise includes SAP BI and ABAP

Upload: srinu-jhon

Post on 13-Dec-2015

242 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

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

© 2009 SAP AG 1

Return Table – How to Achieve

this in SAP BI 7.0.

Applies to:

SAP BI 7.0.For more information, visit the Business Intelligence homepage.

Summary

This paper is about the return table of BW 3.5. Then in particular the paper focuses on how the concept of return table is achieved in BI 7.0. The paper explains the concept using a simple scenario. The paper gives different approaches to achieve the concept. The paper also gives the sample code and results at the end of each approach for the scenario.

Author: Vamsi Kiran Talluri

Company: Tata Consultancy Services Ltd.

Created on: 27 October 2009

Author Bio

The author works for Tata Consultancy Services Ltd. His expertise includes SAP BI and ABAP

Page 2: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 2

Table of Contents

Introduction ................................................................................................................................................... 3

Scenario ....................................................................................................................................................... 3

Approach A - Using Start Routine and End Routine ....................................................................................... 4

Approach to Scenario ................................................................................................................................ 4

How to Implement...................................................................................................................................... 4

Output ....................................................................................................................................................... 9

Approach B - Using only Start Routine ........................................................................................................ 10

Approach to Scenario .............................................................................................................................. 10

How to Implement.................................................................................................................................... 10

Sample Code........................................................................................................................................... 12

Output ..................................................................................................................................................... 13

Approach C - Using Expert Routine ............................................................................................................. 14

Approach to Scenario .............................................................................................................................. 14

How to Implement.................................................................................................................................... 14

Sample Code........................................................................................................................................... 16

Output ..................................................................................................................................................... 17

Conclusions ................................................................................................................................................ 18

Related Content .......................................................................................................................................... 19

Disclaimer and Liability Notice ..................................................................................................................... 20

Page 3: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 3

Introduction

In most of the cases data won’t be coming directly in required form before sending to the target. The source and target structure may not always be the same. Return table is used to obtain multiple records based on a single source record. This option is present in SAP BW 3.5 to split an incoming record into multiple records.

This paper shows how to achieve the concept of Return table in SAP BI 7.0. This paper presents a scenario and the different approaches to achieve the scenario.

Scenario

The Scenario is for a sales region the data across three diff months of a year with their sales value will be coming in a single record into the source. But the target structure is entirely different it has only one month and sales value field. So the target should be updated with three individual records.

Data from the Source

Sales Region Year Month1 Sales1 Month2 Sales2 Month3 Sales3

101 2009 JAN 1000 FEB 2000 MAR 3000

Data from Target Should be like

Sales Region Year Month Sales

101 2009 JAN 1000

101 2009 FEB 2000

101 2009 MAR 3000

Note: Here in this scenario, I have taken the source data only for three month fields and three sales value fields. In other

cases it may come up with all the twelve months and twelve sales values fields. Then each source record has to

be split into twelve records.

This note will play some importance and will be explained later.

Data from PSA:

Page 4: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 4

Approach A - Using Start Routine and End Routine

Approach to Scenario

In all the Approaches A, B, C taken in the paper most of the steps will be same.

1) In Start Routine we will create an internal table in the global section, as it will be visible every where.

2) In Start Routine we will loop at the Source_Package which contains the incoming data.

3) While looping across the Source_Package we will split the source record into 3 records.

4) These 3 records will be stored in the internal table.

5) Similarly for all the records will be split and will be stored in internal table.

These 1-5 Steps are common for all the three approaches. Once we get the data in the internal table there will be difference in transformation mappings across all the approaches.

6) Now the data will be available in internal table and it is visible in end routine also.

7) As a result we need not map all the mappings from source to target why because we will flush out all the Result_Package values in end routine and replace them with internal table values which is desired output.

How to Implement

In the below screen shot only one field is mapped from source to target. This is because in the start routine we will process all the data from Source_Package into internal table. And all the data that will flow through transformation i.e. Source_Package will go into Result_Package which we are flushing out. So we need not map all the necessary mappings, populate Result_Package and flush it.

Page 5: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 5

In Start Routine we have created an internal table in global part. This internal table is populated using Source_Package.

Do 3 times this is because we have three month values and three sales values. If we take twelve month values and twelve sales values we have to take do 12 times as mentioned in Note.

Page 6: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 6

So at the end of Start routine internal table contains the desired split values. The values that go from Source_Package to Result_Package through transformation mappings will be flushed in end routine.

This is the code written in end routine.

We are flushing out the Result_Package values. And then we will move all the values from internal table to Result_Package.

The Start and End Routines are checked and saved and the transformation is activated.

Page 7: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 7

When triggered the DTP we can see there is split of 2 source records into 6 records.

Page 8: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 8

Sample Code

In Start Routine

******************This part in global section********************* FIELD-SYMBOLS: <mth> , <sls> . TYPES : begin of ty_itab,

region_code type /bic/oizsl_rgn,

year type /bic/oizyear,

month type /bic/oizmonth,

sales type /bic/oizsales,

end of ty_itab.

DATA: l_index TYPE c length 1,

l_fnam type c length 50,

l_fnam1 type c length 50.

DATA: itab TYPE STANDARD TABLE OF ty_itab,

wa_itab LIKE LINE OF itab.

***********************************************************************************

data : wa_source_package type _ty_s_SC_1.

loop at SOURCE_PACKAGE into wa_SOURCE_PACKAGE.

do 3 times.

MOVE sy-index TO l_index.

CONCATENATE 'wa_source_package-/bic/zmnth' l_index INTO l_fnam.

ASSIGN (l_fnam) TO <mth>.

check not <mth> is initial.

CONCATENATE 'wa_source_package-/bic/zsales' l_index INTO l_fnam1.

ASSIGN (l_fnam1) TO <sls>.

check not <sls> is initial.

CLEAR wa_itab.

wa_itab-region_code = wa_source_package-/BIC/ZSL_RGN.

wa_itab-year = wa_source_package-/BIC/ZYEAR.

wa_itab-month = <mth>.

wa_itab-sales = <sls>.

APPEND wa_itab TO itab.

enddo.

ENDLOOP.

In End Routine clear RESULT_PACKAGE. data : wa_result_package type _ty_s_TG_1. loop at itab into wa_itab. wa_result_package-/BIC/ZSL_RGN = wa_itab-region_code. wa_result_package-/BIC/ZYEAR = wa_itab-year. wa_result_package-/BIC/ZMNTH = wa_itab-month. wa_result_package-/BIC/ZSALES = wa_itab-sales. append wa_RESULT_PACKAGE to RESULT_PACKAGE. endloop.

Page 9: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 9

Output

Page 10: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 10

Approach B - Using only Start Routine

Approach to Scenario

The Approach B to the Scenario will be almost similar to the above Approach.

1) In Start Routine we will create an internal table in the global section, as it will be visible every where.

2) In Start Routine we will loop at the Source_Package which contains the incoming data.

3) While looping across the Source_Package we will split the source record into 3 records.

4) These 3 records will be stored in the internal table.

5) Similarly for all the records will be split and will be stored in internal table.

As said above in Approach A Steps (1-5) will be same. Next comes small changes

6) In this approach we wont flush the Result_Package instead we will flush out the entire Source_Package.

7) Then the values from internal table will be sent to Source_Package and the month and sales values will be sent to any one of the three month and sales values fields in Source.

8) The fields which are populated should be mapped to the target.

How to Implement

In this approach we will get desired records in internal table first using Start Routine. Next We will flush the Source_Package then the two incoming records will be removed. Now from the internal table we will move the month and sales value to say any of the three month or sales value fields. In this Scenario I have used Month1 and Salesvalue1 so we will map Month1 and Sales value1 to Month and Sales. The other field data are also taken into Source_Package from internal table.

Here we have no end routine only start routine.

Page 11: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 11

In the Start Routine we are flushing out Source_Package once we get all the values into internal table.

Next we will move all the values into Source_Package and the Month and Sales for example moving to

Month1 and Sales Value1

Now the Start Routine is checked and the transformation is activated. Only Start no End Routine here

Page 12: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 12

We can see the Split of 2 Source Records into 6 Output Records

Sample Code

In Start Routine

******************This part in global section********************* FIELD-SYMBOLS: <mth> , <sls> . TYPES : begin of ty_itab, region_code type /bic/oizsl_rgn, year type /bic/oizyear, month type /bic/oizmonth, sales type /bic/oizsales, end of ty_itab. DATA: l_index TYPE c length 1, l_fnam type c length 50, l_fnam1 type c length 50. DATA: itab TYPE STANDARD TABLE OF ty_itab, wa_itab LIKE LINE OF itab. ***********************************************************************************

data : wa_source_package type _ty_s_SC_1.

loop at SOURCE_PACKAGE into wa_SOURCE_PACKAGE.

do 3 times.

MOVE sy-index TO l_index.

CONCATENATE 'wa_source_package-/bic/zmnth' l_index INTO l_fnam.

ASSIGN (l_fnam) TO <mth>.

check not <mth> is initial.

CONCATENATE 'wa_source_package-/bic/zsales' l_index INTO l_fnam1.

ASSIGN (l_fnam1) TO <sls>.

check not <sls> is initial.

CLEAR wa_itab.

wa_itab-region_code = wa_source_package-/BIC/ZSL_RGN.

wa_itab-year = wa_source_package-/BIC/ZYEAR.

Page 13: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 13

wa_itab-month = <mth>.

wa_itab-sales = <sls>.

APPEND wa_itab TO itab.

enddo.

ENDLOOP.

****************Up to above Code part it is same for previous approach

also******************

clear SOURCE_PACKAGE.

loop at itab into wa_itab.

wa_source_package-/BIC/ZSL_RGN = wa_itab-region_code .

wa_source_package-/BIC/ZYEAR = wa_itab-year.

wa_source_package-/BIC/ZMNTH1 = wa_itab-month.

wa_source_package-/BIC/ZSALES1 = wa_itab-sales.

append wa_SOURCE_PACKAGE to SOURCE_PACKAGE.

endloop.

Output

Page 14: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 14

Approach C - Using Expert Routine

Approach to Scenario

In this approach we don’t have the start and end routine as we are writing the expert routine.

All the transformation mappings every things needs to be taken care by expert routine.

1) In Expert Routine using Source_Package we will have the source data.

2) Using Source_Package we will populate internal table.

3) While Populating internal table we will split the Source data.

In this approach we won’t flush out Source_Package or Result_Package. We have to populate Result_Package with the data of internal table.

4) The End Routine Code in Approach A will be also added to this Expert Routine Code and that finishes the job except the flush statement which is optional because till now we didn’t have any data into Result_Package.

How to Implement

Once We go into change mode of transformation go to edit and click Expert Routine. Then It shows all the existing mappings and transformation will be deleted.

Page 15: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 15

Click Yes and it will take us to the editor.

Write the Code in the editor and check the code and save it and then activate the transformation.

Page 16: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 16

We can see all the transformation mappings are removed. Only Expert Routine is Enabled.

Sample Code

******************This part in global section********************* FIELD-SYMBOLS: <mth> , <sls> . TYPES : begin of ty_itab, region_code type /bic/oizsl_rgn, year type /bic/oizyear, month type /bic/oizmonth, sales type /bic/oizsales, end of ty_itab. DATA: l_index TYPE c length 1, l_fnam type c length 50, l_fnam1 type c length 50. DATA: itab TYPE STANDARD TABLE OF ty_itab, wa_itab LIKE LINE OF itab. ***********************************************************************************

data : wa_source_package type _ty_s_SC_1.

data : wa_result_package type _ty_s_TG_1.

loop at SOURCE_PACKAGE into wa_SOURCE_PACKAGE.

do 3 times.

MOVE sy-index TO l_index.

CONCATENATE 'wa_source_package-/bic/zmnth' l_index INTO l_fnam.

ASSIGN (l_fnam) TO <mth>.

check not <mth> is initial.

CONCATENATE 'wa_source_package-/bic/zsales' l_index INTO l_fnam1.

ASSIGN (l_fnam1) TO <sls>.

check not <sls> is initial.

CLEAR wa_itab.

wa_itab-region_code = wa_source_package-/BIC/ZSL_RGN.

wa_itab-year = wa_source_package-/BIC/ZYEAR.

Page 17: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 17

wa_itab-month = <mth>.

wa_itab-sales = <sls>.

APPEND wa_itab TO itab.

enddo.

ENDLOOP.

loop at itab into wa_itab.

wa_result_package-/BIC/ZSL_RGN = wa_itab-region_code.

wa_result_package-/BIC/ZYEAR = wa_itab-year.

wa_result_package-/BIC/ZMNTH = wa_itab-month.

wa_result_package-/BIC/ZSALES = wa_itab-sales.

append wa_RESULT_PACKAGE to RESULT_PACKAGE.

endloop.

Output

Page 18: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 18

Conclusions

1) Approach A – Using Start and End Routine: In this Approach we will populate an internal table

using Source_Package of Start Routine. This Internal table contains all the records obtained after splitting the source records in Start Routine. The transformation mappings u can map any of the fields because we will be flushing the Result_Package Values later in End Routine. Then in the End Routine we will flush the Result_Package and populate with the internal table values.

2) Approach B – Using Start Routine only: In this Approach also we will populate an internal table

using Source_Package of Start Routine. This Internal table contains all the records obtained after splitting the source records in desired output form. After this we will flush the Source_Package and we will populate this with the internal table values. And regarding the Month and Sales value it will be populated to the one of the three month and Sales value and therefore this is mapped to the target in transformation. This Approach looks quite confusing until and unless we check the Start Routine.

3) Approach C – Using Expert Routine: In this Approach all the mappings, start and end routines

should be taken care by expert routine. Here also we will populate an internal table using Source_Package present in Expert Routine .Then the internal table contains all the records obtained after splitting the source records in desired output form. After that we will populate the Result_Package using internal table.

Page 19: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 19

Related Content

For more information, visit the Business Intelligence homepage.

Page 20: Return Table%3a How to Achieve this in SAP BI 7.0.pdf

Return Table – How to Achieve this in SAP BI 7.0.

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

© 2009 SAP AG 20

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.