Professional Documents
Culture Documents
PDEBWB
o n l y
F o r
i n t e r n a l
C S C
b y
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
Preface-1
Copyright
Copyright 2004 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. All rights reserved.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
Trademarks: Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, WINDOWS, NT, EXCEL, Word, PowerPoint and SQL Server 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 and Informix Dynamic ServerTM are trademarks of IBM Corporation in USA 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, the Citrix logo, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, MultiWin and other Citrix product names referenced herein are trademarks of Citrix Systems, Inc. HTML, DHTML, XML, XHTML 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. MarketSet and Enterprise Buyer are jointly owned trademarks of SAP AG and Commerce One. SAP, SAP Logo, R/2, R/3, mySAP, mySAP.com, 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.
C S C
o n l y
F o r
SAP AG
PDEBWB
Preface-2
Prerequisites
Essential:
Advanced Business Warehouse knowledge Basic knowledge in ABAP Programming
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
Preface-3
Target Audience
Participants
Business Warehouse Consultants and Developer
Duration: 2 days
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
User notes These training materials are not a teach-yourself program. They complement the explanations provided by your course instructor. Space is provided on each page for you to note down additional information. There may not be sufficient time during the course to complete all the exercises. The exercises provide additional examples that are covered during the course. You can also work through these examples in your own time to increase your understanding of the topics.
C S C
o n l y
F o r
SAP AG
PDEBWB
Preface-4
Course Overview
Contents:
Course Goals Course Objectives Course Content Course Overview Diagram
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
Preface-5
Course Goals
This course will prepare you to: Highlight the main features of ABAP needed in a BW environment Get to know how to influence the BW backend process by programming SAP enhancements and BAdIs.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
Preface-6
Course Objectives
After completing this course, you will be able to: Adapt BW backend processes by programming SAP enhancements (Exits) and BAdIs in the following areas: Data Extraction Data Staging Reporting In process chains
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
Preface-7
Course Content
Preface Unit 1 Unit 2 Unit 3 Unit 4 Course Overview ABAP Basics Data Extraction Data Staging Unit 7 Unit 8 Appendices Unit 5 Unit 6 BEx-Variables Virtual Key Figures and Characteristics Report-Report Interface ABAP in Process Chains
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
Preface-8
3 5 BEx-Variables Reporting
InfoCubes / ODS & Master Data
2 ABAP Basics
InfoSource
o n l y
SAP BW Server
1 3 Data Extraction Extraction
F o r
i n t e r n a l
C S C
DB DB
R/3 R/3
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
Preface-9
ABAP Basics
Contents:
Internal Tables Field Symbols Subroutines Data Retrieval Enhancements
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
1-1
After completing this unit, you will be able to: Work with internal tables Use field symbols Work with subroutines Select data from the database Explain the different enhancement techniques
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
1-2
2 ABAP Basics
InfoSource
o n l y
SAP BW Server
1 3 Data Extraction Extraction
F o r
i n t e r n a l
C S C
DB DB
R/3 R/3
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
1-3
Data Retrieval
F o r
o n l y
Enhancements
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
1-4
Line type Key definition Components Sequence Unique / non-unique key non-
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The data type of an internal table is completely specified by the following attributes: Line type This is the source of the attributes of the individual columns. You normally specify a structure type but any data types are possible. Key definition The key columns and their order define the criteria by which the tables are identified. Depending on the access type, the key can be defined as unique or non-unique. With unique keys there are no multiple entries with identical values in the key. Data access type With a key access as with database tables you access using the field contents. Example: A read access using the search term 'UA 0007' to an internal table with the unique key CARRID CONNID and the data pictured above returns exactly one data record. Index access: Unlike database tables, with internal tables the system may number the lines and give the line an index. You can use this idex to access a specific table line. Example: A read access to a data record with index 5 returns the fifth data record of the internal table
C S C
o n l y
F o r
SAP AG
PDEBWB
1-5
Hashed table
STANDARD TABLE
SORTED TABLE
HASHED TABLE
Key access
o n l y
F o r
UNIQUE | NON-UNIQUE
UNIQUE
i n t e r n a l
C S C
Mainly keys
Keys only
b y
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
Another internal table attribute is the table type. Internal tables can be divided into three table types according to the respective access types:
C S C
With standard tables the line numbering is maintained internally. Both index and key accesses are
possible.
With sorted tables the data records are always sorted according to key and saved. Here too, the index
is maintained internally. Both index and key accesses are possible.
o n l y
F o r
With hashed tables the data records are managed optimized at run time. A unique key is a
requirement. With hashed tables only key accesses are possible. Which table type you use in each case, depends on how that table's entries are generally going to be accessed:
For index accesses you should normally use standard tables. Sorted tables are best for unique keys and fixed sorting. With hashed tables the runtime optimization is noticeable only if the accesses are of the read type
with a unique key. This course deals with standard tables only. Apart from a few special cases, the syntax is identical for all three table types.
SAP AG
PDEBWB
1-6
F o r
o n l y
seatsmax
seatsocc
percentage
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
Table types can be defined locally in a program or globally in the ABAP Dictionary. For DATA itab_name TYPE itab_type you can use local or global types itab_type. For detailed information on the definition of global table types in the ABAP Dictionary, refer to the SAP Library under Basis ABAP Workbench BC-ABAP Dictionary Types Table types.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-7
seatsmax
seatsocc
percentage
C S C
* fill structure with values: wa_flightinfo-carrid = ... wa_flightinfo-connid = ... wa_flightinfo-fldate = ... wa_flightinfo-seatsmax = ... wa_flightinfo-seatsocc = ... wa_flightinfo-percentage = ...
. . . . . .
F o r
o n l y
i n t e r n a l
* insert structure into internal table: INSERT wa_flightinfo INTO TABLE itab_flightinfo.
SAP AG 2003
u s e
b y
u s e
i n t e r n a l
b y
You can also define internal table types locally using the TYPE statement. The table type is specified between TYPE and TABLE OF. The line type comes after TABLE OF. The key fields are listed after the WITH addition. Note that the order of the key fields plays a part here. For detailed information about defining local table types, refer to the keyword documentation on TYPES. You define the data object itself in the usual way. For compatibility reasons, you can also directly define an internal table as follows: DATA itab_name TYPE table_kind TABLE OF struc_type WITH key_def.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-8
sign(1) TYPE c
b y
C S C
option(2) TYPE c
APPEND wa_carrid TO rg_carrid. : : : * Use selection table SELECT WHERE carrid IN rg_carrid.
F o r
o n l y
i n t e r n a l
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
Use the SELECT-OPTION statement to create an internal table with a header, for which the runtime system automatically creates an input dialog for value sets for a selection screen. The system automatically inserts the appropriate entries in the internal table, from the user input. For more details, refer to the keyword documentation for the SELECT-OPTIONS statement. As of SAP R/3 Basis Release 4.6A onwards, you can use the RANGE OF addition to the TYPES and DATA statements to define a corresponding (internal) table without a header line.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-9
STANDARD
SORTED
HASHED
READ TABLE itab INTO wa WITH KEY key. WITH KEY STANDARD key
Complete/part key left-aligned without gaps leftBy qualified key Any component condition
SAP AG 2003
Table kind
SORTED
Binary search
HASHED
F o r
o n l y
Table scan
u s e
b y
C S C
Table scan
Table scan
i n t e r n a l
u s e
i n t e r n a l
b y
Whenever you want to read individual table lines by declaring a complete key, use the READ TABLE ... WITH TABLE KEY statement (fastest single record access by key). The runtime system supports this syntax variant especially for SORTED and HASHED tables. If the table is a STANDARD table, the runtime system performs a table scan. The same applies if you have copied the values from all key fields of the entry to be read into the work area wa and are then use READ TABLE itab FROM wa. The runtime system carries out the syntax variant READ TABLE ... WITH KEY (read an entry after applying any condition) using a table scan. The only exception to this rule applies to SORTED tables, if you fill the first n key fields with "=" (no gaps), where n <= number of key fields. With standard tables however, you can also sort correspondingly using SORT and then use the BINARY SEARCH addition. Summary: Whenever possible, use READ TABLE ... WITH TABLE KEY or the variant with a correspondinglyfilled work area. If you need to use READ TABLE ... WITH KEY, make your internal table a SORTED table.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-10
Hash Table
<adr_400_CO> <adr_400_LH>
mandtcarrid carrname
4 0 0 CO 4 0 0 LH 4 0 0 AF 4 0 0 BL 4 0 0 BA 4 0 0 DL 4 0 0 AA 4 0 0 FC 4 0 0 AZ 4 0 0 AC Lufthansa Air France Pacific Airlines British Airways Delta Airlines American Airlines Berliner Spez. Flug Alitalia Air Canada
currcode
DEM FF USD GBP USD USD DEM ITL CAD
Hash Function
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
Whenever you want to read individual table lines by declaring a complete key, use the READ TABLE ... WITH TABLE KEY statement (fastest single record access by key). The runtime system supports this syntax variant especially for SORTED and HASHED tables. If the table is a STANDARD table, the runtime system performs a table scan. The same applies if you have copied the values from all key fields of the entry to be read into the work area wa and are then use READ TABLE itab FROM wa. The runtime system carries out the syntax variant READ TABLE ... WITH KEY (read an entry after applying any condition) using a table scan. The only exception to this rule applies to SORTED tables, if you fill the first n key fields with "=" (no gaps), where n <= number of key fields. With standard tables however, you can also sort correspondingly using SORT and then use the BINARY SEARCH addition. Summary: Whenever possible, use READ TABLE ... WITH TABLE KEY or the variant with a correspondinglyfilled work area. If you need to use READ TABLE ... WITH KEY, make your internal table a SORTED table.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-11
Table kind
SORTED
HASHED
Table scan
Table scan
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The runtime system generally processes loops with a WHERE clause by performing a table scan - that is, determining whether the condition in the WHERE clause is true for each line in the table. SORTED tables are the only exception to this rule. For these, the runtime system optimizes the runtime under the following condition: In the WHERE clause, the first n key fields are filled with a "=" (no gaps). (n is less than or equal to the number of all key fields). As a result, the loop is only performed on the lines that match the condition in the WHERE clause. Since the table is sorted, the first line can be specified to optimize performance at runtime (using a binary search).
C S C
o n l y
F o r
SAP AG
PDEBWB
1-12
Data Retrieval
F o r
o n l y
Enhancements
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
1-13
<fs> var_a
<fs> var_a
o n l y
F o r
<fs> var_a
<fs> = 77. 77
i n t e r n a l
C S C
Time
SAP AG 2003
u s e
b y
u s e
i n t e r n a l
b y
You can create a pointer to a data object in ABAP using a field symbol. First, declare a data object using the FIELD-SYMBOLS statement. This data object can contain a pointer to another data object at runtime. Where possible, you should give the field symbol the same type as the data object (TYPE i, in this example). Note that the angle brackets (<>) are part of the name of the field symbol: In this example, the name is <fs>. To point a field symbol at a data object, you must assign it to the object data_object using the ASSIGN data_object TO <fs> statement. You can use the field symbol to access the content of the data object to which it points - either to read or to change this content. You can "redirect" a field symbol to a different data object at runtime using the ASSIGN statement. In order to get access to single fields of a structure by a field symbol you can use the following statement: ASSIGN COMPONENT comp-no OF STRUCTURE struct TO <fs>.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-14
<fs> it_sflight
F o r
o n l y
<fs> it_sflight
b y
C S C
i n t e r n a l
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
In the above example, a field symbol is assigned the line type of an internal table. This makes it possible to assign a table line to this field symbol. The syntax required for this is discussed later in this unit. After a field symbol has been assigned a line, it is also possible to access the individual column values of the assigned line. As well as being able to read the data contents, you can also change the contents of the individual components.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-15
READ TABLE itab ASSIGNING <fs1> WITH TABLE KEY ... . READ TABLE <fs1>-col3 ASSIGNING <fs2> WITH TABLE KEY ... .
<fs2>
READ TABLE itab INTO wa1 WITH TABLE KEY ... . READ TABLE wa1-col3 INTO wa2 WITH TABLE KEY ... .
wa2 wa1 Copy
<fs1> Copy
F o r
o n l y
i n t e r n a l
C S C
b y
col1
col2
col3
col4
itab
col1
col2
col3
col4
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
Instead of READ TABLE ... INTO, you can use the READ TABLE ... ASSIGNING variant. This offers better performance at runtime for pure read accesses with a line width greater than or equal to 1000 bytes. If you then change the read line using MODIFY, READ ... ASSIGNING already improves runtime with a line width of 100 bytes. The same applies to LOOP ... INTO in comparison with LOOP ... ASSIGNING. The LOOP ... ASSIGNING variant offers better performance at runtime for any loop of five loop passes or more. Both field symbol variants are much faster than work area variants, in particular when you use nested internal tables. This is because, if you use work areas instead, the whole inner internal table is copied (unless you prevent this by using a TRANSPORTING addition). Always assign a type to field symbols, if you know their static type (again, for performance reasons). Note: If you use READ TABLE ... ASSIGNING the field symbol points to the originally assigned table line, even after the internal table has been sorted. Note that when using field symbols, you cannot change key fields in SORTED or HASHED tables. Trying to do so causes a runtime error. The following restrictions apply to LOOP ... ASSIGNING <fs>: You cannot use the SUM statement in control level processing. You cannot reassign field symbols within the loop. The statements ASSIGN do TO <fs> and UNASSIGN <fs> will cause runtime errors.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-16
Data Retrieval
F o r
o n l y
Enhancements
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
1-17
PERFORM ...
PERFORM ...
Inquiries 1000
Bookings 555
F o r
o n l y
FORM ...
i n t e r n a l
C S C
Subroutine
b y
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
A subroutine is an internal module within a program. In a subroutine, you lift parts of a program out of the main programming block and put them somewhere else. This makes your program easier to read and allows you to use these code segments more than once. You can pass data to the subroutine and back through its interface. This allows you to call the same function for different data objects. The example in the graphic shows a subroutine that calculates a percentage. This subroutine is called several times, even though different data objects are passed to the interface in each case. Using subroutines makes your program more function oriented: it splits the program's task into subfunctions so that each subroutine is responsible for one subfunction. This generally makes programs easier to maintain. In the Debugger, you can execute the subroutines in background so that you see only the result. This usually makes it easier to find the source of the error. The structure of a subroutine includes the following: Each subroutine starts with FORM and ends with ENDFORM. The name of the subroutine is followed by the interface definition. The statements that the subroutine executes come between FORM and ENDFORM.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-18
Visible globally
... PERFORM fill_itab CHANGING it_flightinfo. FORM fill_itab CHANGING f_itab TYPE sbc400_t_sbc400focc. Visible locally DATA l_wa LIKE LINE OF f_itab. DATA * LOOP AT it_flightinfo INTO wa_flightinfo * would be also possible LOOP AT f_itab INTO l_wa. ... ENDLOOP. ENDFORM.
SAP AG 2003
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
You can define local data within a subroutine. Both the formal parameters and the local data objects are active only at the run time of the subroutine. This means that memory is allocated only when the subroutine is called and is released as soon as the subroutine has been executed. Thus these parameters and data objects can be addressed only from within the subroutine. The global data objects from the main program can also be addressed from the subroutine. However, you should avoid doing this wherever possible. Otherwise, you bypass the interface, which makes the program more prone to errors. If a local data object or formal parameter has the same name as a global data object, the ABAP runtime system addresses the local data object in the subroutine and the global one outside it. These objects are then known as locally obscured objects. Summary of hints about gobal and local data objects: Address the global data objects in the main program and pass them to the subroutine using the interface. Address only formal parameters and local data objects in the subroutine. For clarity, avoid using identically named global and local variables. Instead, use a simple prefix, such as f_ for formal parameters and l_ for local data objects.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-19
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
1-20
ABAP program Data objects pa_car wa_scarr ABAP Processing block SELECT ... SELECT FROM scarr Open SQL DatabaseDatabasespecific conversion Database interface ABAP runtime system Database SQL Database table SCARR
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
Open SQL statements are a subset of Standard SQL that is fully integrated in the ABAP language. (SQL stands for standard query language.) Open SQL statements allow you to access the database in a uniform way from your programs, regardless of the database system installed. The database interface converts Open SQL statements to databasespecific SQL statements.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-21
Which table(s)?
Single line
o n l y
}
Particular column
Multiple lines
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
To program database read access, use the Open SQL statement SELECT. The SELECT statement contains a series of clauses, each of which has a different task: The SELECT clause describes, among other things, whether the result of the selection will be several lines or a single data record and which fields of the table are to be read. The FROM clause names the source (database table or view) from which the data is to be selected. The INTO clause determines the internal data objects into which the selected data is to be placed. The WHERE clause specifies the conditions that the selection results must fulfill. It thus determines the lines to be selected from the table. For information about other clauses, refer to the keyword documentation for SELECT.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-22
o n l y
SELECT SINGLE * FROM scarr INTO INTO wa_scarr WHERE carrid = pa_car. WHERE IF sy-subrc = 0. ... Database interface
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The SELECT SINGLE* statement allows you to read a single record from the database table. To ensure that you read a unique entry, all of the key fields must be filled by the WHERE clause. The asterisk * after SINGLE tells the database interface to read all columns in that line of the database table. If you want only a specific selection of columns, you can list the required fields instead. In the INTO clause, enter the destination where the database interface is to copy the data. The target area should be structured left justified just like the required columns of the database table. If you use the CORRESPONDING FIELDS OF addition in the INTO clause, you can fill the target area component by component. The system fills only those components that have identical names to columns in the database table. Note: If you do not use this addition, the system fills the target area left justified, irrespective of its structure. If the system finds a table entry matching your conditions, SY-SUBRC has the value zero (0). The SINGLE addition tells the database that only one line needs to be read. The database can then terminate the search as soon as it has found that line. Therefore, SELECT SINGLE produces better performance for single-record access than a SELECT loop if you supply values for all key fields
C S C
o n l y
F o r
SAP AG
PDEBWB
1-23
pa_car wa_sbc400focc
SELECT carrid connid fldate SELECT seatsocc seatsmax FROM sflight INTO wa_sbc400focc WHERE carrid = pa_car.
Statements for every record read
F o r
o n l y
b y
C S C
Database interface
i n t e r n a l
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
If you do not use the addition SINGLE with the SELECT statement, the system reads multiple records from the database. The field list determines the columns whose data is to be read from the database. The number of requested lines to be read can be restricted using the WHERE clause. In the WHERE clause you may enter only the field names of the database table. The name of the database table you want to access is found in the FROM clause. Multiple logical conditions can be added to the WHERE clause using AND, NOT or OR statements. The database delivers data to the database interface in packages. The ABAP runtime system copies the data records to the target area line by line using a loop. It also enables sequential processing of all the statements between SELECT and ENDSELECT. After the ENDSELECT statement, you can check the return code for the SELECT loop. sy-subrc will have the value zero (0) if the database interface has found at least one record. After the ENDSELECT statement, sy-dbcnt contains the total number of lines read.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-24
pa_car itab_focc
SELECT carrid connid fldate seatsmax seatsocc FROM sflight INTO TABLE itab_focc WHERE carrid = pa_car.
F o r
o n l y
IF sy-subrc = 0. ...
b y
C S C
Database interface
i n t e r n a l
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The addition INTO TABLE itab causes the ABAP runtime system to copy the contents of the database interface directly to the internal table itab. This is called an array fetch. Since the array fetch is not executed as a loop, do not program any ENDSELECT statement. If you want to add lines to the end of an internal table that is already filled, instead of overwriting it, use the APPENDING TABLE itab addition. sy-subrc has the value 0 if the system was able to read at least one record.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-25
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The program must contain a data object with a suitable type for each column that is required from a database table. For program maintenance reasons, you must use the corresponding Dictionary objects to assign types to the data objects. The INTO clause specifies the data object into which you want to place the data from the database table. You can use the INTO clause in two different ways: Using a flat structure You define a structure in your program that has the same fields in the same sequence as the field list in the SELECT clause. You can enter the name of the structure in the INTO clause. The contents are copied left justified. The field names of the structure are disregarded here. Using individual data objects You can enter a set of data objects in the INTO clause. For example: DATA: gd_carrid TYPE sflight-carrid, gd_connid TYPE sflight-connid, gd_fldate TYPE sflight-fldate, gd_seatsmax TYPE sflight-seatsmax, gd_seatsocc TYPE sflight-seatsocc. START-OF-SELECTION. SELECT carrid connid fldate seatsmax seatsocc FROM sflight INTO (gd_carrid, gd_connid, gd_fldate, gd_seatsmax, gd_seatsocc) WHERE ...
C S C
o n l y
F o r
SAP AG
PDEBWB
1-26
F o r
o n l y
i n t e r n a l
C S C
b y
...
DEPTIME
u s e
u s e
i n t e r n a l
b y
If you use the INTO CORRESPONDING FIELDS clause, the data is placed in the fields with the same name in the target structure. Advantages of this construction: The target structure does not have to be structured left justified in the identical way as the field list. This construction is easy to maintain, because extending the field list does not require other changes to the program, as long as there is a field in the target structure that has the same name and type. To place data in internal table columns of the same name using an array fetch, use the INTO CORRESPONDING FIELDS OF TABLE itab statement.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-27
Secondary index
CITYFROM BERLIN BERLIN ... FRANKFURT FRANKFURT FRANKFURT FRANKFURT ... NEW YORK NEW YORK ...
SAP AG 2003
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
When you go to the definition of a database table in the ABAP Dictionary, you will see information on all the technical attributes of the database table. The following information is useful for improving the performance of database accesses: Key fields If the lines requested from the database are retrieved according to key fields, the Database Optimizer can perform access using a primary index. Secondary index If the lines requested from the database are retrieved according to fields, the Database Optimizer can perform access using a secondary index. Secondary indexes are displayed in a dialog box whenever you select Indexes. You choose an index from the dialog box by double-clicking it. The system then displays a screen with additional information about that index.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-28
Data Retrieval
F o r
o n l y
Enhancements
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
1-29
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The purpose of a program enhancement is always to call an object in the customer namespace. You can use the following techniques here: Customer Exits A special exit function module is called by the SAP application program. The function module is part of a function group that is handled in a special manner by the system. Business Transaction Events The SAP application program dynamically calls a function module in the customer namespace. Business Add-Ins BAdIs are the new object oriented enhancement concept, which in the future will replace all other enhancement concepts. The advantages of this concept lies in the facts that you can have several implementations for one enhancement and that you can use filters. The application program calls a method of a class or instance of a class. This class lies in the customer namespace.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-30
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
This graphic shows the flow of a program providing an enhancement in the form of a function module exit. The exit function module is called in the PAI logic of a screen at a position determined by the SAP application developer. Within the function module, the user can add functions in the customer namespace using an include.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-31
START-OF-SELECTION. ... CALL CUSTOMER-FUNCTION '001' CUSTOMEREXPORTING .... IMPORTING .... . FUNCTION-POOL XAAA. ... FUNCTION exit_<program_name>_001. ... INCLUDE zxaaau01.
F o r
o n l y
i n t e r n a l
b y
C S C
ENDFUNCTION.
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
To call function modules use the ABAP statement CALL CUSTOMER-FUNCTION 'nnn', where nnn is a three-digit number. The programmer must also create the function module he wants to call and its related function group. These function modules always belong to function groups whose names begin with X (X function group). The following naming convention applies to function modules: Prefix: EXIT Name: Name of the program that calls the function module Suffix: Three-digit number The three parts of the name are separated by an underscore. The CALL CUSTOMER-FUNCTION statement is only executed once the enhancement project has been activated. Multiple calls of the same function module are all activated at the same time.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-32
<impl>
Change
Create
F o r
o n l y
i n t e r n a l
b y
C S C
Definition name
<badi>
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
To implement Business Add-Ins, use transaction SE19 (Tools -> ABAP Workbench -> Utilities -> Business Add-Ins ->Implementation). Enter a name for the implementation and choose Create. A dialog box appears. Enter the name of the Business Add-In. The maintenance screen for the Business Add-In then appears. Alternatively, you can use the Business Add-In definition transaction (SE18) to reach its implementations. The menu contains an entry, Implementation, which you can use to get an overview of the existing implementations. You can also create new implementations from here.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-33
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
You can assign any name to the implementing class. However, it is a good idea to observe the proposed naming convention. The suggested name is constructed as follows: Namespace prefix, Y or Z CL_ (for class) IM_ (for implementation) Name of the implementation To implement the method, double-click its name. The system starts the Class Builder editor. When you have finished, you must activate your objects.
C S C
o n l y
F o r
SAP AG
PDEBWB
1-34
You should now be able to: Work with internal tables Use field symbols Work with subroutines Select data from the database Explain the different enhancement techniques
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
1-35
Data Extraction
Contents:
Creating generic DataSources using function modules for Data Extraction Enhancing DataSources for transaction data, master data attibutes and texts Using the Service API function enhancement to enrich data Overview of the options available for enhancing data in the source system
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
2-1
After completing this unit, you will be able to: Create generic DataSources using function modules for data extraction Enhance DataSources to meet your companys requirements Use the Service-API (SAPI) SAP enhancements to enrich data
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
2-2
3 5 BEx-Variables Reporting
InfoCubes / ODS & Master Data
2 ABAP Basics
InfoSource
o n l y
SAP BW Server
1 3 Data Extraction Extraction
F o r
i n t e r n a l
C S C
DB DB
R/3 R/3
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
2-3
Your company wants to analyze data from SAP systems in a BW system. Since no DataSources suitable for this purpose are delivered with Business Content, you have been given the task of using the generic data extraction tools to generate a DataSource that can also extract data from several DB tables and enrich it. Furthermore, your company wants to include the old material number as an additional characteristic in certain queries in BW. You decide to modify/enhance a Business Content extractor for getting this piece of information.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
2-4
When should you use the generic data extraction tools to create a DataSource?
Business Content does not include a DataSource for your application. You want to implement a delta method on your generic DataSource that cannot be implemented by using the generic delta functionality (timestamp, date, ...). The application does not allow to create additional application specific generic extractors (CO-PA, FI-SL, LIS). You use your own programs in the SAP system to populate your own tables. You have to extract data from several DB tables: using a view is not possible because of insufficient JOIN only some fields are relevant of these tables data has to be enriched with information not available in BW system
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
Make sure first that the functionality is not available within Business Content!
C S C
o n l y
F o r
SAP AG
PDEBWB
2-5
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The tools for generic data extraction are accessed in transaction RSO2. You use this transaction to create DataSources for transaction data, master data and texts.
C S C
o n l y
F o r
SAP AG
PDEBWB
2-6
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
When you create a generic DataSource, you first have to specify the application component and the texts that describe the DataSource. The application component determines where the DataSource is stored in the DataSources section of the source system tab in the Administrator Workbench after the DataSources have been replicated. You are then able to select the source of data for the generic DataSource. Besides using function modules as sources, you can also use transparent tables, database views and the SAP Query / InfoSet Query to extract data. Click on the Extraction by FM' button, if you want to extract data from a function module, and type in the name of the function module and of the extraction structure that you want to use. When you generate the DataSource, its extract structure corresponds to that of the view or table that you used. You get to the screen for maintaining a function module and for maintaining an existing extraction structure by double-clicking on the relevant field. There are several templates delivered that helps you to use function modules to extract data: RSAX_BIW_GET_DATA, RSAX_BIW_GET_DATA_SIMPLE, RSAX_BIW_GET_DATA_WITH_ARCHIVE, RSAX_BIW_GET_MASTER_DATA, RSAX_BIW_GET_TEXTS, RSAX_EVENT_ACTIVATE_CONTENT, RSAX_EVENT_AFTER_IMPORT,RSAX_EVENT_DELETE_DSOURCE, RSAX_EVENT_RESET_DELTA, RSAX_EVENT_SAVE_DATASOURCE, RSAX_EVENT_TRANSPORT_DSOURCE, RSAX_GEN_HIERARCHY_CATALOG, RSAX_GEN_HIERARCHY_TRANSFER, RSAX_HIERARCHY_CATALOG_HCLASS, RSAX_HIERARCHY_TRANSFER_HCLASS
SAP AG
C S C
o n l y
F o r
PDEBWB
2-7
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
The interface (i.e. imporing parameters, tables and exceptions) of the function module are the following: IMPORTING I_REQUNR - Request number I_DSOURCE - Name of the DataSource I_MAXSIZE - Maximal numbers of records read while processing the code (field V_IDOCPRMSMAXLINES) I_INITFLAG - Flag, marks the function module is called the first time (X otherwise SPACE) I_READ_ONLY TABLES I_T_SELECT - Select-Options of the DataSource (sended by BW) I_T_FIELDS - Transfer structure fields: only these are actually filled in the data table and be addressed in the program E_T_DATA Data Package (= extracted Data; in structure of the extraction structure) EXCEPTIONS NO_MORE_DATA - Exception, marks the last call fo the function module ERROR_PASSED_TO_MESS_HANDLER - Exception, ends the extraction and sends information message
SAP AG
b y
C S C
o n l y
F o r
can
PDEBWB
2-8
Process of Extraction
The function module is called up several times during an extraction process: 1. Initialization call: Only the request parameters are transferred from the module here. It cannot transfer data at this point. 2. First read call: The extractor delivers the data typed with the extraction structure to an interface table. The number of rows expected is specified in a request parameter (I_MAXSIZE). 3. Further read calls: The extractor delivers the data connected to the last package, again in a package with I_MAXSIZE rows. 4. Last call The function module is now called until the exception NO_MORE_DATA is produced. No more data can be transferred in the call in which the exception is produced.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
Example An example of a function module that corresponds to these requirements is RSAX_BIW_GET_DATA_SIMPLE. A simple procedure for creating a syntactically correct module is to copy this into its own function group, and to copy the rows of the top include of the function group RSAX (LRSAXTOP) into the top include of the function group for the module. You then have to adjust the copied function module to the requirements of the module you created.
C S C
o n l y
F o r
SAP AG
PDEBWB
2-9
Reasons:
You want to add extra attributes to the characteristics (master data) shipped with the system You want to populate additional fields that you appended to the extract structure with data at the time of extraction You want to change/enhance texts or hierachies
Prerequisites:
The additional data is available at the time the extraction takes place All information which is needed for determinating the additional data clearly is available
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
Make sure first that the functionality is not available within Business Content!
C S C
o n l y
F o r
SAP AG
PDEBWB
2-10
* user -enhancement no. 1 CALL CUSTOMER - FUNCTION '001' EXPORTING <Export Parameter> = <value> IMPORTING <Import Parameter> = <value> TABLES <Table structure> EXCEPTIONS
Customer -Exit Nr . 1
<result>. . . * user -enhancement no. 2 CALL CUSTOMER - FUNCTION '002' EXPORTING . . . PERFORM INTERMEDIARY PROCESS. * user -enhancement no. X CALL CUSTOMER - FUNCTION '00X' EXPORTING . . PERFORM FINAL PROCESS.
Customer -Exit Nr . 2
o n l y
. . . . .
Customer -Exit Nr . X
. . . .
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
You use Customer/User Exits to branch at pre-set points from the SAP standard program run into user-defined subprograms. This adds a few features of your own to complement the standard functions available. This also gives SAP software the highest possible degree of flexibility. The user-defined sections of code are managed in isolation as objects in the customer namespace, so there is no need to worry about complications when the next Release comes or when correction packages are implemented. In the example above, the section between the dotted lines describes the data that the user code can use for its logic and the input that the SAP code can expect to receive back from the customergenerated logic.
C S C
o n l y
F o r
SAP AG
PDEBWB
2-11
o n l y
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
In the BW IMG (transaction SBIW) choose the path: Business Information Warehouse Postprocessing of DataSources Edit DataSources In the first step, you have to generate the customer append for the extract structure of your DataSource. The system proposes a name that begins with ZA followed by the name of the extract structure. Next, you maintain the fields that you want to enhance later. The names of all of these fields must start with ZZ so that they can be identified easily. Finally, you have to generate your append structure.
C S C
o n l y
F o r
SAP AG
PDEBWB
2-12
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
In the second step, you must define the function enhancement for filling the new fields in the extract structure. You have to create a project before you can use an enhancement like this. You can then integrate one or more enhancements into this project. For our particular task, SAP provides the enhancement RSAP0001. Remember that an enhancement cannot be used in two projects simultaneously. There are four different enhancement components available for the RSAP0001 enhancement. The code for filling the extract structure is stored in their INCLUDEs. EXIT_SAPLRSAP_001: Transaction data supply EXIT_SAPLRSAP_002: Master data attributes and text supply EXIT_SAPLRSAP_004: Hierarchy supply Documentation is available for every enhancement project. The documentation also explains the individual parameters of the function module. Before you are able to use it, the enhancement must be activated. Documentation for the whole enhancement is available under Help ? Display Documentation in the project management transaction for SAP enhancements (CMOD).
C S C
o n l y
F o r
SAP AG
PDEBWB
2-13
BW
Load Data
3 OLTP
Replicate DataSources
Transfer Structure
F o r
o n l y
Extraktion Structure 1 2
Append Fill
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
If your requirements are not met entirely by the DataSources supplied with Business Content, you can bring additional information into the extraction routine by developing your own program and integrating it in a function enhancement. Note the following four steps: 1. Define the required fields in an append structure that is attached to the extract structure of your DataSource. 2. Write/Enhance your function exit to call up the relevant sources of data for your DataSource. 3. Replicate the DataSource in the BW system. 4. Extract the data for your enhanced Business Content. Use the EXIT_SAPLRSAP_001 function exit to fill the extra fields with data. The original fields are filled by the extractor.
C S C
o n l y
F o r
SAP AG
PDEBWB
2-14
Maintain DataSource
Method A
Extractor for BW
1 2 3 4
Extraction structure 1 2 3 4 5 6
fills
Method B
Extractor for BW (new*)
1 2 3 4 5 6
o n l y
View = Structure
F o r
fills
b y
C S C
i n t e r n a l
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
Method A: Enhancing the extract structure with a customer append and using a function exit to fill the fields. This method can be used with the 'view', 'ABAP Query', and 'function module' types of extraction. Procedure: Do not change the standard view. Create an append structure and define your new fields (attributes). Use the EXIT_SAPLRSAP_002 function exit to fill the extra fields with data. The original fields are filled by the extractor.
C S C
o n l y
F o r
SAP AG
PDEBWB
2-15
Sample Code
*&-------------------------------------------------------* *& Include ZXRSAU02 * *&-------------------------------------------------------* CASE i_datasource. WHEN '0MATERIAL_ATTR'. PERFORM 0material(saplxrsa) TABLES i_t_data IF FOUND. ENDCASE.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
IMPORTANT: Always use a CASE statement to interrogate the DataSource, because this function exit is called with every DataSource. Define one include for each DataSource to manage topics as transport, authorities etc. easier! Interface parameters EXIT_SAPLRSAP_001/-002: IMPORTING I_DATASOURCE/-ISOURCE (extracted data), I_CHABASNM (Name of basic characteristic), I_UPDMODE (Transfer mode, as requested in the Scheduler of BW; usually not required) TABLES I_T_SELECT (Selection criteria), I_T_FIELDS (Transfer structure fields: only these are actually filled in the data table and can be addressed in the program), C-/I_T_DATA (Table with the data obtained from the application API), C_T_MESSAGES EXCEPTIONS RSAP_CUSTOMER_EXIT_ERROR Interface parameters: EXIT_SAPLRSAP_004: IMPORTING I_DATASOURCE, I_S_HIEBAS, I_S_HIEFLAG, I_S_HIER_SEL, I_S_HEADER3 TABLES I_T_LANGU, C_T_HIETEXT, C_T_HIENODE, C_T_FOLDERT, C_T_HIEINTV, C_T_HIENODE3, C_T_HIEINTV3, C_T_MESSAGES EXCEPTIONS
SAP AG
C S C
o n l y
F o r
RSAP_CUSTOMER_EXIT_ERROR
PDEBWB 2-16
o n l y
Trouble-Shooting is easily done by setting a break-point in the exit code and starting the Extractor Checker tool (transaction RSA3)
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
2-17
You should now be able to: Create generic DataSources Use function modules for data extraction Enhance DataSources to meet your companys requirements Use the Service SAP function enhancements to enrich data
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
2-18
Data Staging
Contents:
InfoPackages Start Routines Transfer Rules Update Rules
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-1
After completing this unit, you will be able to: Use and program exits in different parts of the data staging process
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-2
3 5 BEx-Variables Reporting
InfoCubes / ODS & Master Data
2 ABAP Basics
InfoSource
o n l y
SAP BW Server
1 3 Data Extraction Extraction
F o r
i n t e r n a l
C S C
DB DB
R/3 R/3
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-3
The higher complexity of SAP BW data flow during the staging process rises (e.g. consolidation requirements) the more flexibility via ABAP routines is necessary to cover all demands. The reason for using ABAP routines during data staging can simply be the flexibility of coding: Either the combination of SAP BW Business Content with customer demands or highly qualified project demands are covered by the usage of routines. All requirements have nothing to do with application programming. Also there is no GUI programming necessary to get project requirements of a data flow into the system.
SAP AG 2003
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-4
o n l y
Transfer Rules
F o r
i n t e r n a l
b y
C S C
Update Rules
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-5
F o r
o n l y
Static reports like known from SAP R/3 usually do not have to be built in anymore. A SAPGUI Dynpro programming is not necessary at all.
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-6
Info Provider Start Routine Update Rule Communication Structure ABAP Start Routine Transfer Rule Transfer Structure dynamic InfoPackage Selection dynamic Flatfile File Name dynamic Deletion of Requests InfoPackage Data Flow
ABAP
F o r
o n l y
ABAP
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-7
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-8
o n l y
Transfer Rules
F o r
i n t e r n a l
b y
C S C
Update Rules
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-9
InfoPackages
Selections Deletion of equal/similar requests Maintain directory and file names dynamically
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-10
Selection possibilities
InfoPackages provide static and dynamic selection criteria for every selection field for various characteristic types
DYNAMIC
Date field (due date is actual day): get yesterday (00:00 to 24:00h) get last week (Monday to Sunday) get last month (first to last day of last month) get last quarter (first to last day of last quarter) get last year (1st of Jan. to 31st of Dec. Of previous year) No date field: free boundary (also an period boundary is possible) All fields: ABAP Routine SAP AG 2003 OLAP Variable
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-11
1. 2. 3.
Choose type
F o r
o n l y
4.
i n t e r n a l
C S C
5.
Within the form routine there is the index l_idx (like sy-tabix) which gives back the actual record of the selection field
b y
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-12
Example:
InfoObject 0SALESORG Field VKORG Assignment of multiple sales organisations from a table which is filled already
*$*$ begin of routine - insert your code only below this line data: l_idx like sy-tabix. data: z_l_t_range like l_t_range. read table l_t_range with key fieldname = 'VKORG'. l_idx = sy-tabix.
Additional declaration of a helping structure equal to the selection structure Deletion of the typed static selection of field VKORG reason: only the routine should read the values (although both is possible: static values and values from the routine) Loop through sales organisation for all selection parameters Assignment to the helping structure Append of the structure to the selection table Modify the selection table at the index of the sales organisation
* bisherige Selektionstabelle am aktuellen Index fr das Feld lschen: delete l_t_range index l_idx. * Anhngen von vielen VKORGs an die Selektionstabelle * (Interne Tabelle itab_vkorg wurde im Hintergrund befllt) loop at itab_vkorg. z_l_t_range-fieldname ='VKORG'. z_l_t_range-IOBJNM z_l_t_range-low z_l_t_range-sign z_l_t_range-option = l_t_range-IOBJNM.
F o r
o n l y
i n t e r n a l
append z_l_t_range to l_t_range. endloop. modify l_t_range index l_idx. p_subrc = 0. *$*$ end of routine - insert your code only before this line *-*
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-13
1. Choose type
Possible scenario: the last calendar day 0L_DATE to get the necessary booking day (definition of OLAP variables: please refer to course BW305) Define the variable with necessary fiscal variant (in this case) and view the actual values by clicking the glasses button (the day before february 5 2004 equals to 20040204) An OLAP variable also can be filled via an (ABAP-) exit ...
o n l y
2.
F o r
i n t e r n a l
C S C
3.
b y
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-14
InfoPackages Selections Deletion of equal/similar requests Maintain directory and file names dynamically
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-15
When the button at the InfoPackage tab data targets is grey there are no functions for deletion defined
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-16
o n l y
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-17
(it is very similar to the selection routine) All field values for the structure of the deletion request have to be defined at runtime Within a loop all requests into the InfoCube which have to be deleted are added to the internal table
Structure RSREQDELSTRUC of the deletion table l_t_request_to_delete:
RNR SID TIMESTAMP ISOURCE OLTPSOURCE LOGSYS UPDMODE UNAME STATUS ROLLED_UP COMPRESSED Request number for the data transfer Master data ID UTC Time Stamp in Short Form (YYYYMMDDhhmmss) InfoSource DataSource Logical system Boolean SAP System, User Logon Name Request status (internal display) Boolean Boolean
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-18
Scenario
In some cases it is necessary to load data on each 15th day of the month and additionally at the end of month again There is no delta mechanism for it
Dupplication of the data would be the effect (no deletion!)
o n l y
The deletion functions or conditions are able to identify duplicates of the actual request these duplicates can be deleted with the settings on the dialog or via the ABAP routine
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-19
InfoPackages Selections Deletion of equal/similar requests Maintain directory and file names dynamically
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-20
Data load in batch mode is possible Path is physically equal to all administrators
* Field separator FS = ; * Escape character ESCAPE = \ * Decimal point DECIMALPOINT = , * Separator for thousands 1000SEPARATOR = . * Number of records in file RECCOUNT = 985 * Length of one record RECSIZE = 53 * Number of records in one Idoc Packet PACKETSIZE = 1000 * Selection date SELDATE = 19980903 * Selection time SELTIME = 112305
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-21
p_subrc like sy-subrc. Insert source code to current selection field *-*
Transaction data is delivered monthly by flat file The naming convention includes the name of the month within the filename Directory pathes are maintained for every year Coding: concatenate
Directory path Actual year Actual month
*$*$ begin of routine - insert your code only below this line data: l_filename like rsldpsel-filename. concatenate '\\sapcom01\bw\Data\' sy-datum(4) '\bwupload' sy-datum+4(2) '.CSV' into l_filename. p_filename = l_filename. p_subrc = 0. *$*$ end of routine - insert your code only before this line endform. path year "File name with "Month save as csv file
F o r
o n l y
*-*
i n t e r n a l
C S C
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-22
o n l y
Transfer Rules
F o r
i n t e r n a l
b y
C S C
Update Rules
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-23
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-24
Start routines are processed, after the data is written into the PSA Before the transfer rules are processed.
Start routines do get as parameter the whole data package structured in form of the transfer structure
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-25
All fields of the transfer structure are listed in the header of the coding. Global declaration either for the start routine or the transfer rule routines are defined in the header of the coding (delete comment of TABLES and DATA declaration); the local declarations are defined within the form routine STARTROUTINE. The data package is delivered with the internal table DATAPAK The transfer structure and all fields are accessable via the internal form routine declaration l_s_datapak<feldname> just delete the comment.
F o r
o n l y
i n t e r n a l
C S C
Customer CODING
*-*
b y
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-26
The data package DATAPAK is stored in an internal table of type TAB_TRANSTRU and all its records of the type of the transfer structure TRANSFER_STRUCTURE. An error log of the global structure G_T_ERRORLOG allows to set monitor entries (please refer to chapter monitoring). ABORT set as a return code for the whole data package call ( ABORT <> 0 means that the whole working process of the complete data package will be cancelled!)
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-27
Classic usage
Particularly the start routine of the transfer rules gives classic scenarios of usage:
Selective deletion of records delivered with the data package Coding example: DELETE DATAPAK WHERE VKORG = 1000. Advantage: smaller data package loading performance improves
F o r
o n l y
C S C
Fill of an internal table from a DDIC select (please refer to the performance aspects) Complex data cleansing or data consolidation from various source systems eventually with a look up as ETL process
SAP AG 2003
i n t e r n a l
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-28
TINE R OU RT STA
ULE
G_T_ERRORLOG TYPE rssm_t_errorlog_int ABORT LIKE SY-SUBRC. "set ABORT <> 0 to cancel datapackage *$*$ begin of routine - insert your code only below this line * DATA: l_s_errorlog TYPE rssm_s_errorlog_int. * CO_AREA wird nur zugewiesen, wenn die Periode der Transferstruktur dem aktuellen Monat entspricht: if TRAN_STRUCTURE-FISCPER+5(2) = sy-datum+4(2). RESULT = TRAN_STRUCTURE-KOKRS. RETURNCODE = 0. else. * returncode <> 0 means skip this record RETURNCODE = 4. endif. * abort <> 0 means skip whole data package !!! ABORT = 0. *$*$ end of routine - insert your code only before this line ENDFORM. *-* *-*
FORM STARTROUTINE USING G_S_MINFO TYPE RSSM_S_MINFO CHANGING DATAPAK type TAB_TRANSTRU G_T_ERRORLOG TYPE rssm_t_errorlog_int ABORT LIKE SY-SUBRC. "set ABORT <> 0 to cancel datapackage *$*$ begin of routine - insert your code only below this line *-*
o n l y
DATA: l_s_datapak_line type TRANSFER_STRUCTURE, l_s_errorlog TYPE rssm_s_errorlog_int, l_tabix like sy-tabix. loop at datapak into l_s_datapak_line. l_tabix = sy-tabix. if not l_s_datapak_line-FISCPER+5(2) = sy-datum+4(2). delete datapak index l_tabix. endif. endloop.
* abort <> 0 means skip whole data package !!! ABORT = 0. *$*$ end of routine - insert your code only before this line ENDFORM.
F o r
i n t e r n a l
C S C
b y
*-*
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-29
Start routines
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-30
The globale declaration either for the start routine or all update rule routines can be maintained within the header section; the local declaration will be done within the form routineSTARTUP. The communication structure and all its fields are accessable via the structure of the DATA_PACKAGE. The data package is delivered with the internal table DATA_PACKAGE.
F o r
o n l y
i n t e r n a l
C S C
Customer CODING
*-*
* if abort is not equal zero, the update process will be canceled ABORT = 0. *$*$ end of routine - 2003 your code only before this line SAP AG insert
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-31
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-32
Typical scenarios
Fill an internal table from a data base table (DDIC) (please refer also to performance aspects) Look up scenarios during loading into data targets Adding or appending of information from other data provider or data stores Consolidation scenarios:
Consolidate characteristic and key figure combinations Key figure calculation to store the result on the data base in order to release the OLAP processor e.g. when multiple basis cubes are consolidated into one
F o r
o n l y
b y
C S C
Segmentations of characteristic values in order of key figure numbers (e.g. ABC classification on characteristic values)
i n t e r n a l
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-33
Implementation:
Model: The splitting rules are loaded into one ODS-Object and into two master data info objects. A new cube as template of the former one is created and all segmentation characteristics are added into the model. An export data source delivers the data from the former cube. Implementation within the start routine: 1. 2. 3. 4. 5. Master data information and ODS-Object values are read into internal tables and sorted. Loop over the data package read additional informations from the itabs and check the communication structure loop over ODS-Object values all key figures from the first to the n segment are calculated with the segmentation informations from the ODSObject and finally appended to an internal helping table all deliverd records are multiplied end loop ODS-Object. data records which do not depend to a segmentation split are appended directly (otherwise the overallresult is not correct) original record from the data package will be deleted. End loop data package Append internal helping table to (empty) data package table when ok:
F o r
o n l y
6. 7. 8. 9. 10.
i n t e r n a l
C S C
b y
All update rules of key figures and characteristics are set to 1:1 (no further adaption)
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-34
(Please also refer to return tables in chapter update rules) Idea: make multiple records out of one data record Example: account model
Comparison of key figure model vs. account model: refer to note 407563 It is possible to add any key figure because they are identified via characteristics An enhancement of a key figure is not necessary Advantage or disadvantage of an account model denpends on the frequency of changing key figures The communication structure delivers key figure orientated a data record The data target takes each key figure into a value field or a quantity field which differ by characteristic values There is no 1:1 assignment possible within the update rules One records of the communication structure is devided into several records of the data target structure
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-35
Global declaration of an internal table g_t_returntab with the structure of the data target. Loop over the data package all characteristics and key figure 1 all characteristics and key figure 2 all characteristics and key figure n End loop data package (DELETE DATA_PACKAGE.) optional is not needed anymore ... append to g_t_returntab append to g_t_returntab append to g_t_returntab
2. 3. 4. 5. 6. 7.
2. Update rules
1. 2. 3.
F o r
o n l y
Key figure or data field assignment Define routine and set check box return table Assign global table g_t_returntab to the interface of the form routine: APPEND LINES OF G_T_RETURNTAB TO RESULT_TABLE. Eventually this assignment only one time: IF RECORD_NO = RECORD_ALL. APPEND LINES OF ENDIF.
i n t e r n a l
C S C
4.
b y
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-36
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-37
Processing via start routines vs. assignment within transfer or update rules:
The combination of startroutine with a cycle over the data package and additional routines in transfer or update rules my rises historical but it is not useful: multiple (2x) cycle over the whole data package! Whenever the start routine is touched, the data package is edited and you know how to handle ABAP stay in the start routine!
F o r
o n l y
Debugging
(see chapter) All ABAPs are able to be debugged via the PSA data package simulation (or via the monitor) May be it is usefull to code a break-point for development reasons
SAP AG 2003
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-38
Application/process informationen Important informations which are useful to understand the data which is loaded. Motto:
give information to the administrator that mirrors the professional quality of the data Be economical with it because for every record of the data package an information within the monitor can be displayed (uge log files).
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-39
F o r
o n l y
Update rule:
Monitoring without record number: Table MONITOR Monitorin with record number: Table MONITOR_RECNO
SAP AG 2003
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-40
Monitoring - procedure
Message class
Transaction SE91 Open or create message class
Messages
Transaction SE91 Define messages with message numbers Set the place holder & to use variables
(message variables msgv1 to msgv4 are filled in turn for each place holder).
Coding:
Define variables useful with technical or professional information:
MONITOR-msgid = 'ZBWMESS'. MONITOR-msgty = 'I'. MONITOR-msgno = '20'. MONITOR-msgv1 = DATA_PACKAGE-/BIC/ZSOPCOMPS. MONITOR-msgv2 = DATA_PACKAGE-/bic/zlartdiv. MONITOR-msgv3 = DATA_PACKAGE-/BIC/ZLARTNO. MONITOR-msgv4 = DATA_PACKAGE-/BIC/ZLARTVAR. append MONITOR. Customer company code Local article division Local article number Local article variant
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-41
o n l y
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-42
F o r
o n l y
Customer functions can be developed via BADIs The ABAP code is not precalculated or stored on the data base it is calculated for every run performance losses
SAP AG 2003
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-43
Switch on the expert mode to edit directly within the formula window The left frame gives you all fields of the delivering structure (transfer structure transfer rules; communication structure update rules) The right frame gives you all available functions A Download or an upload of formulas is possible via the buttons The syntax check is important ...
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-44
2. 3.
o n l y
F o r
i n t e r n a l
C S C
Give the routine a name Mark the fields with which you want to work with
b y
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-45
Header structure equals to the definitions in a start routine The fields which are selected to work with are not commented any more Global declarations for TABLES and DATA can be made by deletion of the comments
F o r
o n l y
END OF TRANSFER_STRUCTURE . * Global code used by conversion rules *$*$ begin of global - insert your declaration only below this line *-* * TABLES: ... * DATA: ... *$*$ end of global - insert your declaration only before this line *-*
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-46
*--------------------------------------------------------------* * Compute value of InfoObject 0CO_AREA * in communication structure /BI0/CS0CO_OM_OPA_6 * Technical properties: * * * * * * * * field name data element data type length decimals ABAP type ABAP length = CO_AREA = /BI0/OICO_AREA = CHAR = 000004 = 000000 =C = 000004
The actual record number is deliverd by RECORD_NO The transfer structure and the chosen fields are accessable via TRAN_STRUCTURE The parameter RESULT gives the value back to the transfer rule and its info object With the global structure G_T_ERRORLOG it is possible to create monitor entries (see Monitoring). The parameter RETURNCODE of the type sy-subrc delivers the caller wheather the actual record can be processed (=0) or has to be skipped (<> 0) The parameter ABORT of the type sysubrc delivers the caller wheather the processing of the whole data package has to be terminated (<> 0) or not (= 0)
reference field =
F o r
o n l y
* <-> G_T_ERRORLOG Error log * <-- RETURNCODE * <-- ABORT Return code (to skip one record)
i n t e r n a l
C S C
*--------------------------------------------------------------*
b y
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-47
Within the form routine the field RESULT gets the output Example comparing to the chapter start routine:
The transfer structure is delivering a periodic value Actual transfer routine from field KOKRS into info object 0CO_AREA Assignment of this field and the whole record only when the deliverd record is equal to the current month (Periods 13 16 or 17 are not booked). If the month is equal the result is written and other assignments are allowed because of RETURNCODE = 0 If not the actual record is skipped
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-48
Invertion routines are used if the data flow runs into the opposite direction retraction e.g. to the CRM-System Invertion routines are only to be implemented when
SAP Remote Cubes are used to directly read data from the source system or With a report-report-interface and a combined Drill-Through to the source system
*----------------------------------------------------------------------* * --> I_RT_CHAVL_CS * <-- C_T_SELECTION * * <-- E_EXACT * --> I_THX_SELECTION_CS Selection criteria for all other InfoObjects transfer structure Flag: Inversion was exact
*----------------------------------------------------------------------* FORM INVERT_CO_AREA USING I_RT_CHAVL_CS TYPE RSARC_RT_CHAVL TYPE SBIWA_T_SELECT I_THX_SELECTION_CS TYPE RSARC_THX_SELCS CHANGING C_T_SELECTION E_EXACT DATA: L_S_SELECTION LIKE LINE OF C_T_SELECTION. * An empty selection means all values CLEAR C_T_SELECTION. L_S_SELECTION-FIELDNM = 'FISCPER'. * ... * Selection of all values may be not exact E_EXACT = RS_C_FALSE. *$*$ end of inverse routine - insert your code only before this line *-* TYPE RS_BOOL.
*$*$ begin of inverse routine - insert your code only below this line*-*
o n l y
The coding is reflecting selection criteria for characteristic values which were allowed by running into the BW:
See example before: CO_AREA for one period and the actual month
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-49
Convertion routines
Convertion routines depend to InfoObjects Within the transfer structure you can see which convertion routine is defined for the objects Within the InfoPackage you can allow these converts or you can switch them off Convertion routines are function modules to
Bring source system differen field definitions together Enhance data quality Avoid data inconsistency
You can call the function modules by double click on the routine within the InfoObject Examples:
ALPHA conversion (leading zeros), Material number conversion Date formats And a lot more
SAP AG 2003
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-50
o n l y
Transfer Rules
F o r
i n t e r n a l
b y
C S C
Update Rules
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-51
Characteristic assignment change of source (1) Give a name for the update rule (2) Interface:
Like in the start routine globale declaration within the header The form routine compute_key_field delivers following parameters: The table MONITOR for monitoring The communication structure COMM_STRUCTURE with all fields from the data source The current record number of the loop over the data package The number of total records RESULT delivers to the marked characteristic the result value RETURNCODE says wheather the current record will be processed or not ABORT clarfies wheather the whole data package will be processed or not
o n l y
FORM compute_key_field TABLES MONITOR STRUCTURE RSMONITOR "user defined monitoring USING COMM_STRUCTURE LIKE /BIC/CS80FIAR_O03 RECORD_NO LIKE SY-TABIX RECORD_ALL LIKE SY-TABIX SOURCE_SYSTEM LIKE RSUPDSIMULH-LOGSYS CHANGING RESULT LIKE /BI0/V0FIAR_C03T-ACCT_TYPE RETURNCODE LIKE SY-SUBRC ABORT LIKE SY-SUBRC. "set ABORT <> 0 to cancel update * *$*$ begin of routine - insert your code only below this line *-* * fill the internal table "MONITOR", to make monitor entries * result value of the routine RESULT = . * if the returncode is not equal zero, the result will not be updated RETURNCODE = 0. * if abort is not equal zero, the update process will be canceled ABORT = 0. *$*$ end of routine - insert your code only before this line * ENDFORM. *-*
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-52
Time references
Within update rules there are varios possibilities to reference time dependecies:
Characteristic update rule with time reference It is possible to update data target characteristics of type DATE via an automatic time distribution. The field is feeded from a data field out of the communication structure For example the data target characteristic calendar day is feeded from the source characteristic calendar month The effect is that every summariced key figure has to be distributed to the calendar days of the month In addition to that it can be defined wheather the company calendar has to be used. Time characteristics Within the frame time reference various data target time characteristics can be filled automatically from only one time characteristic of the data source.
SAP AG 2003
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-53
Specialities of the key figure calculation within the update rule dialog
The dialog with data target basic cube has
Addition No update
The dialog with data target ODS-Object has in addition to the basic cube update possibilities
overwrite
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-54
1 2
PROGRAM UPDATE_ROUTINE. *$*$ begin of global - insert your declaration only below this line *-* * TABLES: ... * DATA: ... *$*$ end of global - insert your declaration only before this line *-*
Change mode for key figure update rule (1) Name routine (2) Interface:
Like in the start routine globale declaration within the header The form routine compute_data_field delivers following parameters: The table MONITOR for monitoring. The communication structure COMM_STRUCTURE with all fields from the data source. The current record number of the loop over the data package The number of total records RESULT delivers to the marked characteristic the result value RETURNCODE says wheather the current record will be processed or not ABORT clarfies wheather the whole data package will be processed or not.
o n l y
FORM compute_data_field TABLES MONITOR STRUCTURE RSMONITOR "user defined monitoring USING COMM_STRUCTURE LIKE /BIC/CS80FIAR_O03 RECORD_NO LIKE SY-TABIX RECORD_ALL LIKE SY-TABIX SOURCE_SYSTEM LIKE RSUPDSIMULH-LOGSYS CHANGING RESULT LIKE /BI0/V0FIAR_C03T-DEB_CRE_LC RETURNCODE LIKE SY-SUBRC ABORT LIKE SY-SUBRC. "set ABORT <> 0 to cancel update * *$*$ begin of routine - insert your code only below this line *-* * fill the internal table "MONITOR", to make monitor entries * result value of the routine RESULT = . * if the returncode is not equal zero, the result will not be updated RETURNCODE = 0. * if abort is not equal zero, the update process will be canceled ABORT = 0. *$*$ end of routine - insert your code only before this line * ENDFORM. *-*
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-55
o n l y
FORM compute_data_field TABLES MONITOR STRUCTURE RSMONITOR "user defined monitoring RESULT_TABLE STRUCTURE /BI0/V0FIAR_C03T USING COMM_STRUCTURE LIKE /BIC/CS80FIAR_O03 RECORD_NO LIKE SY-TABIX RECORD_ALL LIKE SY-TABIX SOURCE_SYSTEM LIKE RSUPDSIMULH-LOGSYS ICUBE_VALUES LIKE /BI0/V0FIAR_C03T CHANGING RETURNCODE LIKE SY-SUBRC ABORT LIKE SY-SUBRC. "set ABORT <> 0 to cancel update * *$*$ begin of routine - insert your code only below this line *-* * fill the internal table "MONITOR", to make monitor entries * if the returncode is not equal zero, the result will not be updated RETURNCODE = 0. * if abort is not equal zero, the update process will be canceled ABORT = 0. *$*$ end of routine - insert your code only before this line * ENDFORM. *-*
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-56
Please refer to How To ... Disaggregate on upload within the appendix or at SAPNet Application scenario: the amounts of values of a cost center have to be distributed to the employes of the cost center because of the demand to report on employees basis. One record given from the communication structure has to be splitted to the number of employes of one cost center.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-57
If it is necessary to calculate the unit the generated routine differs maginal. ... (1) ... (2) ... Interface::
Globale data declaration within the header in the same way like in start routine and characteristics The form routine compute_data_field delivers following parameters: The table MONITOR for monitoring. Die Kommunikationsstruktur COMM_STRUCTURE mit allen Feldern aus der Datenquelle. The communication structure COMM_STRUCTURE with all fields from the data source. The current record number of the loop over the data package. The field SOURCE_SYSTEM delivers the logical system name of the data source. RESULT delivers to the marked characteristic the result value. UNIT delivers the value unit corresponding to the key figure RETURNCODE says wheather the current record will be processed or not ABORT clarfies wheather the whole data package will be processed or not.
o n l y
FORM compute_data_field TABLES MONITOR STRUCTURE RSMONITOR "user defined monitoring USING COMM_STRUCTURE LIKE /BIC/CS80FIAR_O03 RECORD_NO LIKE SY-TABIX RECORD_ALL LIKE SY-TABIX SOURCE_SYSTEM LIKE RSUPDSIMULH-LOGSYS CHANGING RESULT LIKE /BI0/V0FIAR_C03T-DEB_CRE_LC UNIT LIKE /BI0/V0FIAR_C03T-LOC_CURRCY RETURNCODE LIKE SY-SUBRC ABORT LIKE SY-SUBRC. "set ABORT <> 0 to cancel update * *$*$ begin of routine - insert your code only below this line *-* * fill the internal table "MONITOR", to make monitor entries * result value of the routine RESULT = . * result value of the unit UNIT = . * if the returncode is not equal zero, the result will not be updated RETURNCODE = 0. * if abort is not equal zero, the update process will be canceled ABORT = 0. *$*$ end of routine - insert your code only before this line * ENDFORM. *-*
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-58
Within the update rules the generated ABAP program is visible for analyse: menue Extras display activated program
All form routines of customer enhancements do get consecutive numbers First characteristics or key fields routine_000x, Then key figures or data fields r000x_<techn.NameKZ> The start routine always owns the name routine_9998
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-59
Useful Tips
Copy update rules
When creating new update rules you can work with the template of a different Info Provider: the start routine if existing and all other assignments are copied
Important: when the update rule runs one more record is added to the data target !! This is an alternative to the return table feature ...
F o r
o n l y
Debugging
(see chapter) All ABAPs are able to be debugged via the PSA data package simulation (or via the monitor) May be it is usefull to code a break-point for development reasons
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-60
Unit Summary
Now you are able to: Configure flexible InfoPackage selection with ABAP Delete equal or similar requests into an InfoProvider using ABAP Define with ABAP file and directory names for a flexible flat file upload Use start routines flexible Model transfer and update rules flexible with ABAP
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3-61
Exercises
Unit: Data Staging Topic: Flexible Selection
1-1
You want to fill an InfoCube with data from a flat file. 1-1-1 Create an InfoCube T_BC## with the description Cube Group ## under InfoArea BW Training BW/RIG Workshops ABAP Topics Backend Group ##. Copy the InfoCube T_BC00. Activate the InfoCube. 1-1-2 Create an InfoSource T_EXTERNAL_GR## with the description External Data GR## under the application component BW Training ABAP Topics Backend. Use the InfoSource T_EXTERNAL_GR00 as template. Select I_EXTERN IDES External Data in the Source System field and make the InfoObject 0COSTELMNT available for data selection in an InfoPackage. Activate the InfoSource. 1-1-3 Create update rules for your InfoSource T_EXTERNAL_GR## of your InfoCube T_BC##. Activate the update rules. 1-1-4 Save the flat file T_COSTCENTER_TRANS_2004002 to your local hard disk. You will find the file in the SAP menu under Office Folders Shared folders (TA SO04) TRAINING ABAP Backend Workshop.
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
1-2
The flat file contains data records with different cost elements. You only want to load certain cost elements in your InfoCube. In order to constrain the upload you use an ABAP for the data selection. 1-2-1 Create an InfoPackage for your InfoSource T_EXTERNAL_GR## with the description Flexible Selection GR##. Create an ABAP Routine for the selection of 0COSTELMNT with the description Cost element selection. Define an internal table that you fill with the following values: 1000632000 1000633000 1000634000 1000635000 1000636000 1000637000 1000638000 1000639000
o n l y
F o r
Insert the path of the flat file under the External data tab and make the following adjustments: Field Name or Data Type CSV file Data Separator Escape Sign Separator for Thousands Character Used for Decimal Point Number of Header Rows to be Ignored Values X ; . , 1
Save the InfoPackage and start the data load into your InfoCube immediately. 1-2-2 Check in the administration of your InfoCube if the upload was successful. How many data records were inserted into the InfoCube? Which values have the key figures?
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
2-1
You want to fill an InfoCube every month with transaction data from a flat file. The corresponding flat file will be available ever month in the same folder. The file name contains year and period. Therefore you want to use a flexible file path that changes automatically the filename of the flat file. 2-1-1 Create an InfoPackage for your InfoSource T_EXTERNAL_GR## with the description Flexible File Name GR##. Create an ABAP Routine for your file path under the External data tab with the description Flexible File Name. The routine should return the current file name with the correct suffix concerning year and period. Make the following adjustments: Field Name or Data Type CSV file Data Separator Escape Sign Separator for Thousands Character Used for Decimal Point Number of Header Rows to be Ignored Values X ; . , 1
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
Mark the radio button for deletion of the entire data target content. Save the InfoPackage and start the data load into your InfoCube immediately. 2-1-2 Check in the administration of your InfoCube if the upload was successful. How many data records were inserted into the InfoCube? Which values have the key figures?
3-1
You want to fill an InfoCube with data from a flat file. The flat file contains data records with the value type actual (VTYPE = 10) and plan (VTYPE = 20). The InfoCube should be filled only with actual data records. Therefore you create a start routine for the transfer rules. 3-1-1 Edit the transfer rules of your InfoSource T_EXTERNAL_GR##. Create a start routine for the transfer rules. The routine should delete all data records that have the value type 020 (Plan). Activate the InfoSource. Create an InfoPackage for your InfoSource T_EXTERNAL_GR## with the description Start Routine GR##. Insert the path of the flat file under the External data tab and make the following adjustments: Field Name or Data Type CSV file Data Separator Escape Sign Separator for Thousands Character Used for Decimal Point Number of Header Rows to be Ignored Values X ; . , 1
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
Mark the radio button for deletion of the entire data target content. Save the InfoPackage and start the data load into your InfoCube immediately. 3-1-2 Check in the administration of your InfoCube if the upload was successful. How many data records were inserted into the InfoCube? Which values have the key figures?
BEx-Variables
Contents:
Variables with processing type Customer Exit
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-1
After completing this unit, you will be able to : Use variables with processing type Customer Exit Give examples
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-2
3 5 BEx-Variables Reporting
InfoCubes / ODS & Master Data
2 ABAP Basics
InfoSource
o n l y
SAP BW Server
1 3 Data Extraction Extraction
F o r
i n t e r n a l
C S C
DB DB
R/3 R/3
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-3
One way to fill a variable value is to use ABAP-Coding. The following slides show you how. We can differentiate between two alternatives: 1. fill the value independently with a program 2. fill the value dependent on an other variable value.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-4
Default information: For filling variables the standard SAP Enhancement RSR00001is used. See example for details. There you find the include ZXRSRU01 to include further includes or your program directly The exit is called four times, called steps (I_STEP)
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-5
F o r
o n l y
Output
E_T_RANGE Variables Value Table
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-6
Default information: Step 1 (I_STEP = 1) is called before the processing of the variable pop-up and gets called for every variable of the processing type customer exit. You can use this step to fill your variable with a default or proposal value. Step 2 (I_STEP = 2) is called after processing of the variable pop-up. This step is called only for those variables that are not marked as ready for input and are set to mandatory variable entry. Step 3 (I_STEP = 3) is called after all variable processing and gets called only once and not per variable. Here you can validate the user entries. Step 0 (I_STEP = 0) is called for variables which are used in authorizations objects.
SAP AG 2003
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-7
Depending on the variable type, the fields LOW, HIGH, SIGN and OPT of the internal table E_T_RANGE must be filled as follows and it is the same as in a selection option: LOW Single value or lower interval limit (characteristic variable) Text (Text variable) Formula value (Formula variable) Hierarchy name (Hierarchy variable) Hierarchy node (Hierarchy node variable)
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-8
Depending on the variable type, the fields LOW, HIGH, SIGN and OPT of the internal table E_T_RANGE must be filled as follows: HIGH Upper interval limit (char. variable with interval) InfoObject of the hierarchy node (hierarchy node variable): when selecting a sheet in the LOW field this field must remain empty when selecting a node that cannot be posted into the LOW field, the referred InfoObject, has to be filled in this field (usually here the InfoObject '0HIER_NODE'). Only if the node refers to another InfoObject than the variable, the name of the other InfoObject must appear here. HIGH remains empty for other variable type.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-9
Depending on the variable type, the fields LOW, HIGH, SIGN and OPT of the internal table E_T_RANGE must be filled as follows: SIGN I (inclusive) or E (exclusive) E only makes sense with intervals, otherwise I is always used OPT EQ with single values With intervals: BT or NB.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-10
Please note that you cannot overwrite the user input values into a variable with this customer exit. You can only derive values for other variables or validate the user entries.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-11
Business Scenario:
The business department wants to check if the orders from the customers for a certain week (e.g. 6 weeks from now) are already transmitted into their system. Therefore they run a report with a variable, that is calculated automatically. Note: Of course this is not the only suitable solution, but it will show you how the exit works.
Step by Step Solution: You should create a variable on the info object 0CALWEEK like this: Technical Name: WS_FWEEK Description: Workshop Future Week Interval Mandatory variable entry Processing: Customer Exit NOT ready for input
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-12
Call transaction CMOD for the definition of the customer exit. Create a new project, maintain the short text and assign a development class. Go to Enhancement Assignments and assign RSR00001. Press the button components to continue. Double-click on EXIT_SAPLRRS0_001. For documentation place the cursor an RSR00001 and use the menu GoTo => Display documentation. Then double-click on ZXRSRU01. If the include does not exist, you have to create it; assign a development class and a transport request.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-13
*---------------------------------------------------------* * INCLUDE ZXRSRU01 * *---------------------------------------------------------* data: l_idx like sy-tabix, workdate(8) type d, futureweek(6) type c. DATA: L_S_RANGE TYPE RSR_S_RAGESID.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-14
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-15
Save and activate the coding. Activate the project. (Very important!) Define a query using the above created variable. For displaying the variable values in the executed query you also may define two text variables. These should, if necessary, be able to show the lower and the upper value calculated by the customer exit.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-16
Example for filling variable values depending on an other variable / Deriving one variable value from another variable Business scenario. A query should show in one column the value for one period. The period should be entered by the user. In the second column the accumulated vale from the beginning of the year to the period of the first column should be displayed. The InfoCube contains only the InfoObject 0CALMONTH (Month/Year) and not single InfoObjects for period and year. Solution: For this scenario we need four variables: two variables for the column text and two variables for the period values. One of these period variables is defined as a variable with a customer exit.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-17
Step by Step Solution: Create an input variable MONTH (you need this specific information for the coding example below). The variable is based on the InfoObject 0CALMONTH. Set the following attributes: Single Value Ready for input Mandatory variable entry
b y
C S C
Create a variable CUMMONTH (you need this specific information for the coding example below) with a customer exit as a processing type. The variable is based on the InfoObject 0CALMONTH. Set the following attributes: Interval NOT ready for input! Mandatory variable entry Create two text variables. Both variables use the Replacement Path as processing type. The first text variable is filled with the text from the from value. The second is filled with the text from the to value.
o n l y
F o r
i n t e r n a l
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-18
o n l y
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-19
Save and activate the coding. Activate the project. Define a query containing all the variables.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-20
You should now be able to: Use customer exits with variables
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
4-21
Exercises
Unit: BEx Variables
1-1
You want to create a report for your InfoCube that should display cost center, cost element and amount. For amount should be displayed values for year chosen by the user and for the year before. For the determination of year before use a User Exit. 1-1-1 Open the BEx Analyzer and create a new query BEXVARGR## with the description BEx-Variable GR## for the InfoCube T_BC00. Insert T_05C00 and Cost Element in Rows. Create a restricted key figure at the query level for Amount restricted to Fiscal year. In order to restrict Fiscal year create a variable YEARGR## with the description Year Input GR## for user entry. Create another restricted key figure at the query level for Amount restricted to Fiscal year. In order to restrict Fiscal year create a further variable YEXIT## with the description Year with Exit GR## for a User Exit. For creation of the User Exit use transaction CMOD and project RSR00001. Implement your coding in the function module ZEXIT_VAR_GR##. The Exit should return the year before the year chosen by user entry. Save and activate the function module 1-1-7 Save and execute the query. Check if the values and variables are filled correctly.
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
Contents:
BAdI RSR_OLAP_BADI
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-1
After completing this unit, you will be able to: Use the BAdI RSR_OLAP_BADI
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-2
3 5 BEx-Variables Reporting
InfoCubes / ODS & Master Data
2 ABAP Basics
InfoSource
o n l y
SAP BW Server
1 3 Data Extraction Extraction
F o r
i n t e r n a l
C S C
DB DB
R/3 R/3
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-3
Standard deviation formulas are calculated for variable versions and fiscal years Calculation in the query is too complex because the formula needs to be calculated on a fixed granularity (often more detailed than the query) Calculation in the Administrator Workbench is too inflexible because there are too many combinations of years and versions Warning: This exit is very powerful but can cause huge performance problems
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-4
A virtual characteristic or a virtual key figure is an InfoObject which is defined within the InfoProvider as meta data without having any data stored physically.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-5
F o r
o n l y
b y
C S C
InfoCube T_ABAP_VT
OLAP-Processor
i n t e r n a l
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-6
Historical Background
The BAdI RSR_OLAP_BADI replaces the user exit RSR00002 with following advantages:
easier to implement, different classes for different InfoCubes/implementations, no large includes.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-7
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-8
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-9
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-10
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
Transaction SE19
C S C
o n l y
F o r
SAP AG
PDEBWB
5-11
o n l y
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
You can also enter multiple InfoProviders or use Wildcards to select the InfoProviders It is highly recommended to copy the sample code via Goto -> Sample Code -> Copy. The sample code can only be copied before the implementation is activated!
C S C
o n l y
F o r
SAP AG
PDEBWB
5-12
Creating a BAdI implementation Implementation of the DEFINE method Implementation of the COMPUTE method
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-13
Fill InfoProvider
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-14
FLT_VAL: Filter values for the InfoProvider as defined in the BAdI I_S_RKB1D: General informations about InfoProvider and Query. Most useful are the fields InfoCube and COMPUID or GENUNIID for identifying the query I_TH_CHANM/KYFNM_USED: List of the Characteristics/ Key Figures used in the query C_T_CHANM/KYFNM: List of Characteristics/Key Figures used for calculation in the BAdI. Must be filled in this method.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-15
Sample Implementation
Fill the mode accordingly Fill this table with virtual chars Fill this table with virtual key figures
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
You can select the InfoCube in case you did not restrict the BAdI Implementation to only one cube You only need to provide the mode for characteristics There are two modes: - no_selection: This mode is used for virtual characteristics. The value is not read from the database. - read: The value is always read from the cube, even if it is not used in the query. Example: You need to get prices for materials but the query runs on material group level.
C S C
o n l y
F o r
SAP AG
PDEBWB
5-16
The DEFINE method is only executed when the query is generated So any changes to class attributes are NOT available in the COMPUTE method (i.e. no initialization of data)
o n l y
To debug the DEFINE method use the Generate Report button in the transaction RSRT
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-17
Additional Attributes
You should add a public instance attribute P_CHA_<IOBJECT> for each InfoObject you want to access in the COMPUTE method (real or virtual) and a public instance attribute P_KYF_<IOBJECT> for each key figure you want to use. These attributes should be of type I. In the COMPUTE method these attributes are filled the following way:
Value = 0 InfoObject is not used in the query. Value > 0 Position of the InfoObject in the structure C_S_DATA
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-18
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-19
o n l y
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-20
FLT_VAL, I_S_RKB1D: As in the DEFINE Method I_PARTCUBE: At MultiProviders partial cube for that the values are calculated I_NCUM: Non-cumulative Value C_S_DATA: Data structure of the InfoProvider. Should be filled in the method. You can best access the structure by using the attributes P_CHA_<characteristic> and P_KYF_<characteristic>. They are defined as Integer values and are filled at the moment of calling the method. If the value is larger than 0, the number means the position of the field in structure C_S_DATA.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-21
Sample Implementation
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
P_CHA_<characteristic> is an integer variable that contains the position of the element in the structure c_s_data. The global attribute currdate of the class ZCL_IM_CURRCONV1 must be filled at step 2 of the variable enhancement RSR00001. The best way to debug the method is to use transaction RSRT.
C S C
o n l y
F o r
SAP AG
PDEBWB
5-22
Potential risk
The Method is called once per record that is read from the cube. This can lead to huge performance problems during query execution. To avoid this keep the following things in mind:
Avoid Selects if possible The mode READ may add additional InfoObjects to the query so that old aggregates do not work anymore l_s_chanm-mode READ lowers the detail niveau of characteristics unvisible to the user result of this is that existing aggregates can not be used eventually performance reduction You only get access to one record at a time
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-23
Unit Summary
You should now be able to: Implement the BAdI RSR_OLAP_BADI Compute Virtual Characteristics Compute Virtual Key Figures
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
5-24
Exercises
Unit: Virtual Characteristics and Key Figures
At the conclusion of this exercise, you will be able to: Implement the BAdI for Virtual Characteristics and Key Figures
In this exercise you will define a virtual characteristic to filter values depending on your user name.
F o r
o n l y
i n t e r n a l
C S C
1-1
Implementing the BAdI 1-1-1 Create the BAdI ZT_VT_GR## with the definition RSR_OLAP_BADI. Give it the short text: Virtual Characteristics Group XX 1-1-2 Restrict it to the InfoCube T_VT_GR##. 1-1-3 In the DEFINE method enter the following coding:
* characteristic l_s_chanm-chanm = 'T_FLAG'. l_s_chanm-mode = rrke_c_mode-no_selection. APPEND l_s_chanm TO c_t_chanm. l_s_chanm-chanm = 'T_COUNT'. l_s_chanm-mode = rrke_c_mode-read. APPEND l_s_chanm TO c_t_chanm.
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
1-1-4 Create two attributes P_CHA_T_COUNT and P_CHA_T_FLAG in the class ZCL_IM_T_VT_PR## as static instance attributes of type I. Change the implementation of the COMPUTE method. Enter the following coding:
field-symbols: <l_count> type /bic/oit_count, <l_flag> type /bic/oit_flag. if P_CHA_T_COUNT > 0. assign component P_CHA_T_COUNT of structure C_S_DATA to <l_count>. endif. if P_CHA_T_FLAG > 0. assign component P_CHA_T_FLAG of structure C_S_DATA to <l_flag>. endif. if <l_count> <= sy-uname+6(2). <l_flag> = 'X'. else. <l_flag> = ' ' . endif.
F o r
o n l y
i n t e r n a l
b y
C S C
1-1-4 Activate all objects. 1-2 Test the BAdI 1-2-1 Go to the Query designer and build some reports. List the fields T_COUNT, T_FLAG and T_NUMBER 1-2-2 Filter the value T_FLAG. Try the values X and . 1-2-3 Remove T_COUNT. The sums dont change even if there are less rows. Note That the values are different for each user. You could use this technique to implement complex user-specific filters
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
Contents:
Types of user exits in BW-BPS (Business Planning and Simulation) Creating and using planning functions type exit in BWBPS
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
After completing this unit, you will be able to : Know the different types of user exits in BW-BPS Understand the prerequisites of planning functions in BW-BPS Create a planning function type Exit in BW-BPS and use it
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
3 5 BEx-Variables Reporting
InfoCubes / ODS & Master Data
2 ABAP Basics
InfoSource
o n l y
SAP BW Server
1 3 Data Extraction Extraction
F o r
i n t e r n a l
C S C
DB DB
R/3 R/3
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
Overview of BW-BPS
Modeling of Planning Structures Planning Framework
Multidimensional business structures Definition of work packages Hierarchy maintenance Version management User authorizations Variable handling
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
Planning in BW-BPS comprises four major areas: In Modeling the data model of a planning process is defined. That includes how the planning process will be set up in regards to business structure (slice and dice) and planning strategy (e.g. bottom-up, top-down, counter-current). Planning functions are operations that support the automatic processing of plan data (e.g. copying, forecasting, ...) in a simulative fashion or embedded in batch processing. Planning layouts in manual planning allow to set up the context of entering plan data for different users. Planning interfaces consist of one or many planning layouts together with planning functions to support the planner with the planning task. In order to coordinate the sequence of the planning process a planning tasks may be assigned to the planners and the status of the planning accomplishments can be tracked over the cycle of a planning session.
C S C
o n l y
F o r
SAP AG
PDEBWB
Company
Foods Union Beverages NonAlcohol Juice
F o r
o n l y
i n t e r n a l
C S C
Orange J.
Apple J.
b y
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
Planning is usually executed along organizational structures. Different planners are viewing and changing data on different levels of granularity. These levels of granularity correspond to the levels in the hierarchy of the organizational structures. When modeling the planning process this hierarchy must be materialized in the planning system. The BW-BPS uses InfoCubes as a data storage. So-called planning levels define the fixed levels of aggregation in the InfoCube. Thus the organizational structures correspond to a set of planning levels. On the slide we see an example of an organizational structure in the sales organization of a company that is selling food products. The planning in the company is done on the different levels defined by the organizational structure there are planners for the different products (like Orange Juice and Apple Juice) for different product groups (Juice and Water), for different business units (Non-Alcohol and Alcohol) etc. We will use this hierarchy for showing how such a planning process can be modeled in the BW-BPS and by doing so will learn about the different components of the BW-BPS.
C S C
o n l y
F o r
SAP AG
PDEBWB
Planning Method
Parameter Group Parameter Group
o n l y
Database for planning models Detail Screen Corresponds to one or more InfoCubes Determines the characteristics and key figures for planning
F o r
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
The planning area is the base for planning models. In the planning area all organizational structures and planning tasks related to a specific planning process can be set up. It corresponds to one InfoCube (Basic Planning Area) or multiple InfoCubes (Multi-Planning Area) and may be seen as an enhancement of the InfoCube in order to be able to plan. The InfoCube includes all characteristics and key figures that are relevant in the planning process. The InfoCube we use in our example contains the characteristics country, version, year and period (and fiscal year variant), product, and product line. The key figures are quantity, price, and revenue. The planning area comprises: Attributes (of planning area) Connection to BW via InfoCubes Data Slices Locking of specific characteristics against changes Variables Master data all characteristics and key figures of the corresponding InfoCube Characteristic relationship procedures to check, derive or propose valid combinations of characteristic values.
C S C
o n l y
F o r
SAP AG
PDEBWB
Detail Screen
Planning Method
Parameter Group Parameter Group
Slice of the InfoCube Includes selection of characteristics and characteristic values Carrier of planning methods
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
Planning levels determine the granularity on which data is planned. They also may be used to define the hierarchical orders of the planning model. In our example a planner who is responsible for planning on products uses a planning level that contains the characteristics country, year (and fiscal year variant), version, product and product group. A planner who is responsible for planning on the product group uses a different planning level that contains country, year (and fiscal year variant), version, and product group. Planning functions (automatic planning) and planning layouts (manual data entry) are depending on exactly one planning level. In addition planning levels may include selections of characteristic values (e.g. product group: water, juice) The flag "Selection in package" determines whether characteristic values are selected in the planning level or in the planning package (e.g. for personalization) Selection of characteristic values in the planning level is used when the same selection applies to several planning packages. (e.g. fiscal year: 2010 is to be planned by all planners) Selection of characteristic values in the planning packages is used when different selections are needed on one planning level (e.g. one planning package for product Orange Juice another planning package for product Apple Juice)
C S C
o n l y
F o r
SAP AG
PDEBWB
Detail Screen
Planning Method
Parameter Group Parameter Group
Subset of the planning level Selection of characteristic values Work package for one user or a group of users
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
The planning package is a subset of the planning level (requires setting "selection in package" in planning level) Planning packages are always assigned to exactly one planning level. One planning level can contain several planning packages. Individual restrictions can be made using a planning package (e.g. single product according to responsibility) for personalization If no planning package specific selection is necessary (full selection on the planning level, personalization using variables), at least an Ad-hoc-package must be created. In order to execute a planning method, the selection of a planning package is mandatory.
C S C
o n l y
F o r
SAP AG
PDEBWB
for changing
Planning Method
Parameter Group Parameter Group
o n l y
F o r
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
Planning methods cover the different ways how data may be generated or manipulated using BWBPS Manual planning comprises the planning layouts that are used for manual data entry. Planning functions are methods that automatically change data. BW-BPS delivers generic planning functions that range from copying, distributing, deleting and others to a formula builder which can be used to create calculations according to a companys individual business rules without needing any ABAP programming. Planning functions are two-fold: the planning function and parameter group(s). The planning function defines the basic settings of the function (what characteristics and key figures are the basis for the function?) e.g. Datasets shall be copied from version 1 to version 2, then the planning function will get the information, that version is the basis for the copy. The parameter group defines, which values should be used to execute the planning function and which conditions are applicable. For the copy that would mean from version 1 to version 2. The separation of planning function and parameter groups allows to reuse planning functions for multiple purposes (e.g. one parameter group to copy from version 1 to version 2, another parameter group to copy from version 2 to version 3)
C S C
o n l y
F o r
SAP AG
PDEBWB
All techniques for changing plan data automatically E.g.: Copy, Top-Down, Revaluate, Detail Screen Exit
Planning Method
Parameter Group Parameter Group
o n l y
Defines all the parameters of a Function E.g.: Copy version 100 to version 200
F o r
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
Planning functions change the transaction data in a planning package. Each planning function is assigned to just one planning level. There are various types of planning function (for example: exit, copy, distribute, delete, formula). Parameter groups are created for a planning function. All Planning Functions are generic, which means, that the business logic has to be given by the person, which customizes it. Generally speaking you create an input mask, defining the planning function, by addressing fields to the "fields to be changed". Then, within the parameter group you will then have to fill in the concrete rule in the input mask you created within the planning function itself. After that, the planning function is executed by double-clicking the planning package and the parameter group. If you use a planning function type Exit you do not have predefined masks for the parameter group. You ca define parameters for your Exit yourself but you do not have to do so. Nevertheless you always need a (potentially empty) parameter group for execution of the planning function.
C S C
o n l y
F o r
SAP AG
PDEBWB
10
Amount 400
New Record
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
In BW-BPS data can be created on any aggregation level of an InfoCube e.g. the InfoCube includes the characteristics product group and product a user can enter data on the aggregated level (product group) or on a detailed level (product group, product). If the data is entered on a detailed level it can always automatically be aggregated. If the data is entered on an aggregated level it can either be distributed to a more detailed level or just stay on the aggregated level. If data remains on an aggregated level, it is "not assigned" to some details (e.g. product) Not assigned values may be distributed to detailed planning levels using distribution functions or manual assignment. The example illustrates these effect The InfoCube in the example includes the characteristics product group, fiscal year and the key figure amount. First table: The planning level contains product group, fiscal year and amount, the planning package is restricting the characteristic values for product group to water and juice and the fiscal year to 2010
C S C
o n l y
F o r
SAP AG
PDEBWB
11
Second table: The planning level contains fiscal year and amount only and shows the aggregated amount entered in the first table. The amount is changed. Third table: The planning level contains product group, fiscal year and amount, the planning package is restricting the characteristic values for product group to water and juice and the fiscal year to 2010. As a change was made on an aggregated level, there is an "unassigned value" (#) remaining regarding the product group. The possible next step would be to decide whether the unassigned value should be distributed to the different product groups or remain on unassigned.
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
12
Detail Application
BW-BPS
Read Data Write Read Data Data Write Read Data Data Write Data
Change Data
Planning Buffer
Read Data Save Data
o n l y
BW Data Warehousing
F o r
b y
C S C
InfoCube
SAP AG 2005
i n t e r n a l
u s e
u s e
i n t e r n a l
b y
Planning methods in BW-BPS work on data which is temporarily stored in a buffer called planning buffer Each user who works in BW-BPS writes data into a personal buffer All data in the buffer is locked against changes by other users. Whenever a planning function is called, subsets of data are used from the buffer. If they are not already in the buffer, the data is called from the transactional InfoCube. The subsets that are called into the buffer depend on the data selection of the planning package and the planning function. (e.g. package includes countries Germany and Spain but the planning function only changes or creates data for Spain, then only a subset including Spain is called into the buffer. Whenever a user chooses to save data is written into the InfoCube. In order to do so, deltas are calculated. Even when a save of the data was carried out the data remains in the planning buffer. Only upon leaving of the planning application the data is released from the buffer and available for changes by other users.
C S C
o n l y
F o r
SAP AG
PDEBWB
13
Exits in BW-BPS
All exits are realized via Function Modules. Whenever data records of the InfoCube are manipulated (planning function, derivation) or the characteristics in the data records (combination check, create combination) dynamic structures are used. Thus any access has to be done using field symbols.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
A variable type exit is defined via a function module that is returning a selection table. Upon runtime the variable will be replaces by this selection. Variables in BW-BPS can be used in the data selection, the definition of planning function, and the definition of planning layouts. Characteristic relationships are used to model the relationships between characteristics. They can be used to control that only valid characteristic combinations are written to the InfoCube. E.g. a characteristic relationship between product groups and products assure that every record that contains a juice product (e.g. Orange Juice) is booked to the product group Juice. Any water product will be booked to the product group Water. Characteristic relationships are defined in the planning area and thus hold for all planning levels. Depending on which characteristics are selected in the planning level the system fills in missing characteristic values automatically (so-called derivation), or creates all possible entries as a template for the manual planning or checks all new records created by the user. Planning functions of type exit can be used to create new records, change existing records, or delete existing records. We will concentrate on planning functions in this workshop.
C S C
o n l y
F o r
SAP AG
PDEBWB
14
Purpose: Used for changing key figures (and potentially updating characteristic values). Function exits contain a main function module (always executed when the planning function is started) and optionally an initialization function module. The fields which you want to change through the exit must be declared in the fields to be changed.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
Definition of fields to be changed: characteristics whose values you wish to change in the planning function . Notes: In a planning function type Exit you can change any key figure. You can only change the characteristics that are in the fields to be changed You can only use characteristic values that are in the selection of the package All characteristics that are not in the fields to be changed are use to partitionate the data upon execution of the planning function (subsets see later). Performance: The more fields are changed, the slower becomes the function.
C S C
o n l y
F o r
SAP AG
PDEBWB
15
Before
4.
F o r
o n l y
After
i n t e r n a l
C S C
Field(s) to be changed
SAP AG 2005
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
16
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
Before a planning function is executed the selected data is cut into smaller sets of records called subsets. The planning function will be executed several times, once for each subset. The data from the package is grouped by the characteristics that are contained in the planning level but not in the fields to be changed: within a subset all records have the same characteristic values for those characteristics. Characteristics that are not in the planning level can be ignored. Reason for building subsets: facilitates the coding of planning functions and Fox formulas. Note You cannot rely on the sort order of the subsets! Do not implement coding on the sequential order in a formula or exit function.
C S C
o n l y
F o r
SAP AG
PDEBWB
17
Data Selection Build Subsets from Selected Data Phase 1 Call INIT Function Add Subsets Returned by Init Function FOREACH Subset. Phase 2 Call EXIT Function ENDFOR. End of Execution
SAP AG 2005
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
When an exit function is executed, the system retrieves the data defined by the planning package. The data is read either from the InfoCube or from the buffer, but the developer does not have to worry about this. In the first phase, the system builds subsets of the selected data. The process of the the subsets creation depends on the "fields to be changed" setting in the definition of the exit function. How many subsets are created depends on the "fields to be changed" and the selected data. Note Subsets will be created only for existing data! Now the system calls the INIT function. Preliminary work like reading reference data or selecting from a database table should be implemented here. Optionally, you can return additional subsets. This way you can make sure that the main EXIT function is called for a subset. In the second phase, the main EXIT function is called once for each subset.
C S C
o n l y
F o r
SAP AG
PDEBWB
18
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
You create a planning function type exit by creating a function module (the exit module) that has a predefined interface (a template can be found in the function group UPFX). The function module receives a data table. You can create, delete or change existing records. The planning function is called with several subsets. You have to make sure that you only create records that are contained in the current subset. In order to use a planning function type exit you have to create it in the planning framework (BPS0), specify the fields to be changed and enter the name of your function module. The most important parameters of the interface are: Area, level, method, package, parameter group The selection of the current subset ito_charsel The actual data table (containing the existing data) - xth_data
C S C
o n l y
F o r
SAP AG
PDEBWB
19
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
20
Loop at xth_data into <ls_data>. assign component S_KYFS-0AMOUNT of structure <ls_data> to <l_amount>. <l_amount> = <l_amount> * 2. Endloop.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
There is a second way to access the data in the xth_data table. You can define the type of the field symbols before the loop. Thus the assigns are executed only ones instead of in each loop. This is faster if you are accessing many fields in the structure of xth_data:
C S C
Data: lr_data type ref to data. field-symbols <ls_data>. create data lr_data like line of xth_data. assign lr_data->* to <ls_data>. [...] assign component: 'S_CHAS-0FISCYEAR' of structure <ls_data> to <0FISCYEAR>, 'S_CHAS-0VERSION' of structure <ls_data> to <0VERSION>. [...] Loop at xth_data assigning <ls_data>. [..do something with 0Version and 0Fiscyear..] Endloop.
SAP AG
o n l y
F o r
PDEBWB
21
Copy template function module Implement desired functionality. Create a planning function
i. ii. iii.
Locate planning level Add function module as planning function of type Exit Create a parameter group
F o r
o n l y
4.
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
Create the function module: Call transaction se80. Navigate to function group UPFX. Copy the function module TEMPLATE_EXIT to the function module Z_PF_DELETE in the function group ZTRAINING. Open the new function module. Enter the coding clear xth_data. Save and activate the function module. Create the planning function: Enter the Planning Workbench (transaction BPS0). Expand the planning area Workshop PDESE1 (TRAINER) (PDESE1), double-click on the planning level Copy, vol*price Exit (LEV14). In the lower tree do a right mouse click on the name of the planning level and choose Create Planning Function. Enter a name, a technical name and choose the type Exit-Function from the tree. Enter the name of the function module (Z_PF_DELETE) into the field Function module. Create a parameter group by using the context menu on the name of your exit function in the lower tree on the left. Enter a name and a technical name.
SAP AG
C S C
o n l y
F o r
PDEBWB
22
In order to view the existing data in the InfoCube double click on the Ad-hoc package, expand the node Manual Planning and double click on the layout Enter volume (LAY1). In order to run the planning function double click on the parameter group. You will see that the data is deleted. Save your changes in the customizing but not the changes in the data: In the menu choose Planning and then Save model. Leave the planning workbench by choosing Cancel.
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
23
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
The Init module receives information about the environment it is called from such as the planning area, level, package, function, and parameter group. New subsets can be generated by filling the table xth_chas. The underlying structure of the table consists of all characteristics in the InfoCube. It is the same structure used as S_CHAS in the table xth_data. If a subset should be generated then it is enough to fill in one characteristic combination that would be contained in the subset.
C S C
o n l y
F o r
SAP AG
PDEBWB
24
Function modules are always created within a function group. Function groups have a top include. Every programming variable defined in there is shared between the function modules of the function group. To pass data from the Init module to the Exit module:
Define a global variable (field, structure, table) in the top include of the function group. Fill the variable in the Init module. Use the information in the Exit module.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
25
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
Example: In our exercise we had a copy function that was copying from the actual version (A00) to some plan version (P03). The plan version is hard coded in the ABAP coding. To make the planning function more flexible the target version could be specified in an exit parameter in the parameter group. In the coding the value of the exit parameter can be found in the table it_exitp and then used as a copy target. Example 2: The standard copy function can either add to existing values or overwrite existing values. There is an example in the system how this behavior can be realized in an Exit using exit parameters: Area PDESE1 Planning level: LEV14 Planning Function EXIT2: Exit Copy with Parameters.
C S C
o n l y
F o r
SAP AG
PDEBWB
26
You should now be able to: Know the different types of user exits in BW-BPS Understand the prerequisites of planning functions in BW-BPS Create a planning function type Exit in BW-BPS and use it
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2005
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
27
Exercises
Unit: Virtual Planning Functions Type Exit
At the conclusion of this exercise, you will be able to: Implement a planning function of type Exit to copy your plan data
o n l y
In this exercise you will create a function module, which provides the functionality of the planning function. Subsequent, you will assign this function module to a planning level, and test your planning function. Optionally, you
F o r
i n t e r n a l
C S C
Create a simple planning function type Exit that copies data from the actual version A00 to the plan version P03. 1-1 Create a new function group and copy the function module TEMPLATE_EXIT to the function module Z_BPS_COPY_xx where xx is the number of your group. 1-2 In your coding create the necessary field symbols, read the entry with the version A00, change the version and update the data table. Note Be aware that there are already existing some records for the plan version (the planning function should overwrite them). 1-3 How many records will you find in the table xth_data (keep in mind which fields will be chosen as fields to be changed and how the subsets will be formed)? 1-4 Enter the planning workbench (TCODE BPS0) and choose your planning area (Workshop PDESE1 Group xx/PDESE1xx) 1-5 Create a planning function type Exit using your function module. Use the planning level vol*price (LEV7). 1-6 Which characteristic(s) have to be chosen as field(s) to be changed? 1-7 Check that the selection contains all necessary data, i.e. the versions A00 and P03.
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
1-8 Start the layout Copy version (LAY3) to check/change the existing data. 1-9 Run your planning function and check the results. Solution for 1-3: you will find either one or two records in each subset. As you are only changing the versions this is the only characteristic that should be in the fields to be changed. The data is grouped by all other characteristics (subsets!). There is some data in the actual version for each combination of country, year, product and product group that is in the selection. Thus you will see at least one record. A second record is contained if some data for the plan version also exits. Hint Find a solution for the exercise in planning area PDESE1, LEV14, EXIT3. The name of the function module is PDESE1_COPY_EXIT. The exact menu paths are described in the notes of the slide Planning Functions Type Exit Example.
o n l y
[Optional Exercise] Create a planning function type exit that calculates the revenue for each product from the price and the sold volume. 2-1 The prices are actual prices that are already stored in the system. As the price for a product is independent of country the prices are stored in country #. The prices (key figure Z_PRICE) are stored in version A00. 2-2 In the planning level LEV7 the sales volumes (key figure T_QUANT) are entered by the users in the version P03. The revenue (key figure ZBPS_REV) should also be stored in version P03. 2-3 Create your planning function in planning level LEV7. When deciding which characteristics should be in the fields to be changed remember that the prices and the volumes must be contained in the same subset. Note As the prices and the volumes must be in the same subset and as the records only differ in the characteristics version and country. Thus, these two characteristics must be in the fields to be changed. All the other characteristics need not be chosen as fields to be changed. 2-4 Run your planning function and check the results. Use the Check calculation layout of the Mannual Planning to check your results (has revenue as column included). Hint Find a solution for the exercise in planning area PDESE1, LEV14, EXIT3. The name of the function module is PDESE1_PRICE_CALC. The sequence of steps is the same as for exercise 1. The exact menu paths are described in the notes of the slide Planning Functions Type Exit Example.
F o r
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
F o r
i n t e r n a l
u s e
b y
C S C
o n l y
F o r
i n t e r n a l
u s e
b y
C S C
o n l y
Contents:
Process Chains Insert Process ABAP Program Implementing new Process Types
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-1
After completing this unit, you will be able to: Describe concepts of process chains Insert the process ABAP Program Implement new process types
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-2
3 5 BEx-Variables Reporting
InfoCubes / ODS & Master Data
2 ABAP Basics
InfoSource
o n l y
SAP BW Server
1 3 Data Extraction Extraction
F o r
i n t e r n a l
C S C
DB DB
R/3 R/3
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-3
Maintain process chains in RSPC Maintain process types under Settings -> Maintain Process Types in RSPC and create class under Tools -> ABAP Workbench -> Development -> Class Builder
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-4
Process Chains Insert Process ABAP Program Implementing new Process Types Example
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-5
Start
Activate Data in ODS
Roll up Aggregates
F o r
o n l y
Build DB Statistics
i n t e r n a l
C S C
Build Indices
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-6
Drop IC Indices
Failure?
Email System Admin
Success?
Data Load A
Data Load B
o n l y
Failure?
Email System Admin
Failure?
F o r
C S C
i n t e r n a l
b y
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-7
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-8
Process Chains Insert Process ABAP Program Implementing new Process Types Example
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-9
1.
2.
F o r
o n l y
1. 2.
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-10
Create Variant
1.
2.
F o r
o n l y
1.
Create new process variant: Technical Name and description Maintain process variant
i n t e r n a l
b y
C S C
2.
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-11
Programs with or without variants Predefined events of the application or events you defined yourself. The background processing system receives events (signal stating that a predefined status has been reached) and then starts the job.
F o r
o n l y
i n t e r n a l
C S C
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-12
The process chain waits for the program to end before it starts with possible successors. Errors can be handled, logs can be written.
The process chain maintenance does not equate the end of the process with the end of the background process. The process status remains active. Successor events are not automatically triggered! You need to call RSPC_ABAP_FINISH at the end of the program to signify the real end of your process.
F o r
o n l y
b y
C S C
Start remote programs by synchronous, local programs. This allows you to monitor your process with the process chain maintenance.
i n t e r n a l
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-13
2.
3.
F o r
o n l y
4.
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-14
2. 2.
Define event
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-15
Write logs by outputting success messages Function RSPC_ABAP_FINISH to report the end Destination for function is the BW server
DESTINATION BWP_100'
EXPORTING I_VARIANT
= 'SYSMSGEXTERN'
o n l y
b y
C S C
EXCEPTIONS ALREADY_FINISHED =1 OTHERS =2 . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.
F o r
i n t e r n a l
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-16
Process Chains Insert Process ABAP Program Implementing new Process Types Example
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-17
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-18
F o r
o n l y
i n t e r n a l
C S C
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-19
Interfaces:
EXECUTE GET_INFO GET_LOG MAINTAIN GET_VARIANT
GET_DEFAULT_CHAIN
Maintainance
Runtime
Log View
X X X X X X X X X X X X X X
X X X X X X X X X X X
o n l y
F o r
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-20
Generic Services
There are several services in Paket RSPC which shall help you implementing a process type
Generic variant storage class: CL_RSPC_VARIANT Generic dynpro service for variant maintainance: Function module RSPC_VARIANT_MAINTAIN Generic instance storage class: CL_RSPC_INSTANCE Wrapper class for application log for unambigous assignment of logs to instance CL_RSPC_APPL_LOG Service function group: RSPC_SERVICES
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-21
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-22
Variant (re)-naming Variant documentation link Transport link Last changed by Navigation through variants Creation of new variants Deletion of variants
You provide a subscreen and a form-routine, which checks for changes on the subscreen Ok-Codes, which you must react on in PAI of your subscreen: SAVE: Save the variant EXIT, BACK and CREA: Check if something has changed, and eventually save the variant
SAP AG 2003
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-23
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-24
Process Chains Insert Process ABAP Program Implementing new Process Types Example
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-25
Example
(Transactional) InfoCube for Plan and Actual data Dedicated InfoCube for Reporting
InfoCube for reporting
1.
o n l y
Switch the Planning InfoCube from Planning enabled to Load enabled (the open request is automatically closed, planning is not possible) Data update Switch the InfoCube back to Planning enabled
Planning data
F o r
2. 3.
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-26
Example
Switch data source to BW
REPORT ZTEST. REPORT Z_SWITCH_BATCH_TO_TRANS. * Close open request and switch data source CALL FUNCTION 'RSAPO_SWITCH_BATCH_TO_TRANS' EXPORTING I_INFOCUBE = 'T_ABAP01' EXCEPTIONS CUBE_NOT_TRANSACTIONAL = 1 INHERITED_ERROR = 2 OTHERS = 3 . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-27
You should now be able to: Describe concepts of process chains Insert the process ABAP Program Implement new process types
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
7-28
Exercises
Unit: Process Chains customer defined process type
At the conclusion of this exercise, you will be able to: Implement your own process type Implement an ABAP OO class, which contains the functionality of your own process type Make the settings for a new process type Include the new process type in a process chain A file is posted from some subsidiary to a specified folder on your application server. You know, that it will be posted on a certain day, but do not know the time it will arrive. Your customer-defined process type looks for the file itself and if found returns a Green status. If the file is not found, it returns a Red status. The filename and path is hard-coded. Note: The source code for the process type can also be found as attachment of a mail in the SAP Office (TCODE SO04 Shared folders Training ABAP Backend Workshop Process Chains) 1-1 Implement the class of the process type 1-1-1 Create a new class named ZCL_PC_EX_<group> (TCODE SE24) 1-1-2 Implement the following methods of the interface IF_RSPC_MAINTAIN 1-1.2.1 MAINTAIN: Copy and paste the code underneath. This method is quite empty because we do not have persistence in this exercise. But still a process variant has to be determined, thus a trivial fixed name is given back. Save it.
IF i_variant IS INITIAL. " Create a new one * ---- No maintainance, thus hardcoded variant name ---e_variant = 'HARDCODED'. e_variant_text = 'Filename hardcoded'. ELSE. " maintain an existing one * ---- No maintainance, thus according message ---MESSAGE i023(rspc). ENDIF.
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
1-1.2.2 GET_HEADER: Copy and paste the code underneath. This method is quite empty because we do not have persistence in this exercise. Save it.
e_variant_text = 'Filename hardcoded'.
1-1-3 Implement the following methods of the interface IF_RSPC_EXECUTE 1-1.3.1 GIVE_CHAIN: Copy and paste the code underneath. Save it.
* ---- We do not need to know about the chain during runtime, ---* ---- our method works by itself ---return = ' '.
F o r
o n l y
1-1.3.2 EXECUTE: Copy and paste the code underneath. This method is performing the check on the existence of the file on run time. Activate it. Select everything on the following popup and press ok
* ---- These are the parameters of your process ---DATA: * ---- Evt. Change below line and enter the correct path and filename p_file TYPE char90 VALUE 'N:\T_COSTCENTER_TRANS_2004002.CSV. DATA: l_status l_unique_id TYPE btcxpgstat, TYPE sysuuid_25.
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
* ==== Get Instance ==== CALL FUNCTION 'RSSM_UNIQUE_ID' IMPORTING e_uni_idc25 = l_unique_id. e_instance = l_unique_id. e_state = 'G'. * ==== Go for it ==== DATA: l_file_exists type c. CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXIST EXPORTING FILE = p_file RECEIVING RESULT = l_file_exists. IF l_file_exists is initial. e_state = 'R'. else. e_state = 'G'. ENDIF.
b y
C S C
o n l y
F o r
1-2 Your process type is finished. You now need to declare it for the process chain framework. Go to transaction RSPC. 1-2-1 Create a chain named ZPC_EX_TYPE_<group> with a start process for immediate start. 1-2-2 Choose from the menu Settings Process Types. Choose New Entries.
Enter a process type name ZPCTYPE<group>. Enter meaningful long and short descriptions (include your group number in the description). As ObjectTypeName enter the name of your class (ZCL_PC_EX_<group>). Choose Abap OO as the object type. As Possible Events choose Process ends "successful" or "incorrect". Process is Repeatable but not Repairable. As ID choose a cool icon with F4. Select internal name. As process category choose 98. Save and leave.
F o r
o n l y
i n t e r n a l
C S C
1-2-3 Your process type is ready to be inserted in the chain: Choose the tree Process Types. Find your process type under node Others. Add it to the process chain. 1-2-4 Connect the your process type with the trigger process. 1-2-5 Add any process type after your new process type (e.g. the InfoPackage you created in Chapter 3 for the Data Staging). 1-2-6 Now you can test your solution: Run the chain. Your process should become green if the file is there, and red if it was not there.
u s e
b y
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
Appendix
Contents:
List of existing SAP Enhancements & BAdIs ABAP Basics Data Extraction Data Staging
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
8-1
Appendix (1)
List of existing SAP Enhancements and BAdIs ABAP Basics Performance Data Extraction Data Staging
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
8-2
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The list of the SAP enhancements and BAdIs is based on the release 3.0B. The complete transition from SAP enhancements to BAdIs will occur in the next releases. Please check your system for the existence of SAP enhancements or BAdIs, respectively (all documented SAP enhancements and BAdIs will be included implementation guide [IMG]).
C S C
o n l y
F o r
SAP AG
PDEBWB
8-3
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The list of the SAP enhancements and BAdIs is based on the release 3.0B. The complete transition from SAP enhancements to BAdIs will occur in the next releases. Please check your system for the existence of SAP enhancements or BAdIs, respectively (all documented SAP enhancements and BAdIs will be included implementation guide [IMG]).
C S C
o n l y
F o r
SAP AG
PDEBWB
8-4
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The list of the SAP enhancements and BAdIs is based on the release 3.0B. The complete transition from SAP enhancements to BAdIs will occur in the next releases. Please check your system for the existence of SAP enhancements or BAdIs, respectively (all documented SAP enhancements and BAdIs will be included implementation guide [IMG]).
C S C
o n l y
F o r
SAP AG
PDEBWB
8-5
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The complete transition from SAP enhancements to BAdIs will occur in the next releases. Please check your system for the existence of SAP enhancements or BAdIs, respectively (all documented SAP enhancements and BAdIs will be included implementation guide [IMG]).
C S C
o n l y
F o r
SAP AG
PDEBWB
8-6
Appendix (2)
List of existing SAP Enhancements and BAdIs ABAP Basics Performance Data Extraction Data Staging
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
8-7
DATA: wa_sflight TYPE sflight, wa_focc TYPE sbc400focc. MOVE-CORRESPONDING MOVE-CORRESPONDING wa_sflight TO wa_focc. MOVE-
...
F o r
o n l y
i n t e r n a l
C S C
b y
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The statement MOVE-CORRESPONDING source_struc TO target_struc copies the contents of the structure source_struc into the structure target_struc component by component. The value assignment works only if the components have identical names. All other components remain unchanged.
C S C
o n l y
F o r
SAP AG
PDEBWB
8-8
Search in a character string Position of search string using MATCH OFFSET off addition Replace first occurrence Replace all occurrences Move Remove space characters Overwrite : Spaces are overwritten by characters from the second character string Concatenate several character strings Split a character string
F o r
o n l y
CONCATENATE SPLIT
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
Note for FIND statement (search in a character string): There are special comparison operators for strings, which you can use in logical expressions in a query (IF) to search more flexibly for character sequences in a character string. For more information, see the keyword documentation for IF. For every statement, the operands are treated like type c fields, regardless of their actual field type. No internal type conversions take place. All of the statements apart from TRANSLATE and CONDENSE set the system field sy-subrc. (SEARCH also sets the system field sy-fdpos with the offset of the character string found.) All of the statements apart from SEARCH are case-sensitive. To find out the occupied length of a string, use the standard function STRLEN(). For the SPLIT statement there is the variant SPLIT ... INTO TABLE <itab>, which you can use to split the character string dynamically. You do not need to specify the number of parts into which the string should be split.
C S C
o n l y
F o r
SAP AG
PDEBWB
8-9
Insert
INSERT INSERT
Read
F o r
o n l y
Change
i n t e r n a l
C S C
Delete
SAP AG 2003
u s e
b y
u s e
i n t e r n a l
b y
The following single record operations are available for internal tables: In each case wa represents a structure that must have the same type as the line type of the internal table itab. APPEND INSERT Appends the contents of a structure to an internal table. This operation should be used with standard tables only. Inserts the contents of a structure into an internal table. In a standard table it is appended, in a sorted table it is inserted in the right place, and in a hashed table it is inserted according to the hash algorithm. Copies the contents of a line in an internal table to a structure. Overwrites a line in an internal table with the content of a structure. Deletes a line of an internal table. Accumulates the contents of a structure into an internal table. This statement may be used only for tables whose non-key fields are all numeric. The numeric values are summarized for identical keys
C S C
o n l y
F o r
For detailed information about the ABAP statements described here, refer to the relevant keyword documentation.
SAP AG
PDEBWB
8-10
Delete
o n l y
F o r
b y
C S C
i n t e r n a l
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The following set operations are available for internal tables: In each case wa represents a structure that must have the same type as the line type of the internal table itab. LOOP ... ENDLOOP The LOOP places the lines of an internal table one by one into the structure specified in the INTO clause. All single record operations can be executed within the loop. In this case, for the single record operations, the system identifies the line to be processed. DELETE Deletes the lines of the internal table that satisfy the condition <condition>. INSERT Copies the contents of several lines of an internal table to another internal table. APPEND Appends the contents of several lines of an internal table to another standard table. For detailed information about the ABAP statements described here, refer to the relevant keyword documentation.
C S C
o n l y
F o r
SAP AG
PDEBWB
8-11
Sort
SORT SORT
itab <conditions>.
REFRESH REFRESH
itab.
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The following operations affect the whole internal table. SORT You can use this to sort any number of columns in a standard or hashed table in ascending or descending order. You may want to take culture-specific sort rules into account. REFRESH This deletes the entire contents of an internal table. A part of the previously used working memory remains available for future insertions. FREE This deletes the entire contents of the internal table and releases the previously used working memory. CLEAR Unlike all other data objects, this statement has the same effect as the REFRESH statement on internal tables with no header line.
C S C
o n l y
F o r
SAP AG
PDEBWB
8-12
Conditional Branching
IF <logical_expression>. IF
Statements
ENDCASE ENDCASE.
F o r
o n l y
ELSE ELSE.
Statements
i n t e r n a l
C S C
ENDIF ENDIF.
b y
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
In ABAP you have two ways to execute different sequences of statements, depending on certain conditions. With the CASE-ENDCASE construction the criterion for the execution of a statement block is the similarity of the data objects. If no comparison is successful, then the system executes the OTHERS branch, if it is available. Except for the first WHEN branch, all further additions are optional. With the IF-ENDIF construction, you can use any logical expressions. If the condition is met, the system executes the relevant statement sequence. If no comparison is successful, then the system executes the OTHERS branch, if it is available. Except for the first query, all further branches are optional. For both constructions, the system executes only one statement sequence and always for the first valid case. Recommendation: If, in every condition, you check that a variable is equal to a given value, use the CASE-ENDCASE construction. It is clearer and less runtime intensive. Outside of loops you can also use CHECK instead of IF. This query sets the execution of all statements up to the end of the current processing block under one condition. If this is unsuccessful, the system continues with the first statement in the next processing block.
SAP AG
C S C
o n l y
F o r
PDEBWB
8-13
Loops
DO [ n TIMES ] [...].
Statements
ENDDO.
Loop counter: Loop counter: sy-index sy-index
WHILE <logical_expression>.
Statements
ENDWHILE.
LOOP AT ...
Statements
ENDLOOP.
DO.
Statements
F o r
o n l y
SELECT ...
Statements
C S C
ENDSELECT.
i n t e r n a l
b y
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
In ABAP there are four loop constructions, whereby LOOP-ENDLOOP and SELECTENDSELECT represent special cases. In the DO and WHILE loops, the system stores the number of the current loop pass in the sy-index field. If these loops are nested, sy-index contains the number of the current (that is, inner) loop. Unconditional/index controlled loops The statements between DO and ENDDO are executed until the loop is left over other statements. You also have the option of specifying the maximum number of loop passes; otherwise, you may get an endless loop. Header controlled loops The statements between WHILE and ENDWHILE are executed only if the condition <logical_expression> has been met. You can use the statements CHECK and EXIT for different effects on the way the loop is processed. For example, you can construct a footer-controlled loop.
C S C
o n l y
F o r
SAP AG
PDEBWB
8-14
Function Group
Inte r face
F o r
o n l y
Screen
C S C
Fun
i n t e r n a l
Interface
b y
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
A function group represents the main program for function modules. Several function modules that operate on the same data content are combined to form a function group. The function group remains active for as long as the calling program is active. For example, if an executable program calls a function module, its entire function group is loaded as well. It remains active until the executable program is completed. A function group can contain the same components as an executable program. These include: Data Objects These are then global in relation to the function group, that is, they are visible to and changeable by all function modules within the group. The validity period is the same as for the function group. Subroutines These can be called from all function modules in the group. Screens These can be called from all function modules in the group.
C S C
o n l y
F o r
SAP AG
PDEBWB
8-15
In te rfac e
F o r
o n l y
C S C
i n t e r n a l
Interface
SAP AG 2003
u s e
b y
u s e
i n t e r n a l
b y
The global data of a function module is retained until the program that contained the first call of a function module in the function group is finished. Thus, if a function module that writes values to the global data is called, other function modules in the same function group can access this data when the program calls them. Seen from the outside, the global data is encapsulated, that is, it is not possible to access it directly. Therefore, you must have function modules that allow orderly access from the outside. The same applies to all the other components of the function group (screens, subroutines).
C S C
o n l y
F o r
SAP AG
PDEBWB
8-16
PAI
MODULE user_command_0100 INPUT. CASE ok_code. WHEN 'CANCEL'. CALL FUNCTION 'POPUP_TO_CONFIRM_LOSS_OF_DATA' EXPORTING EXPORTING textline = text-001 title = text-002 IMPORTING IMPORTING answer = pop_answer. CASE pop_answer. when 'J'. ... when 'N'. ... ENDCASE. ... ENDCASE. ABAP program
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
You call function modules using the ABAP statement CALL FUNCTION. The name of the function module follows in capital letters enclosed in single quotation marks. After EXPORTING has taken place, the system passes values to the Import parameters of the function module. After IMPORTING has taken place, the function module returns the result through its Export parameter. Looking at this from the calling program's side, we see that the parameters passed to the function module are exported, and those passed from the function module to the program are imported. On the Parameter assignment screen, the system displays the names of the interface parameters of the function module (formal parameters) to the left of the equal sign. The system displays the calling program's data objects (actual parameters) to the right of the equal sign.
C S C
o n l y
F o r
SAP AG
PDEBWB
8-17
Database table
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
With most function modules, exceptions are triggered in error situations. In such cases, the exceptions are assigned to the number values after EXCEPTIONS. If the function module triggered such an exception, the respective value is placed into the system field sy-subrc. If you do not want to list the triggered exception under EXCEPTIONS or you cannot do so, the exception is assigned to the OTHERS case, provided this addition is listed. By evaluating this field, you can then react accordingly. In the example shown in the graphic, suitable messages are transmitted. If no exception was triggered or neither the exception nor OTHERS was listed under EXCEPTIONS, the system sets the sy-subrc field to 0.
C S C
o n l y
F o r
SAP AG
PDEBWB
8-18
+ + +
+ + +
F o r
o n l y
Information System
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The structure of the application components is shown in the application hierarchy. From the SAP Easy Access menu, you access the application hierarchy by choosing Tools ABAP Workbench Overview Application Hierarchy. The application components are displayed in a tree structure in the application hierarchy. Expanding a component displays all the development classes that are assigned to that component. You can select a subtree or branch and navigate from the application hierarchy to the R/3 Repository Information System. The system then collects all development classes for the branch selected and passes them to the Repository Information System.
C S C
o n l y
F o r
SAP AG
PDEBWB
8-19
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
You can use the Repository Information System to search for specific Repository objects. Suitable search criteria are available for the various Repository objects. Which objects are to be found using the Repository Information System depends on how you get there: From within the application hierachy, select the Information system (double-click the selected application component or development class). This filters the the respective Repository objects. From the SAP Easy Access menu, choose Tools ABAP Workbench Overview Information system. The system lists all the Repository Objects available for searching.
C S C
o n l y
F o r
SAP AG
PDEBWB
8-20
Appendix (3)
List of existing SAP Enhancements and BAdIs ABAP Basics Performance Data Extraction Data Staging
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
8-21
Performance aspects
Performance critical areas:
Data retrieval (SELECT statement)
Using SELECT ... INTO TABLE ... and READ TABLE ... instead of several SELECT SINGLE ...
Internal tables
Choose table type for optimal search algorithm
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
8-22
Secondary index
CITYFROM BERLIN BERLIN ... FRANKFURT FRANKFURT FRANKFURT FRANKFURT ... NEW YORK NEW YORK ...
SAP AG 2003
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y
When you go to the definition of a database table in the ABAP Dictionary, you will see information on all the technical attributes of the database table. The following information is useful for improving the performance of database accesses: Key fields If the lines requested from the database are retrieved according to key fields, the Database Optimizer can perform access using a primary index. Secondary index If the lines requested from the database are retrieved according to fields, the Database Optimizer can perform access using a secondary index. Secondary indexes are displayed in a dialog box whenever you select Indexes. You choose an index from the dialog box by doubleclicking it. The system then displays a screen with additional information about that index.
C S C
o n l y
F o r
SAP AG
PDEBWB
8-23
Hashed table
STANDARD TABLE
SORTED TABLE
HASHED TABLE
Performance
searchtime increases only logarithmically with the number of table entries If you use only index access sorting is wasted time -> standard table
searchtime is independet of the number of table entries no index access possible and the key needs to be full qualified otherwise: linear search
F o r
o n l y
Comment
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
8-24
Internal Tables: Single Record Access - Completely and Partially Qualified Key
READ TABLE itab INTO wa WITH TABLE KEY key. WITH TABLE KEY key
Must be completely qualified Table scan Binary search Hash algorithm Table kind
STANDARD
SORTED
HASHED
READ TABLE itab INTO wa WITH KEY key. WITH KEY STANDARD key
Complete/part key left-aligned without gaps leftBy qualified key Any component condition
SAP AG 2003
Table kind
SORTED
Binary search
HASHED
F o r
o n l y
i n t e r n a l
Table scan
u s e
b y
C S C
Table scan
Table scan
u s e
i n t e r n a l
b y
Whenever you want to read individual table lines by declaring a complete key, use the READ TABLE ... WITH TABLE KEY statement (fastest single record access by key). The runtime system supports this syntax variant especially for SORTED and HASHED tables. If the table is a STANDARD table, the runtime system performs a table scan. The same applies if you have copied the values from all key fields of the entry to be read into the work area wa and are then use READ TABLE itab FROM wa. The runtime system carries out the syntax variant READ TABLE ... WITH KEY (read an entry after applying any condition) using a table scan. The only exception to this rule applies to SORTED tables, if you fill the first n key fields with "=" (no gaps), where n <= number of key fields. With standard tables however, you can also sort correspondingly using SORT and then use the BINARY SEARCH addition. Summary: Whenever possible, use READ TABLE ... WITH TABLE KEY or the variant with a correspondingly-filled work area. If you need to use READ TABLE ... WITH KEY, make your internal table a SORTED table.
C S C
o n l y
F o r
SAP AG
PDEBWB
8-25
Table kind
SORTED
HASHED
Table scan
Table scan
o n l y
F o r
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
The runtime system generally processes loops with a WHERE clause by performing a table scan that is, determining whether the condition in the WHERE clause is true for each line in the table. SORTED tables are the only exception to this rule. For these, the runtime system optimizes the runtime under the following condition: In the WHERE clause, the first n key fields are filled with a "=" (no gaps). (n is less than or equal to the number of all key fields). As a result, the loop is only performed on the lines that match the condition in the WHERE clause. Since the table is sorted, the first line can be specified to optimize performance at runtime (using a binary search).
C S C
o n l y
F o r
SAP AG
PDEBWB
8-26
READ TABLE itab ASSIGNING <fs1> WITH TABLE KEY ... . READ TABLE <fs1>-col3 ASSIGNING <fs2> WITH TABLE KEY ... .
<fs2>
READ TABLE itab INTO wa1 WITH TABLE KEY ... . READ TABLE wa1-col3 INTO wa2 WITH TABLE KEY ... .
wa2 wa1 Copy
<fs1> Copy
F o r
o n l y
i n t e r n a l
C S C
b y
col1
col2
col3
col4
itab
col1
col2
col3
col4
SAP AG 2003
u s e
u s e
i n t e r n a l
Instead of READ TABLE ... INTO, you can use the READ TABLE ... ASSIGNING variant. This offers better performance at runtime for pure read accesses with a line width greater than or equal to 1000 bytes. If you then change the read line using MODIFY, READ ... ASSIGNING already improves runtime with a line width of 100 bytes. The same applies to LOOP ... INTO in comparison with LOOP ... ASSIGNING. The LOOP ... ASSIGNING variant offers better performance at runtime for any loop of five loop passes or more. Both field symbol variants are much faster than work area variants, in particular when you use nested internal tables. This is because, if you use work areas instead, the whole inner internal table is copied (unless you prevent this by using a TRANSPORTING addition). Always assign a type to field symbols, if you know their static type (again, for performance reasons). Note: If you use READ TABLE ... ASSIGNING the field symbol points to the originally assigned table line, even after the internal table has been sorted. Note that when using field symbols, you cannot change key fields in SORTED or HASHED tables. Trying to do so causes a runtime error. The following restrictions apply to LOOP ... ASSIGNING <fs>: You cannot use the SUM statement in control level processing. You cannot reassign field symbols within the loop. The statements ASSIGN do TO <fs> and UNASSIGN <fs> will cause runtime errors.
SAP AG
b y
C S C
o n l y
F o r
PDEBWB
8-27
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
8-28
Appendix (4)
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
8-29
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
8-30
C S C
FUNCTION RSAX_BIW_GET_DATA_SIMPLE. *"---------------------------------------------------------------------*"*"Lokale Schnittstelle: *" IMPORTING *" VALUE(I_REQUNR) TYPE SRSC_S_IF_SIMPLE-REQUNR *" VALUE(I_DSOURCE) TYPE SRSC_S_IF_SIMPLE-DSOURCE *" OPTIONAL *" VALUE(I_MAXSIZE) TYPE SRSC_S_IF_SIMPLE-MAXSIZE *" OPTIONAL *" VALUE(I_INITFLAG) TYPE SRSC_S_IF_SIMPLE-INITFLAG *" OPTIONAL *" VALUE(I_READ_ONLY) TYPE SRSC_S_IF_SIMPLE-READONLY *" OPTIONAL *" TABLES *" I_T_SELECT TYPE SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL *" I_T_FIELDS TYPE SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL *" E_T_DATA STRUCTURE SFLIGHT OPTIONAL *" EXCEPTIONS *" NO_MORE_DATA *" ERROR_PASSED_TO_MESS_HANDLER *"---------------------------------------------------------------------* Example: DataSource for table SFLIGHT TABLES: SFLIGHT. * Auxiliary Selection criteria structure DATA: L_S_SELECT TYPE SRSC_S_SELECT. * Maximum number of lines for DB table STATICS: S_S_IF TYPE SRSC_S_IF_SIMPLE, * counter S_COUNTER_DATAPAKID LIKE SY-TABIX, * cursor S_CURSOR TYPE CURSOR. * Select ranges RANGES: L_R_CARRID FOR SFLIGHT-CARRID, L_R_CONNID FOR SFLIGHT-CONNID. * Initialization mode (first call by SAPI) or data transfer mode * (following calls) ? IF I_INITFLAG = SBIWA_C_FLAG_ON. ************************************************************************ * Initialization: check input parameters * buffer input parameters * prepare data selection ************************************************************************
F o r
o n l y
i n t e r n a l
u s e
b y
u s e
i n t e r n a l
b y C S C o n l y
F o r
* Check DataSource validity CASE I_DSOURCE. WHEN '0SAPI_SFLIGHT_SIMPLE'. WHEN OTHERS. IF 1 = 2. MESSAGE E009(R3). ENDIF. * this is a typical log call. Please write every error message like this LOG_WRITE 'E' "message type 'R3' "message class '009' "message number I_DSOURCE "message variable 1 ' '. "message variable 2 RAISE ERROR_PASSED_TO_MESS_HANDLER. ENDCASE. APPEND LINES OF I_T_SELECT TO S_S_IF-T_SELECT. * Fill parameter buffer for data extraction calls S_S_IF-REQUNR = I_REQUNR. S_S_IF-DSOURCE = I_DSOURCE. S_S_IF-MAXSIZE = I_MAXSIZE. * Fill field list table for an optimized select statement * (in case that there is no 1:1 relation between InfoSource fields * and database table fields this may be far from beeing trivial) APPEND LINES OF I_T_FIELDS TO S_S_IF-T_FIELDS. ELSE. "Initialization mode or data extraction ?
F o r o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
************************************************************************ * Data transfer: First Call OPEN CURSOR + FETCH * Following Calls FETCH only ************************************************************************ * First data package -> OPEN CURSOR IF S_COUNTER_DATAPAKID = 0. * Fill range tables BW will only pass down simple selection criteria * of the type SIGN = 'I' and OPTION = 'EQ' or OPTION = 'BT'. LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'CARRID'. MOVE-CORRESPONDING L_S_SELECT TO L_R_CARRID. APPEND L_R_CARRID. ENDLOOP. LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'CONNID'. MOVE-CORRESPONDING L_S_SELECT TO L_R_CONNID. APPEND L_R_CONNID. ENDLOOP. * Determine number of database records to be read per FETCH statement * from input parameter I_MAXSIZE. If there is a one to one relation
b y C S C o n l y
F o r
* between DataSource table lines and database entries, this is trivial. * In other cases, it may be impossible and some estimated value has to * be determined. OPEN CURSOR WITH HOLD S_CURSOR FOR SELECT (S_S_IF-T_FIELDS) FROM SFLIGHT WHERE CARRID IN L_R_CARRID AND CONNID IN L_R_CONNID. ENDIF. "First data package ? * Fetch records into interface table. * named E_T_'Name of extract structure'. FETCH NEXT CURSOR S_CURSOR APPENDING CORRESPONDING FIELDS OF TABLE E_T_DATA PACKAGE SIZE S_S_IF-MAXSIZE. IF SY-SUBRC <> 0. CLOSE CURSOR S_CURSOR. RAISE NO_MORE_DATA. ENDIF. S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1. ENDIF. "Initialization mode or data extraction ?
F o r o n l y
i n t e r n a l
b y
C S C
u s e
ENDFUNCTION.
u s e
i n t e r n a l
b y C S C o n l y
F o r
Functionality
This function module allows you to fill user-defined fields that you have attached to existing InfoSources as an append structure. You can find further information the documentation under User-defined enhancement to the extract structure. The following transfer parameters are available: I_ISOURCE: Name of the InfoSource. I_T_FIELDS: List of the transfer structure fields. Only these fields are actually filled in the data table and can be sensibly addressed in the program. C_T_DATA: Table with the data received from the API in the format of source structure entered in table ROIS (field ROIS-STRUCTURE). I_UPDMODE: Transfer mode as requested in the Scheduler of the Business Information Warehouse. Not normally required. I_T_SELECT: Table with the selection criteria stored in the Scheduler of the SAP-Business Information Warehouse. This is not normally required.
F o r
o n l y
i n t e r n a l
b y
C S C
F o r
FUNCTION EXIT_SAPLRSAP_001. *"---------------------------------------------------------------------*"*"Lokale Schnittstelle: *" IMPORTING *" VALUE(I_DATASOURCE) TYPE RSAOT_OLTPSOURCE *" VALUE(I_ISOURCE) TYPE SBIWA_S_INTERFACE-ISOURCE *" VALUE(I_UPDMODE) TYPE SBIWA_S_INTERFACE-UPDMODE *" TABLES *" I_T_SELECT TYPE SBIWA_T_SELECT *" I_T_FIELDS TYPE SBIWA_T_FIELDS *" C_T_DATA *" C_T_MESSAGES STRUCTURE BALMI OPTIONAL *" EXCEPTIONS *" RSAP_CUSTOMER_EXIT_ERROR *"----------------------------------------------------------------------
u s e
u s e
i n t e r n a l
b y C S C o n l y
Functionality
This function module allows you to fill customer-defined fields that you have hung as an append structure to master data structures of the SAP Business Information Warehouse. Transfer Parameters: I_CHABASNM: Name of the basic characteristic. I_T_FIELDS: List of the transfer structure fields. Only these fields are actually filled in the database table and can be used in any meaningful way in the program. I_T_DATA: Table - with the data contained by the API - in the format of source structure entered in the RODCHABAS table (field RODCHABAS-STRUCTURE). I_UPDMODE: Transfer mode, as requested in the scheduler of the Business Information Warehouse. This is not usually required. I_T_SELECT: Table with the selection conditions that are stored in the scheduler of the Business Information Warehouse. This is not usually. required.
F o r
o n l y
i n t e r n a l
C S C
Further Information
Documentation of the Business Information Warehouse under Customer-Defined Enhancement of the Extract Structure
u s e
b y
u s e
F o r
FUNCTION EXIT_SAPLRSAP_002. *"---------------------------------------------------------------------*"*"Lokale Schnittstelle: *" IMPORTING *" VALUE(I_DATASOURCE) TYPE RSAOT_OLTPSOURCE *" VALUE(I_CHABASNM) TYPE SBIWA_S_INTERFACE-CHABASNM *" VALUE(I_UPDMODE) TYPE SBIWA_S_INTERFACE-UPDMODE *" TABLES *" I_T_SELECT TYPE SBIWA_T_SELECT *" I_T_FIELDS TYPE SBIWA_T_FIELDS *" I_T_DATA *" C_T_MESSAGES STRUCTURE BALMI OPTIONAL *" EXCEPTIONS *" RSAP_CUSTOMER_EXIT_ERROR *"----------------------------------------------------------------------
i n t e r n a l
b y C S C o n l y
Functionality
This function module allows you to change the contents of transfer tables generated for a hierarchy request. This can be useful, for example, with customer-defined hierarchy classes. The module should not used to change the contents of key fields. That should certainly be done in the SAP Business Information Warehouse! The following transfer parameters are available: C_T_HIETEXT: Table with the description of the hierarchy in the requested language. C_T_HIENODE: Table with all components of the hierarchy. C_T_FOLDERT: Table with the descriptions of all of the nodes of the hierarchy that cannot be posted to, in the requested languages. C_T_HIEINTV: Table wiht those hierarchy sheets that represent value intervals. I_UPDMODE: Transfer mode as requested in the Scheduler of the SAP Business Information Warehouse. This is not normally required. I_S_HIER_SEL: Structure that the requested hierarchy contains. I_T_LANGU: Table with the languages for which the descriptions have been requested.
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
Further information
SAP Business Information Warehouse documentation
b y C S C
FUNCTION EXIT_SAPLRSAP_004. *"---------------------------------------------------------------------*"*"Lokale Schnittstelle: *" IMPORTING *" VALUE(I_DATASOURCE) TYPE RSAOT_OLTPSOURCE *" VALUE(I_S_HIEBAS) TYPE RSAP_S_HIEBAS *" VALUE(I_S_HIEFLAG) TYPE RSAP_S_HIEFLAG *" VALUE(I_S_HIER_SEL) TYPE RSAP_S_HIER_LIST *" VALUE(I_S_HEADER3) OPTIONAL *" TABLES *" I_T_LANGU TYPE SBIWA_T_LANGU *" C_T_HIETEXT TYPE RSAP_T_HIETEXT *" C_T_HIENODE TYPE RSAP_T_HIENODE *" C_T_FOLDERT TYPE RSAP_T_FOLDERT *" C_T_HIEINTV TYPE RSAP_T_HIEINTV *" C_T_HIENODE3 OPTIONAL *" C_T_HIEINTV3 OPTIONAL *" C_T_MESSAGES STRUCTURE BALMI OPTIONAL *" EXCEPTIONS *" RSAP_CUSTOMER_EXIT_ERROR *"----------------------------------------------------------------------
o n l y
F o r
Appendix (5)
F o r
o n l y
i n t e r n a l
b y
C S C
SAP AG 2003
u s e
u s e
i n t e r n a l
b y
C S C
o n l y
F o r
SAP AG
PDEBWB
Appendix
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y C S C o n l y
F o r
select /BIC/ZLOCCUCAT /BIC/ZSOPCOMPS /BIC/ZCUSTNR * due to performance select to view * from /BIC/PZCUSTNR into corresponding fields of l_/BIC/PZCUSTNR from ZV_PZCUSTNR into corresponding fields of l_/BIC/PZCUSTNR where OBJVERS = 'A'. append l_/BIC/PZCUSTNR to it_/BIC/PZCUSTNR. endselect. sort it_/BIC/PZCUSTNR by /BIC/ZSOPCOMPS /BIC/ZCUSTNR. * read ods data into itab select * from /BIC/AZLMS200 into l_ods. append l_ods to it_ods. endselect. sort it_ods by /BIC/ZSELLCOMP /BIC/ZLOCCUCAT /BIC/ZPRODAREA. * loop over the data package loop at DATA_PACKAGE. l_tabix = sy-tabix. * get product area from itab read table it_/BIC/PZLARTVAR with key /BIC/ZSOPCOMPS = DATA_PACKAGE-/BIC/ZSOPCOMPS /BIC/ZLARTDIV = DATA_PACKAGE-/bic/zlartdiv /BIC/ZLARTNO = DATA_PACKAGE-/BIC/ZLARTNO /BIC/ZLARTVAR = DATA_PACKAGE-/BIC/ZLARTVAR binary search. if sy-subrc = 4 or sy-subrc = 8. MONITOR-msgid = 'ZBWMESS'. MONITOR-msgty = 'I'. MONITOR-msgno = '20'. MONITOR-msgv1 = DATA_PACKAGE-/BIC/ZSOPCOMPS. MONITOR-msgv2 = DATA_PACKAGE-/bic/zlartdiv. MONITOR-msgv3 = DATA_PACKAGE-/BIC/ZLARTNO. MONITOR-msgv4 = DATA_PACKAGE-/BIC/ZLARTVAR. append MONITOR. endif. * if the product area of the cube's record is not from the inco * business skip the record if it_/BIC/PZLARTVAR-/BIC/ZPRODAREA(2) ne 'IN'. continue. endif. * get local customer category read table it_/BIC/PZCUSTNR with key /BIC/ZSOPCOMPS = DATA_PACKAGE-/BIC/ZSOPCOMPS /BIC/ZCUSTNR = DATA_PACKAGE-/BIC/ZCUSTNR binary search. if sy-subrc = 4 or sy-subrc = 8. MONITOR-msgid = 'ZBWMESS'. MONITOR-msgty = 'I'. MONITOR-msgno = '21'. MONITOR-msgv1 = DATA_PACKAGE-/BIC/ZSOPCOMPS. MONITOR-msgv2 = DATA_PACKAGE-/BIC/ZCUSTNR.
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y C S C o n l y
F o r
append MONITOR. endif. * create bw style of loccustcat * empty loccustcat values for the Inco business are filled with misc if it_/BIC/PZCUSTNR-/BIC/ZLOCCUCAT = ' ' or it_/BIC/PZCUSTNR-/BIC/ZLOCCUCAT is initial. concatenate DATA_PACKAGE-/BIC/ZSELLCOMP '_MISC' into l_loccustcat. else. l_loccustcat = it_/BIC/PZCUSTNR-/BIC/ZLOCCUCAT. endif. * check value if ods data fits to data package record l_rc = '8'. * and loop over ods data clear l_ods. loop at it_ods into l_ods where /BIC/ZSELLCOMP = DATA_PACKAGE-/BIC/ZSELLCOMP and /BIC/ZLOCCUCAT = l_loccustcat and /BIC/ZPRODAREA = it_/BIC/PZLARTVAR-/BIC/ZPRODAREA. * comparison of ods characteristics to cube characteristics * Segmentation 1: check institutions if l_ods-/BIC/ZSELLCOMP = DATA_PACKAGE-/BIC/ZSELLCOMP and l_ods-/BIC/ZLOCCUCAT = l_loccustcat and l_ods-/BIC/ZPRODAREA = it_/BIC/PZLARTVAR-/BIC/ZPRODAREA and l_ods-/BIC/ZSEGM = '10'. "Institutions * append new record to help structure (eq cube structure) clear l_data_pack. move-corresponding DATA_PACKAGE to l_data_pack. l_data_pack-/BIC/ZSEGM = l_ods-/BIC/ZSEGM. l_data_pack-/BIC/ZSEGMP = l_ods-/BIC/ZSEGMP. l_data_pack-/BIC/ZAPHTC = DATA_PACKAGE-/BIC/ZAPHTC * l_ods-/BIC/ZSEGMP. l_data_pack-/BIC/ZAPWHC = DATA_PACKAGE-/BIC/ZAPWHC * l_ods-/BIC/ZSEGMP. l_data_pack-/BIC/ZCIFREIAM = DATA_PACKAGE-/BIC/ZCIFREIAM * l_ods-/BIC/ZSEGMP. * und hier kommen noch viele weitere Kennzahlen im Projekt waren es an die 80 l_data_pack-/BIC/ZSTABONAM = DATA_PACKAGE-/BIC/ZSTABONAM "ok * l_ods-/BIC/ZSEGMP. append l_data_pack to it_data_pack. l_rc = '0'. * Segmentation 2: check health care elseif l_ods-/BIC/ZSELLCOMP = DATA_PACKAGE-/BIC/ZSELLCOMP and l_ods-/BIC/ZLOCCUCAT = l_loccustcat and l_ods-/BIC/ZPRODAREA = it_/BIC/PZLARTVAR-/BIC/ZPRODAREA and l_ods-/BIC/ZSEGM = '20'. "Health Care * gleiches Vorgehen wie bei Segment 1 die Kennzahlen werden mit der Prozentzahl multipliziert append l_data_pack to it_data_pack. l_rc = '0'. * Segmentation 3: check Retail elseif l_ods-/BIC/ZSELLCOMP = DATA_PACKAGE-/BIC/ZSELLCOMP and l_ods-/BIC/ZLOCCUCAT = l_loccustcat and l_ods-/BIC/ZPRODAREA = it_/BIC/PZLARTVAR-/BIC/ZPRODAREA and l_ods-/BIC/ZSEGM = '30'. "Retail * gleiches Vorgehen wie bei Segment 1 und 2 die Kennzahlen werden mit der Prozentzahl multipliziert
F o r
o n l y
i n t e r n a l
u s e
b y
C S C
u s e
i n t e r n a l
b y C S C o n l y
F o r
u s e
append l_data_pack to it_data_pack. l_rc = '0'. endif. endloop. * those records of the data_package which do not have a split rule * are added at glance if sy-subrc <> 0. clear l_data_pack. move-corresponding DATA_PACKAGE to l_data_pack. append l_data_pack to it_data_pack. endif. * no match of records of split table ods and data package from cube if l_rc = '8'. MONITOR-msgid = 'ZBWMESS'. MONITOR-msgty = 'I'. MONITOR-msgno = '23'. MONITOR-msgv1 = DATA_PACKAGE-/BIC/ZCUSTNR. MONITOR-msgv2 = l_loccustcat. MONITOR-msgv3 = DATA_PACKAGE-/BIC/ZSOPCOMPS. append MONITOR. endif. * delete record from data package delete DATA_PACKAGE index l_tabix. endloop. * append records of internal data pack append lines of it_data_pack to DATA_PACKAGE. * if abort is not equal zero, the update process will be canceled ABORT = 0. *$*$ end of routine - insert your code only before this line *-* * ENDFORM.
F o r
o n l y
i n t e r n a l
b y
C S C
u s e
i n t e r n a l
b y C S C o n l y
F o r