How to SELECT in SAP BW transformations.pdf

11
SAP How-to Guide Business Analytics Applicable Releases: SAP BW 7.0* and later releases Version 1.0 April 2012 How to SELECT in SAP BW transformations

Transcript of How to SELECT in SAP BW transformations.pdf

  • SAP How-to Guide Business Analytics

    Applicable Releases:

    SAP BW 7.0* and later releases

    Version 1.0

    April 2012

    How to SELECT in SAP BW transformations

  • Copyright 2013 SAP AG. All rights reserved. No part of this p ubli cati on may be repro du ced or transmi tte d in a ny f orm or for any purp ose wi th out th e expres s permissio n of SAP AG. Th e inf ormatio n co nt aine d herei n may b e ch ang ed wi th out pr ior no tice. Some sof tware pro duc ts marke ted by SAP AG and i ts dis tr ibu tors co nt ain pr opriet ary sof tware c ompo ne nts of o th er soft ware ve ndors. Microso ft, Wi nd ows, Ex cel, Ou tlo ok, a nd Pow erPoint are regist ered tra demarks of Mi croso ft Corp orati on.

    IBM, DB2, DB2 U niversal Da tab ase, Sys tem i, Syst em i5, Syst em p, Syst em p5, Sys tem x, Sys tem z, Syst em z10, System z9, z10, z 9, iSer ies, pSeries, xSeries , zSeries, eServer, z/VM , z/OS, i5 /OS, S/390, OS/ 390, OS/ 400, AS/400, S/390 Parallel E nter prise S erver, PowerVM, Power Archit ect ure, POWER6+, POWER6 , POWER5+, POWER5, POWER, O penPow er, PowerPC, Batc hPipes, Bla deCe nter, Sys tem Stora ge, GPFS, HACMP, RE TAIN, DB2 Co nne ct, RACF, Re db ooks, OS/ 2, Parallel Sys plex, MVS/ESA, AIX,

    Intelli gen t Miner, We bSphere, N et fini ty, Ti voli a nd I nformix are trademarks or registere d tra demarks o f IBM Cor porati on.

    Linux is th e regist ered trademark o f Li nus Torval ds in t he U.S. a nd o th er cou ntr ies.

    Adobe , th e Ado be lo go, Acro ba t, PostScrip t, a nd Rea der are ei ther tra demarks or registere d tra demarks o f Ado be Syst ems Inc orpora ted i n t he Uni te d Sta tes a nd/ or ot her co untr ie s. Oracle is a regis tered trademark of Oracl e Corpora tio n.

    UNIX, X/Open, OS F/1, an d M oti f are regis tered tradem arks of the O pe n Grou p.

    Citr ix, ICA, Program Neigh borho od, Me taFrame , WinFrame, Vid eoFrame , an d M ultiWin are trad emarks or regis tered trademarks of Ci tr ix Systems, I nc.

    HTM L, XML, XH TM L an d W3C are trademarks or registere d tra demarks o f W3C, World Wi de Web C ons ortium, Massa chu set ts In sti tu te o f Te chn olo gy.

    Java is a regis tere d trad emark of Su n Mi crosys tems, In c. JavaScript is a regist ered trademark o f Sun Microsy stems, Inc., use d un der lice nse f or tec hn olog y inve nte d a nd impl emen ted by Ne tsca pe.

    SAP, R/3, SAP NetWeaver, Due t, Partner Edg e, ByDesig n, SAP BusinessO bjec ts E xpl orer, StreamWork, an d o ther SAP produ cts a nd s ervices men tio ne d herei n as well a s th eir respec tive lo gos are trad emarks or regis tered trademarks of SAP AG in Germany a nd o th er cou ntr ies.

    Business Objects and the Business Objects logo, BusinessObjects,

    Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other

    Business Objects products and services mentioned herein as well as their

    respective logos are trademarks or registered trademarks of Business

    Objects Software Ltd. Business Objects is an SAP company. Sybase a nd Ad ap tive Server, iAnyw here, Syb ase 3 65, SQL A nywh ere, an d o ther Syb ase pro du cts a nd s ervices men tio ne d herein as well as th eir respec tive lo gos are trad emarks or regist ered trademarks of Syb ase, I nc. Syb ase is a n SAP company .

    All other pro du ct a nd s ervice nam es men tion ed are the trad emarks of their res pec tive c ompa nies. Da ta c ont aine d in this doc umen t serves i nforma tion al p urpose s onl y. Nati on al pro duc t spe cific atio ns may v ary. The i nforma tion i n t his d ocume nt is proprie tary t o SAP. No part of t his d ocum ent ma y be re prod uce d, co pied , or transmi tt ed in any form or for an y pur pose wi th ou t t he ex press pr ior writ ten permissio n of SAP AG.

    This doc umen t is a prelimin ary version an d no t su bjec t t o yo ur license agreeme nt or any o th er agreeme nt wi th SAP. This doc umen t co nt ains o nly in te nde d stra te gies, d evel opmen ts, a nd fu ncti onali ties of t he SAP produ ct a nd is no t in ten ded to be bi ndi ng u po n SAP to an y parti cular c ourse o f b usines s, pro duc t stra teg y, an d/ or devel opme nt. Plea se n ote th at this d ocum en t is su bjec t to cha nge a nd ma y be c ha nge d by SAP at a ny tim e wit hou t n otic e.

    SAP assumes no resp onsi bilit y for errors or omissio ns in this doc umen t. SAP does not w arrant the accura cy or com plet ene ss of th e inf ormatio n, t ext, graphi cs, link s, or o ther it ems co ntai ned withi n t his mat er ial. T his d ocume nt is provid ed wi th out a warran ty of any ki nd, eit her express or implied , incl udin g b ut n ot limi ted to the im plied w arranti es of merc han ta bil ity, fit ness for a par ticul ar purp ose, or n on -in fr ingeme nt.

    SAP shall have n o liabili ty f or dama ges o f an y kin d incl udi ng wit ho ut limit ati on direct, s peci al, in direct, or cons eq uen tial d amage s th at may res ult from th e use of thes e material s. T his limita tio n shall no t ap ply in c ases of in te nt or gro ss ne glige nce.

    The s ta tu tory lia bility for perso nal i njury an d d efec tive prod uct s is no t af fec te d. SAP has no con trol ov er the i nf ormatio n t hat y ou ma y acce ss t hroug h t he us e of ho t links con tai ned i n t hese ma terials a nd does no t en dorse y our us e of third -p arty Web pag es n or provid e any w arranty wha tso ever relati ng t o t hird- party W eb p ages .

    SAP How-to Guides are intended to simplify the product implement-

    tation. 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

    SAPs Support Services and may not be modified or altered in any way.

  • Document History

    Document Version Description

    1.10 Second Review

    1.00 First draft of this guide

    2.00 Official Release

  • 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.

    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

  • How to SELECT in SAP BW transformations

    March 2013 1

    Table of Contents

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

    2. Step by Step Solution ...................................................................................................... 3

    3. Conclusions / Recommendations ................................................................................... 5

    4. Appendix ......................................................................................................................... 6

  • How to SELECT in SAP BW transformations

    March 2013 2

    1. Business Scenario For complex data staging scenarios within SAP BW it is usually necessary to manipulate data, this

    can be done at several points during loading:

    Start routine

    Expert routine

    End routine

    The following scenario is about manipulation and transformation of data during staging through the

    data warehouse. Scenario:

    (1) You need to do a lookup on custom Z-table and populate a field in this case ZCOUNTRY in

    the data target (InfoCube) within transformation from DataStore Object to InfoCube.

    In order to accomplish the above task it has been determined to use End Routine for the

    Enhancement. As best practice it is well known and recommendable to use internal tables rather

    than SELECT SINGLE statement in performance point of view. As mentioned on SAP NetWeaver

    BW powered by SAP HANA this best practices remains valid, therefore the data selection via the

    internal table will be showed.

    For demonstration purposes data will be loaded from a DataStore Object to an InfoCube. In the

    transformation for field 0SOLD_TO a lookup for country in the customer Z-Table will be done.

    This transformation will be enhanced via end routines by performing the following actions:

    (1) Get the country from Z-Table for each 0SOLD_TO and populate field ZCOUNTRY in the

    Data Target (InfoCube)

    A SAP BW system powered by HANA at current state doesnt change much on the ABAP Application Layer, a lot of well-known performance optimizations in this area are remaining valid.

    Therefore the present How to guide shows an efficient way to use SELECT statements in

    transformation in SAP NetWeaver BW powered by SAP HANA as well as with SAP BW on other

    databases.

  • How to SELECT in SAP BW transformations

    March 2013 3

    2. Step by Step Solution

    (1) Create Transformation from DataStore Object to InfoCube.

    (2) Create End Routine as follows.

    Add Global Declaration. Refer to appendix for the ABAP Code.

  • How to SELECT in SAP BW transformations

    March 2013 4

    Remarks on the shown example:

    - If it is useful to read a table according to our example ZCUSTLOC in the end routine is

    depending on the amount of records. Considering tables, in our example ZCUSTLOC, with a

    lot of entries it is recommendable to read only the relevant Data Packages and to buffer this

    table (usage of FOR ALL ENTRIES IN ). See also Note 1662726 - Optimizing select with FOR ALL ENTRIES in SAP HANA database

    - In scenarios where a lookup of data of BW InfoObjects is executed it is recommendable to

    use the standard rule type reading master data because this is already optimized for data selects without the need to use ABAP coding. This is also possible for Navigation Attributes

    and DataStore objects since BW 7.30 (see below).

    - The mentioned best practices are also valid for scenarios where 3.x data flow logic is used

    as well as for new HANA optimized objects like shown.

    - New standard look-up features with SAP BW 7.30:

    Beside the possibility to the do master data look up via a routine or rule (reading master

    data) it is also possible switch on the navigation attribute in the source object to make this

    attribute visible as a source field in the transformation. Hence it is available as field for

    staging, which makes it not necessary to read to master data separately:

    Afterwards the navigation attribute become available in the transformation and can be used:

    - There is also a new look-up feature available for lock ups in DataStore Object. - These standard functionalities are fully optimized, easy to use and therefore highly

    recommended to use.

  • How to SELECT in SAP BW transformations

    March 2013 5

    3. Conclusions / Recommendations

    There is significant improvement in End Routine Processing times when using Read Table rather than Select Single with-in Loop Statement. Select Single should be avoided with in a loop where-ever possible.

    Valid for SAP NetWeaver BW powered by SAP HANA:

    (1) Due to the architecture of SAP HANA database recommendation and best practices of

    good ABAP coding are valid and still important.

    (2) During different loading cycles it has been observed that larger DTP - Data Package size of

    100,000 - 150,000 records showed a significant performance gain than smaller

    DataPackages.

    (3) Secondary indexes on customer Z-Tables might not be required, as data is already stored

    in column store with in HANA. DataStore Object Secondary indexes arent required on SAP HANA anymore. However for some use cases secondary indexes can still be beneficial. This

    is especially true for highly selective queries on non-primary key fields. These queries can

    be significantly improved by indexes on single fields which are most selective. (Note

    1740373 - DSO: Maintenance of database indexes in SAP HANA.)

    All best practices of the following SAP Notes should be considered for SAP HANA as well:

    - Note 1227667 - Guidelines for expert routine: Design rules - Note 1258089 - Design rule: Adding records to the start routine - Note 1223532 - Design rules: Adding records to end routine

  • How to SELECT in SAP BW transformations

    March 2013 6

    4. Appendix

    DATA: BEGIN OF I_S_CUSTOMER,

    /BIC/S_CUSTOMER TYPE ZCUSTLOC-/BIC/S_CUSTOMER,

    /BIC/S_COUNTRY TYPE ZCUSTLOC-/BIC/S_COUNTRY,

    END OF I_S_CUSTOMER.

    DATA: i_t_customer like HASHED table of I_S_CUSTOMER with uniq

    ue key

    /BIC/S_CUSTOMER.

    select /BIC/S_CUSTOMER /BIC/S_COUNTRY from zcustloc

    into corresponding fields of table i_t_customer.

    if sy-subrc = 4.

    RAISE EXCEPTION TYPE CX_RSROUT_ABORT.

    endif.

    sort i_t_customer by /BIC/S_CUSTOMER.

    loop at RESULT_PACKAGE ASSIGNING .

    read table i_t_customer into I_S_CUSTOMER with key

    /BIC/S_CUSTOMER = -/BIC/S_SOLD_TO.

    if sy-subrc eq 0.

    -/BIC/S_COUNTRY = I_S_CUSTOMER-

    /BIC/S_COUNTRY.

    endif.

    endloop.

  • www.sap.com/contactsap

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