27
SAP NetWeaver How-To Guide How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW Applicable Releases: SAP NetWeaver BW 7.0 and higher Topic Area: Enterprise Data Warehousing Version 1.0 March 2012

How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

Embed Size (px)

DESCRIPTION

How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

Citation preview

Page 1: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

SAP NetWeaver

How-To Guide

SAP NetWeaver

How-To Guide

How To... Perform ABAP Unit Tests

for Transformations in SAP

NetWeaver BW

Applicable Releases:

SAP NetWeaver BW 7.0 and higher

Topic Area:

Enterprise Data Warehousing

Version 1.0

March 2012

Page 2: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

© Copyright 2012 SAP AG. All rights reserved.

No part of this publication may be reproduced or

transmitted in any form or for any purpose without the

express permission of SAP AG. The information contained

herein may be changed without prior notice.

Some software products marketed by SAP AG and its

distributors contain proprietary software components of

other software vendors.

Microsoft, Windows, Outlook, and PowerPoint are

registered trademarks of Microsoft Corporation.

IBM, DB2, DB2 Universal Database, OS/2, Parallel

Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390,

OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP,

Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix,

i5/OS, POWER, POWER5, OpenPower and PowerPC are

trademarks or registered trademarks of IBM Corporation.

Adobe, the Adobe logo, Acrobat, PostScript, and Reader

are either trademarks or registered trademarks of Adobe

Systems Incorporated in the United States and/or other

countries.

Oracle is a registered trademark of Oracle Corporation.

UNIX, X/Open, OSF/1, and Motif are registered

trademarks of the Open Group.

Citrix, ICA, Program Neighborhood, MetaFrame,

WinFrame, VideoFrame, and MultiWin are trademarks or

registered trademarks of Citrix Systems, Inc.

HTML, XML, XHTML and W3C are trademarks or

registered trademarks of W3C®, World Wide Web

Consortium, Massachusetts Institute of Technology.

Java is a registered trademark of Sun Microsystems, Inc.

JavaScript is a registered trademark of Sun Microsystems,

Inc., used under license for technology invented and

implemented by Netscape.

MaxDB is a trademark of MySQL AB, Sweden.

SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP

NetWeaver, and other SAP products and services

mentioned herein as well as their respective logos are

trademarks or registered trademarks of SAP AG in

Germany and in several other countries all over the world.

All other product and service names mentioned are the

trademarks of their respective companies. Data contained

in this document serves informational purposes only.

National product specifications may vary.

These materials are subject to change without notice.

These materials are provided by SAP AG and its affiliated

companies ("SAP Group") for informational purposes only,

without representation or warranty of any kind, and SAP

Group shall not be liable for errors or omissions with

respect to the materials. The only warranties for SAP

Group products and services are those that are set forth in

the express warranty statements accompanying such

products and services, if any. Nothing herein should be

construed as constituting an additional warranty.

These materials are provided “as is” without a warranty of

any kind, either express or implied, including but not

limited to, the implied warranties of merchantability,

fitness for a particular purpose, or non-infringement.

SAP shall not be liable for damages of any kind including

without limitation direct, special, indirect, or consequential

damages that may result from the use of these materials.

SAP does not warrant the accuracy or completeness of the

information, text, graphics, links or other items contained

within these materials. SAP has no control over the

information that you may access through the use of hot

links contained in these materials and does not endorse

your use of third party web pages nor provide any warranty

whatsoever relating to third party web pages.

SAP NetWeaver “How-to” Guides are intended to simplify

the product implementation. While specific product

features and procedures typically are explained in a

practical business context, it is not implied that those

features and procedures are the only approach in solving a

specific business problem using SAP NetWeaver. Should

you wish to receive additional information, clarification or

support, please refer to SAP Consulting.

Any software coding and/or code lines / strings (“Code”)

included in this documentation are only examples and are

not intended to be used in a productive system

environment. The Code is only intended better explain and

visualize the syntax and phrasing rules of certain coding.

SAP does not warrant the correctness and completeness of

the Code given herein, and SAP shall not be liable for

errors or damages caused by the usage of the Code, except

if such damages were caused by SAP intentionally or

grossly negligent.

Disclaimer

Some components of this product are based on Java™. Any

code change in these components may cause unpredictable

and severe malfunctions and is therefore expressively

prohibited, as is any decompilation of these components.

Any Java™ Source Code delivered with this product is only

to be used by SAP’s Support Services and may not be

modified or altered in any way.

Page 3: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

Document History

Document Version Description

1.00 First official release of this guide

Page 4: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

Typographic Conventions

Type Style Description

Example Text Words or characters quoted

from the screen. These

include field names, screen

titles, pushbuttons labels,

menu names, menu paths,

and menu options.

Cross-references to other

documentation

Example text Emphasized words or

phrases in body text, graphic

titles, and table titles

Example text File and directory names and

their paths, messages,

names of variables and

parameters, source text, and

names of installation,

upgrade and database tools.

Example text User entry texts. These are

words or characters that you

enter in the system exactly as

they appear in the

documentation.

<Example

text>

Variable user entry. Angle

brackets indicate that you

replace these words and

characters with appropriate

entries to make entries in the

system.

EXAMPLE TEXT Keys on the keyboard, for

example, F2 or ENTER.

Icons

Icon Description

Caution

Note or Important

Example

Recommendation or Tip

Page 5: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 1

Table of Contents

1. Scenario ................................................................................................................................ 2

2. General Description of the Solution .................................................................................. 2

3. Prerequisite .......................................................................................................................... 2

4. Step by Step Solution.......................................................................................................... 3

4.1 Display Details of the BW Transformation .................................................................... 3

4.2 Define Data Structures for the eCATT Test Data Container ........................................ 5

4.3 Create an eCATT Test Data Container ........................................................................ 7

4.4 Create a Wrapper Class for the Test Data Container ................................................ 10

4.5 Create a Wrapper Class for Class CL_RSTRAN_EXECUTE .................................... 11

4.6 Create Test Class for ABAP Unit Test........................................................................ 12

4.6.1 Program Logic of Test Class ZLCL_TEST_RSTRAN ................................... 13

4.7 Perform ABAP Unit Test for BW Transformation ....................................................... 13

5. Appendix – ABAP Class Coding ...................................................................................... 15

5.1 Coding of Wrapper Class ZCL_TDC_VARIANT ........................................................ 15

5.1.1 Adjustments to Coding of Wrapper Class ZCL_TDC_VARIANT ................... 16

5.2 Coding of Wrapper Class ZCL_RSTRAN_EXECUTE ................................................ 17

5.3 Coding of Test Class ZLCL_TEST_RSTRAN ............................................................ 18

5.3.1 Adjustments to Coding of Test Class ZLCL_TEST_RSTRAN ....................... 21

Page 6: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 2

1. Scenario

ABAP unit tests enable writing and running white box tests during the development of complex BW transformation rules and routines. This How-To document shows you the tools you need to develop BW transformations according to a test-driven paradigm.

2. General Description of the Solution

In this How-To document we describe a prototype implementation of an ABAP unit test for a selected

BW transformation.

In the first step, the details of the selected BW transformation are analyzed to get some basic

information (transformation ID, inbound/outbound data structures) needed for the later

implementation.

Then we create an eCATT-based test data container, which will store inbound (source) data and

expected (target) data values of the BW transformation. In addition, a wrapper class is coded to

access this test data container during the execution of an ABAP unit test.

After these preparation steps we are ready to build the test class itself. This test class invokes a

method of a tested program (provided by the class CL_RSTRAN_EXECUTE) which in turn isolates

and calls the generated ABAP program for the selected BW transformation. Thus it enables to

compare the outbound (target) data of the BW transformation with the expected values.

The ABAP code of this prototype implementation is displayed in the appendix of this document.

It is also described there, what adjustments need to be done to prepare an ABAP unit test for an

arbitrarily chosen BW transformation.

3. Prerequisite

SAP NetWaever BW 7.00, Support Package 28

or SAP NetWaever BW 7.30, Support Package 6

or corresponding support packages of SAP NetWaever BW 7.01, 7.02, 7.31.

Details are provided by OSS note 1645796.

This note also contains correction instructions which you can implement as an advance correction to

enable this ABAP unit test scenario on lower support package levels of SAP NetWaever BW 7.00 or

SAP NetWaever BW 7.30.

Page 7: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 3

4. Step by Step Solution

We now create an ABAP unit test for a selected transformation in SAP NetWeaver BW.

4.1 Display Details of the BW Transformation

Open the Data Warehousing Workbench (transaction RSA1) and navigate the following way to the BW

transformation to be tested:

Choose Goto then use function Modeling and double-click on field InfoProvider. Now press icon

Search to find the target InfoProvider of the BW transformation. Open the list below this InfoProvider

to find the BW transformation to be tested.

Example: Transformation from DataStore Object 0FIAR_O06 to InfoCube 0FIAR_C02

Picture 1: Transformation in Data Warehousing Workbench

The technical name of the transformation determines the transformation ID, which you will need later

in the ABAP unit test code. The transformation from DataStore Object 0FIAR_O06 (source) to

InfoCube 0FIAR_C02 (target) has the transformation ID:

0ON484YZMTWZJJZKKQ6A8S4REX6ROF0F

Now double-click on the transformation to display the details.

Page 8: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 4

Picture 2: Details of Transformation

The details screen displays the structures of inbound (source) data (left side) and outbound (target)

data (right side) of the transformation. The transformation rules are depicted between both source and

target structures.

The example transformation has the inbound data structure of the DataStore Object 0FIAR_O06 and a

flattened outbound data structure representing the characteristics and key figures of the InfoCube

0FIAR_C02. All InfoObjects are mapped from source to target structure except 0FISCVARNT which is

set to constant value K3 in the target structure.

Now choose Extras then use function Display Generated Program to see the ABAP code that was

generated by the SAP BW system for this transformation.

Scroll down to ABAP statement class lcl_transform definition and find the type definitions

for the structures of source data (type _ty_s_SC_1, corresponding to DataStore Object 0FIAR_O06)

and target data (type _ty_s_TG_1, corresponding to InfoCube 0FIAR_C02).

TYPES:

BEGIN OF _ty_s_SC_1,

* InfoObject: 0DEBITOR Customer Number.

DEBITOR TYPE /BI0/OIDEBITOR,

* InfoObject: 0COMP_CODE Company code.

COMP_CODE TYPE /BI0/OICOMP_CODE,

* InfoObject: 0FISCPER Fiscal year / period.

FISCPER TYPE /BI0/OIFISCPER,

* InfoObject: 0DEBIT Total Debit Postings.

DEBIT TYPE /BI0/OIDEBIT,

* InfoObject: 0CREDIT Total credit postings.

CREDIT TYPE /BI0/OICREDIT,

* InfoObject: 0BALANCE Cumulative Balance.

BALANCE TYPE /BI0/OIBALANCE,

* InfoObject: 0SALES Sales for the Period.

SALES TYPE /BI0/OISALES,

* InfoObject: 0CURRENCY Currency Key.

CURRENCY TYPE /BI0/OICURRENCY,

* InfoObject: 0CURTYPE Currency Type.

CURTYPE TYPE /BI0/OICURTYPE,

Page 9: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 5

* Field: RECORD Data record number.

RECORD TYPE RSARECORD,

END OF _ty_s_SC_1.

:

TYPES:

BEGIN OF _ty_s_TG_1,

* InfoObject: 0CHNGID Change run ID.

CHNGID TYPE /BI0/OICHNGID,

* InfoObject: 0RECORDTP Record type.

RECORDTP TYPE /BI0/OIRECORDTP,

* InfoObject: 0REQUID Request ID.

REQUID TYPE /BI0/OIREQUID,

* InfoObject: 0FISCPER Fiscal year / period.

FISCPER TYPE /BI0/OIFISCPER,

* InfoObject: 0FISCVARNT Fiscal year variant.

FISCVARNT TYPE /BI0/OIFISCVARNT,

* InfoObject: 0FISCYEAR Fiscal year.

FISCYEAR TYPE /BI0/OIFISCYEAR,

* InfoObject: 0FISCPER3 Posting period.

FISCPER3 TYPE /BI0/OIFISCPER3,

* InfoObject: 0CURRENCY Currency Key.

CURRENCY TYPE /BI0/OICURRENCY,

* InfoObject: 0DEBITOR Customer Number.

DEBITOR TYPE /BI0/OIDEBITOR,

* InfoObject: 0COMP_CODE Company code.

COMP_CODE TYPE /BI0/OICOMP_CODE,

* InfoObject: 0CURTYPE Currency Type.

CURTYPE TYPE /BI0/OICURTYPE,

* InfoObject: 0SALES Sales for the Period.

SALES TYPE /BI0/OISALES,

* InfoObject: 0DEBIT Total Debit Postings.

DEBIT TYPE /BI0/OIDEBIT,

* InfoObject: 0BALANCE Cumulative Balance.

BALANCE TYPE /BI0/OIBALANCE,

* InfoObject: 0CREDIT Total credit postings.

CREDIT TYPE /BI0/OICREDIT,

* Field: RECORD Data record number.

RECORD TYPE RSARECORD,

END OF _ty_s_TG_1.

Picture 3: Generated program of transformation - Type definitions

Now you have displayed all detail information about the BW transformation which you will need when

you are programming the ABAP unit test for this transformation.

4.2 Define Data Structures for the eCATT Test Data

Container

In this preparing step, you define the data structures for source and target data of the transformation.

These structures will be used to create an eCATT Test Data Container for the inbound (source)

parameter and the expected (target) parameter values.

Page 10: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 6

Data Store Object

The BW system creates a data structure (the table for active records) in the data dictionary (DDIC)

when you activate the corresponding DataStore Object. You can directly use this structure for the

creation of the eCATT Test Data Container.

The technical name of this table is composed of

/BI0/A<technical name of DataStore Object w/o leading 0>00.

Example: DataStore Object 0FIAR_O06 (source of transformation) has the structure defined by

the table for active records with technical name /BI0/AFIAR_O0600. We use this structure

definition while creating the eCATT Test Data Container for the inbound (source) data values.

DataSource, InfoSource, and InfoCube

For these BI Content objects, the BW system does not create flat data structures during content

activation. Therefore, you have to create a corresponding structure in the data dictionary manually

where you can use the type definition of the generated program (see Picture 3).

Example: We create a data structure corresponding to the InfoCube 0FIAR_C02 which shall be

used for creating the eCATT Test Data Container for the expected (target) data values.

Open the data dictionary (transaction SE11) and enter the technical name of the data structure

corresponding to the InfoCube 0FIAR_C02 into field Data type: ZST_EXP_0FIAR_C02. Then press

button Create. On the next pop-up, choose radio button Structure and press Enter.

Add a Short Description of the structure. On the tab strip Components, enter all components (fields)

of the structure and their component type definitions according to the type definitions in the

generated program (see Picture 3).

Picture 4: Components of structure corresponding to InfoCube 0FIAR_C02

Page 11: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 7

Now change to tab strip Currency/quantity fields and define currency key and unit of measure for the

key figures of the structure.

Picture 5: Currency/quantity fields of structure correspondig to InfoCube 0FIAR_C02

In case of an amount field, use the reference field WAERS of reference table TCURC. In case of a

quantity field, use the reference field MSEHI of reference table T006.

Press on icon Activate to save and activate this structure.

Now you have defined the data structures which you will use to create an eCATT Test Data Container

for the inbound (source) data values and the expected (target) data values.

4.3 Create an eCATT Test Data Container

In this preparing step, you create an eCATT Test Data Container where you can store a set of inbound

data records of the transformation together with the corresponding target data records which you

expect after performing the ABAP unit test of transformation rules and routines.

Example: Create Test Data Container ZTDC_TEST_RSTRAN for transformation from DataStore

Object 0FIAR_O06 to InfoCube 0FIAR_C02

Open eCATT initial screen (transaction SECATT) and choose radio button Test Data. Enter the

technical name ZTDC_TEST_RSTRAN for this field and set field Version to 1. Then press on icon Create

Object.

On tab strip Attributes then tab strip General Data enter a title for the test data container and an

application component.

Page 12: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 8

Picture 6: Test Data Container ZTCD_TEST_RSTRAN - General Data

On tab strip Parameters insert two parameter lines which will contain the inbound (source) and

expected (target) data values.

For each parameter line, enter a Parameter (technical name), a Description, and a Parameter

Reference. The values for Parameter Reference are determined by the technical name of the

structures for the inbound (source) data values and the expected (target) data values which were

defined in the previous section 4.2.

Picture 7: Test Data Container – Parameters I_ODSO_0FIAR_O06 and E_CUBE_0FIAR_C02

Page 13: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 9

For inbound data of the transformation we use the Parameter Reference to the generated DDIC table

structure /BI0/AFIAR_O0600 of the DataStore Object. For expected data of the transformation we use

the manually created DDIC structure ZST_EXT_0FIAR_C02 representing a flattened data structure of

InfoCube 0FIAR_C02.

On tab strip Variants set radio button Internal Variants and insert new variant lines. Each variant will

contain the values for both the inbound (source) data and the expected (target) data.

For each variant line, enter a Variant (technical name) and a Description.

Picture 8: Test Data Container – Variants RECORD_1 and RECORD_2

Double-click on both columns I_ODSO_0FIAR_O06 and E_CUBE_0FIAR_C02 for each variant line to

get a details screen where you can enter values for parameters.

Page 14: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 10

Picture 9: Test Data Container - Parameter values of a variant RECORD_1

Note that each variant line contains both inbound (source) data values (parameter

I_ODSO_0FIAR_O06) and expected (target) data values (parameter E_CUBE_0FIAR_C02). So, you

have to fill both sets of values for each variant line.

Save the test data container.

Now you have created an eCATT Test Data Container for the inbound (source) data values and the

expected (target) data values. You have also stored there some test records for the ABP unit test of

the transformation.

4.4 Create a Wrapper Class for the Test Data

Container

In this step, you create a wrapper class for the test data container ZTDC_TEST_RSTRAN that was

built in the previous section. This wrapper class reads the data stored in the test data container to be

used as inbound and expected data values within the ABAP unit test of the transformation.

Open class builder (transaction SE24) and enter ZCL_TDC_VARIANT to field Object type. Then press

on button Create.

On the next pop-up enter the text Wrapper to access data of test data container to the

field Description and set the following flags. Then press Save.

Page 15: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 11

Picture 10: Class Builder – Properties

Open class builder (transaction SE24) and enter ZCL_TDC_VARIANT to field Object type. Then press

on button Change.

Press on button Source Code-Based and replace the existing ABAP source code by the text stored in

Appendix 5.1.

Adjust the ABAP source code to meet your use case according to Appendix 5.1.1.

Press on icon Activate to store and activate the class ZCL_TDC_VARIANT.

4.5 Create a Wrapper Class for Class

CL_RSTRAN_EXECUTE

The class CL_RSTRAN_EXECUTE (Direct Execution of Transformation) is part of software

component SAP_BW. As ABAP code of this software component cannot be changed in your system,

we create a wrapper ABAP class ZCL_RSTRAN_EXECUTE, which only calls the method RUN_TRAN

of class CL_RSTRAN_EXECUTE.

Open class builder (transaction SE24) and enter ZCL_RSTRAN_EXECUTE to field Object type. Then

press on icon Create.

On the next pop-up enter the text Wrapper of class CL_RSTRAN_EXECUTE to the field

Description and set the following flags. Then press Save.

Page 16: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 12

Picture 11: Class Builder – Properties

Press button Source Code-Based and replace the generated ABAP source code by the text stored in

Appendix 5.2.

Press on icon Activate to store and activate the class ZCL_RSTRAN_EXECUTE

Now you have created a wrapper class ZCL_RSTRAN_EXECUTE for the class which directly

executes any BW transformation. For this wrapper class we will now create a test class to perform an

ABAP unit test of a selected transformation.

4.6 Create Test Class for ABAP Unit Test

In the last step, you create the test class for the ABAP unit test corresponding to the class

ZCL_RSTRAN_EXECUTE which directly executes any BW transformation. Then you implement some

methods of this test class according to a selected transformation that you need to test. After this you

are able to perform the ABAP unit test for this transformation.

Open class builder (transaction SE24) and enter ZCL_RSTRAN_EXECUTE to field Object type. Then

press on button Change.

Choose Utilities the use function Test Classes Generate. The Test Class Generation Wizard

opens. Press button Continue.

Wizard step Class Selection: assure that the radio button Global Class is set and that the field

Global Class Name has the value ZCL_RSTRAN_EXECUTE. Press button Continue.

Wizard step Test Class Selection & Options: press on icon Create (located right beside the field

Test class name). On the next pop-up enter the value ZLCL_TEST_RSTRAN to the field Test

Class Name. Press Enter.

Wizard step Test Class Selection & Options: enter the Options displayed in Picture 12. Press

button Continue.

Page 17: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 13

Picture 12: Test Class Generation – Options

Wizard step Method Selection: select method RUN_TRAN. Press button Continue.

Wizard step Summary: press button Continue.

Wizard step Finish: press button Complete.

Replace the generated ABAP source code by the text stored in Appendix 5.3.

Adjust the ABAP source code to meet your use case according to Appendix 5.3.1.

Press on icon Activate to save and activate the new test class ZLCL_TEST_RSTRAN.

4.6.1 Program Logic of Test Class ZLCL_TEST_RSTRAN

See the comments in the ABAP source code of Appendix 5.2 to understand the functionality and

program flow in detail.

METHOD setup is called before the test of the transformation is started. It sets the parameter

transformation ID of the selected BW transformation and reads the inbound (source) data and

expected (target) data values from the test data container.

METHOD run_tran performs the ABAP unit test of the selected transformation. It calls the

method zcl_rstran_execute=>run_tran of class ZCL_RSTRAN_EXECUTE which

executes the selected BW transformation. Then it passes the outbound (target) data of the

transformation and the expected (target) data values from the test data container to the method

cl_abap_unit_assert=>assert_equals of the ABAP unit test framework. This method

compares the outbound data of transformation with the expected data from the test data container

and displays a detailed error message if there are any differences between them (on field level of

the corresponding structures).

4.7 Perform ABAP Unit Test for BW Transformation

Now everything is prepared for the ABAP unit test for a selected BW transformation.

Open class builder (transaction SE24) and enter ZCL_RSTRAN_EXECUTE to field Object type. Then

press on icon Display.

Choose Goto then use function Local Definitions/Implementations Local Test Classes.

Choose Local Test Classes then use function Execute Unit Tests to start the ABAP unit test for the

BW transformation.

Page 18: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 14

Picture 13: Result of ABAP Unit Test

The ABAP unit test result displays an error for the first set of compared records. The actual table (that

is the outbound data record of the BW transformation) shows value K3 for field FISCVARNT whereas

the expected table (that is the expected data record) shows value K4 for the same field.

Analysis of this test result:

The inbound data record (that is parameter I_ODSO_0FIAR_O06 of the test data container, see

Picture 9) contains value K4 for field FISCVARNT. The expectation for this field is the same value.

That means the ABAP unit test for the transformation expects a direct move of field FISCVARNT

from inbound to outbound data record.

The actual value of field FISCVARNT after execution of the BW transformation is K3 in contrast

which is approved by looking at the transformation rules in Picture 2: A constant value K3 is set

at the outbound side of the selected BW transformation.

So, the implemented BW transformation does not meet the expectation of the ABAP unit test. It needs

to be adjusted accordingly (direct move of field FISCVARNT instead of setting a constant value K3).

Page 19: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 15

5. Appendix – ABAP Class Coding

5.1 Coding of Wrapper Class ZCL_TDC_VARIANT

CLASS zcl_tdc_variant DEFINITION PUBLIC CREATE PRIVATE.

PUBLIC SECTION.

TYPES:

tab TYPE STANDARD TABLE OF REF TO zcl_tdc_variant WITH DEFAULT KEY.

CLASS-METHODS:

s_get_variants

RETURNING value(r_variants) TYPE zcl_tdc_variant=>tab

RAISING cx_ecatt_tdc_access.

METHODS:

get_i_odso_0fiar_o06

RETURNING value(r_i_odso_0fiar_o06) TYPE /bi0/afiar_o0600,

get_e_cube_0fiar_c02

RETURNING value(r_e_cube_0fiar_c02) TYPE zst_exp_0fiar_c02.

PRIVATE SECTION.

CLASS-DATA:

tdc TYPE REF TO cl_apl_ecatt_tdc_api.

METHODS:

init IMPORTING i_name TYPE csequence.

DATA:

name TYPE etvar_id.

ENDCLASS.

CLASS ZCL_TDC_VARIANT IMPLEMENTATION.

METHOD get_e_cube_0fiar_c02.

TRY.

tdc->get_value(

EXPORTING

i_param_name = 'E_CUBE_0FIAR_C02'

i_variant_name = me->name

CHANGING

e_param_value = r_e_cube_0fiar_c02 ).

CATCH cx_ecatt_tdc_access.

cl_aunit_assert=>fail(

msg = 'Error reading expected data of transform.: CUBE 0FIAR_C02'

Page 20: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 16

quit = 0 ).

ENDTRY.

ENDMETHOD. "get_ e_cube_0fiar_c02

METHOD get_i_odso_0fiar_o06.

TRY.

tdc->get_value(

EXPORTING

i_param_name = 'I_ODSO_0FIAR_O06'

i_variant_name = me->name

CHANGING

e_param_value = r_i_odso_0fiar_o06 ).

CATCH cx_ecatt_tdc_access.

cl_aunit_assert=>fail(

msg = 'Error reading Inbound data of transform.: ODSO 0FIAR_O06'

quit = 0 ).

ENDTRY.

ENDMETHOD. "get_i_dso_0fiar_o06

METHOD init.

name = i_name.

ENDMETHOD. "init

METHOD s_get_variants.

DATA: lt_variants TYPE etvar_name_tabtype,

lv_variant LIKE LINE OF lt_variants,

variant TYPE REF TO zcl_tdc_variant.

tdc = cl_apl_ecatt_tdc_api=>get_instance( 'ZTDC_TEST_RSTRAN' ).

lt_variants = tdc->get_variant_list( ).

LOOP AT lt_variants INTO lv_variant WHERE table_line <> 'ECATTDEFAULT'.

CREATE OBJECT variant.

variant->init( i_name = lv_variant ).

APPEND variant TO r_variants.

ENDLOOP.

ENDMETHOD. "s_get_variants

ENDCLASS.

5.1.1 Adjustments to Coding of Wrapper Class

ZCL_TDC_VARIANT

Adjustments in CLASS zcl_tdc_variant DEFINITION

The method definitions have to be adjusted according to your inbound (source) data and expected (target) data structures.

Replace:

(1) the name of the get_... methods by your own method names,

(2) the RETURNING value parameters by your own returning parameter names,

(3) the TYPE assignments by your own inbound and expected data structures.

Page 21: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 17

Adjustments in CLASS ZCL_TDC_VARIANT IMPLEMENTATION

Each get_... method implementation has to be adjusted according to your adjustments in the class definition part and also according to your inbound (source) data and expected (target) data structures.

Replace:

(1) the name of the get_... methods by your own method names given in the class definition

part,

(2) the exporting parameter i_param_name of method tdc->get_value by the

corresponding inbounding (source) or expected (target) data parameters of your test data

container defined in section 4.3,

(3) the changing parameter e_param_value of method tdc->get_value by the

corresponding RETURNING value parameters given for the get_... methods in the class

definition part ,

(4) the message text in the CATCH statement by your own data source and target of your

tested transformation.

5.2 Coding of Wrapper Class ZCL_RSTRAN_EXECUTE

CLASS zcl_rstran_execute DEFINITION

PUBLIC

FINAL

CREATE PUBLIC .

PUBLIC SECTION.

CLASS-METHODS run_tran

IMPORTING

i_tranid TYPE rstranid

i_t_data TYPE ANY TABLE

EXPORTING

e_t_data TYPE ANY TABLE.

ENDCLASS.

CLASS ZCL_RSTRAN_EXECUTE IMPLEMENTATION.

METHOD run_tran.

CLEAR e_t_data.

CALL METHOD cl_rstran_execute=>run_tran

EXPORTING

i_tranid = i_tranid

i_t_data = i_t_data

IMPORTING

e_t_data = e_t_data.

ENDMETHOD. "run_tran

Page 22: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 18

ENDCLASS.

5.3 Coding of Test Class ZLCL_TEST_RSTRAN

*----------------------------------------------------------------------*

* CLASS zlcl_Test_Rstran DEFINITION

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

CLASS zlcl_test_rstran DEFINITION FOR TESTING

DURATION SHORT

RISK LEVEL HARMLESS.

PRIVATE SECTION.

DATA: ld_tranid TYPE rstranid,

* Inbound data of transformation

ls_data TYPE /bi0/afiar_o0600,

lt_data LIKE TABLE OF ls_data,

* Expected data after transformation

ls_exp_data TYPE zst_exp_0fiar_c02,

lt_exp_data LIKE TABLE OF ls_exp_data.

METHODS: setup,

run_tran FOR TESTING.

ENDCLASS. "zlcl_Test_Rstran

*----------------------------------------------------------------------*

* CLASS zlcl_Test_Rstran IMPLEMENTATION

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

CLASS zlcl_test_rstran IMPLEMENTATION.

METHOD setup.

DATA: variants TYPE zcl_tdc_variant=>tab,

variant TYPE REF TO zcl_tdc_variant.

* Set the ID of the transformation to be tested.

ld_tranid = '0ON484YZMTWZJJZKKQ6A8S4REX6ROF0F'.

* Get variants of Test Data Container ZTDC_TEST_RSTRAN

variants = zcl_tdc_variant=>s_get_variants( ).

REFRESH: lt_data, lt_exp_data.

* Loop variants and read test data from container

LOOP AT variants INTO variant.

Page 23: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 19

CLEAR: ls_data, ls_exp_data.

* Fill inbound data of transformation

ls_data = variant->get_i_odso_0fiar_o06( ).

APPEND ls_data TO lt_data.

* Fill expected data of transformation

ls_exp_data = variant->get_e_cube_0fiar_c02( ).

APPEND ls_exp_data TO lt_exp_data.

ENDLOOP.

ENDMETHOD. "setup

METHOD run_tran.

TYPES:

* Inbound data of transformation:

* copy TYPE _ty_s_SC_1 of generated program here

BEGIN OF ty_i_data,

* InfoObject: 0DEBITOR Customer Number.

debitor TYPE /bi0/oidebitor,

* InfoObject: 0COMP_CODE Company code.

comp_code TYPE /bi0/oicomp_code,

* InfoObject: 0FISCPER Fiscal year / period.

fiscper TYPE /bi0/oifiscper,

* InfoObject: 0FISCVARNT Fiscal year variant.

fiscvarnt TYPE /bi0/oifiscvarnt,

* InfoObject: 0DEBIT Total Debit Postings.

debit TYPE /bi0/oidebit,

* InfoObject: 0CREDIT Total credit postings.

credit TYPE /bi0/oicredit,

* InfoObject: 0BALANCE Cumulative Balance.

balance TYPE /bi0/oibalance,

* InfoObject: 0SALES Sales for the Period.

sales TYPE /bi0/oisales,

* InfoObject: 0CURRENCY Currency Key.

currency TYPE /bi0/oicurrency,

* InfoObject: 0CURTYPE Currency Type.

curtype TYPE /bi0/oicurtype,

* Field: RECORD Data record number.

record TYPE rsarecord,

END OF ty_i_data.

TYPES:

* Outbound data of transformation:

* copy TYPE _ty_s_TG_1 of generated program here

BEGIN OF ty_e_data,

* InfoObject: 0CHNGID Change run ID.

chngid TYPE /bi0/oichngid,

* InfoObject: 0RECORDTP Record type.

recordtp TYPE /bi0/oirecordtp,

* InfoObject: 0REQUID Request ID.

requid TYPE /bi0/oirequid,

Page 24: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 20

* InfoObject: 0FISCPER Fiscal year / period.

fiscper TYPE /bi0/oifiscper,

* InfoObject: 0FISCVARNT Fiscal year variant.

fiscvarnt TYPE /bi0/oifiscvarnt,

* InfoObject: 0FISCYEAR Fiscal year.

fiscyear TYPE /bi0/oifiscyear,

* InfoObject: 0FISCPER3 Posting period.

fiscper3 TYPE /bi0/oifiscper3,

* InfoObject: 0CURRENCY Currency Key.

currency TYPE /bi0/oicurrency,

* InfoObject: 0DEBITOR Customer Number.

debitor TYPE /bi0/oidebitor,

* InfoObject: 0COMP_CODE Company code.

comp_code TYPE /bi0/oicomp_code,

* InfoObject: 0CURTYPE Currency Type.

curtype TYPE /bi0/oicurtype,

* InfoObject: 0SALES Sales for the Period.

sales TYPE /bi0/oisales,

* InfoObject: 0DEBIT Total Debit Postings.

debit TYPE /bi0/oidebit,

* InfoObject: 0BALANCE Cumulative Balance.

balance TYPE /bi0/oibalance,

* InfoObject: 0CREDIT Total credit postings.

credit TYPE /bi0/oicredit,

* Field: RECORD Data record number.

record TYPE rsarecord,

END OF ty_e_data.

DATA:

* Inbound data of transformation

ls_i_data TYPE ty_i_data,

lt_i_data TYPE TABLE OF ty_i_data,

* Outbound data of transformation

ls_e_data TYPE ty_e_data,

lt_e_data TYPE TABLE OF ty_e_data,

* Outbound data of transformation with same structure as expected data

ls_out_data LIKE ls_exp_data,

lt_out_data LIKE TABLE OF ls_exp_data.

DATA: l_lines TYPE i.

* Transfer inbound data of transformation to structure of

* generated program

LOOP AT lt_data INTO ls_data.

MOVE-CORRESPONDING ls_data TO ls_i_data.

APPEND ls_i_data TO lt_i_data.

ENDLOOP.

* Perform transformation code

zcl_rstran_execute=>run_tran(

EXPORTING

i_tranid = ld_tranid

Page 25: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 21

i_t_data = lt_i_data

IMPORTING

e_t_data = lt_e_data ).

* Check if outbound data of transformation is filled

DESCRIBE TABLE lt_e_data LINES l_lines.

IF l_lines IS INITIAL.

FORMAT COLOR = col_negative INVERSE ON.

WRITE: /,/ 'Error message from ABAP unit test of transformation:',

/,

/ 'Outbound data of transformation is empty.',/,

/ 'Check, if type definitions of inbound and outbound data',

/ 'in method RUN_TRAN of your local test class is exactly',

/ 'the same as in the generated program of the tested',

/ 'BW transformation.'.

EXIT.

ENDIF.

* Transfer outbound data of transformation to structure of

* expected data (without technical fields)

LOOP AT lt_e_data INTO ls_e_data.

MOVE-CORRESPONDING ls_e_data TO ls_out_data.

APPEND ls_out_data TO lt_out_data.

ENDLOOP.

* Compare outbound data of transformation with expected data

cl_abap_unit_assert=>assert_equals(

act = lt_out_data

exp = lt_exp_data

msg = 'Testing value lt_exp_data'

* level =

).

ENDMETHOD. "parameterized_test

ENDCLASS. "zlcl_Test_Rstran

5.3.1 Adjustments to Coding of Test Class

ZLCL_TEST_RSTRAN

Adjustments in CLASS zlcl_test_rstran DEFINITION

The DATA definitions have to be adjusted according to your inbound (source) data and expected (target) data structures.

Replace the TYPE assignments by your own inbound and expected data structures.

Adjustments in CLASS zlcl_test_rstran IMPLEMENTATION

Adjustments in METHOD setup

Replace

Page 26: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

How To... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

March 2012 22

(1) the transformation ID (statement ld_tranid = '…') by the transformation ID of your

BW transformation to be tested. You determine this transformation ID in section 4.1,

(2) the name of the get_... methods by your own method names given in the class definition part

of the ABAP class CLASS ZCL_TDC_VARIANT (see section 5.1)

Adjustments in METHOD run_tran

Replace

(1) the type definition of ty_i_data (inbound data of transformation) by the type definition

_ty_s_SC_1 of the generated program,

(2) the type definition of ty_e_data (outbound data of transformation) by the type definition

_ty_s_TG_1 of the generated program.

You determine the type definitions _ty_s_SC_1 and _ty_s_TG_1 of the generated program

of the transformation in section 4.1.

Page 27: How to... Perform ABAP Unit Tests for Transformations in SAP NetWeaver BW

www.sdn.sap.com/irj/sdn/howtoguides