Upload
hatuyen
View
322
Download
24
Embed Size (px)
Citation preview
SAP NetWeaver
How-To Guide
SAP NetWeaver
How-To Guide
How to… Log Changes in Plan Data
when using the SAP BW Planning
Applications Kit
Applicable Releases:
SAP NetWeaver BW 7.30 SP9, BW7.31 SP 7 (or note 1802658) and higher,
SAP HANA
Topic Area:
Data Warehousing
Version 1.2
May 2014
© Copyright 2014 SAP AG. All rights reserved.
No part of this publication may be reproduced or
transmitted in any form or for any purpose without the
express permission of SAP AG. The information contained
herein may be changed without prior notice.
Some software products marketed by SAP AG and its
distributors contain proprietary software components of
other software vendors.
Microsoft, Windows, Outlook, and PowerPoint are
registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, OS/2, Parallel
Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390,
OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP,
Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix,
i5/OS, POWER, POWER5, OpenPower and PowerPC are
trademarks or registered trademarks of IBM Corporation.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader
are either trademarks or registered trademarks of Adobe
Systems Incorporated in the United States and/or other
countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered
trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame,
WinFrame, VideoFrame, and MultiWin are trademarks or
registered trademarks of Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or
registered trademarks of W3C®, World Wide Web
Consortium, Massachusetts Institute of Technology.
Java is a registered trademark of Sun Microsystems, Inc.
JavaScript is a registered trademark of Sun Microsystems,
Inc., used under license for technology invented and
implemented by Netscape.
MaxDB is a trademark of MySQL AB, Sweden.
SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP
NetWeaver, and other SAP products and services
mentioned herein as well as their respective logos are
trademarks or registered trademarks of SAP AG in
Germany and in several other countries all over the world.
All other product and service names mentioned are the
trademarks of their respective companies. Data contained
in this document serves informational purposes only.
National product specifications may vary.
These materials are subject to change without notice.
These materials are provided by SAP AG and its affiliated
companies ("SAP Group") for informational purposes only,
without representation or warranty of any kind, and SAP
Group shall not be liable for errors or omissions with
respect to the materials. The only warranties for SAP
Group products and services are those that are set forth in
the express warranty statements accompanying such
products and services, if any. Nothing herein should be
construed as constituting an additional warranty.
These materials are provided “as is” without a warranty of
any kind, either express or implied, including but not
limited to, the implied warranties of merchantability,
fitness for a particular purpose, or non-infringement.
SAP shall not be liable for damages of any kind including
without limitation direct, special, indirect, or consequential
damages that may result from the use of these materials.
SAP does not warrant the accuracy or completeness of the
information, text, graphics, links or other items contained
within these materials. SAP has no control over the
information that you may access through the use of hot
links contained in these materials and does not endorse
your use of third party web pages nor provide any warranty
whatsoever relating to third party web pages.
SAP NetWeaver “How-to” Guides are intended to simplify
the product implementation. While specific product
features and procedures typically are explained in a
practical business context, it is not implied that those
features and procedures are the only approach in solving a
specific business problem using SAP NetWeaver. Should
you wish to receive additional information, clarification or
support, please refer to SAP Consulting.
Any software coding and/or code lines / strings (“Code”)
included in this documentation are only examples and are
not intended to be used in a productive system
environment. The Code is only intended better explain and
visualize the syntax and phrasing rules of certain coding.
SAP does not warrant the correctness and completeness of
the Code given herein, and SAP shall not be liable for
errors or damages caused by the usage of the Code, except
if such damages were caused by SAP intentionally or
grossly negligent.
Disclaimer
Some components of this product are based on Java™. Any
code change in these components may cause unpredictable
and severe malfunctions and is therefore expressively
prohibited, as is any decompilation of these components.
Any Java™ Source Code delivered with this product is only
to be used by SAP’s Support Services and may not be
modified or altered in any way.
Document History
Document Version Description
1.00 First official release of this guide
1.10 Correction of error when using an integer or double field in the structure
1.20 Correction of error when using navigational attributes and own (non
content) characteristics:
Report Z_CREATE_DB_TABLE
Methods IF_RSPLS_LOGGING_ON_SAVE~LOG_WRITE_DB and
IF_RSPLS_LOGGING_ON_SAVE~LOG_STRUCTURE
Typographic Conventions
Type Style Description
Example Text Words or characters quoted
from the screen. These
include field names, screen
titles, pushbuttons labels,
menu names, menu paths,
and menu options.
Cross-references to other
documentation
Example text Emphasized words or
phrases in body text, graphic
titles, and table titles
Example text File and directory names and
their paths, messages,
names of variables and
parameters, source text, and
names of installation,
upgrade and database tools.
Example text User entry texts. These are
words or characters that you
enter in the system exactly as
they appear in the
documentation.
<Example
text>
Variable user entry. Angle
brackets indicate that you
replace these words and
characters with appropriate
entries to make entries in the
system.
EXAMPLE TEXT Keys on the keyboard, for
example, F2 or ENTER.
Icons
Icon Description
Caution
Note or Important
Example
Recommendation or Tip
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 1
Table of Contents
1. Scenario ................................................................................................................................ 2
2. General Description of the Solution .................................................................................. 2
3. Prerequisites ........................................................................................................................ 4
4. Step-by-Step Procedure ...................................................................................................... 5
4.1 Create a Structure for the Interface Table .................................................................... 5
4.2 Create the Database Table as Data Dictionary Object ................................................ 7
4.3 Create a Database Table directly in HANA .................................................................. 9
4.4 Create the Class for the Logging BAdI ....................................................................... 10
4.5 Create the Enhancement Spot Implementation ......................................................... 11
4.6 Test your Implementation/How to Debug ................................................................... 13
5. Appendix ............................................................................................................................ 15
5.1 ABAP Report for Creating HANA Table from Structure ............................................. 15
5.2 Class ZCL_LOG_BADI ............................................................................................... 18
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 2
1. Scenario
In the How to Paper…Log Changes in Plan Data Using DataStore Objects (see
http://scn.sap.com/docs/DOC-16124) we have given an example how to use the Logging BAdI in SAP
NetWeaver BW-IP.
This paper is building on this How to Paper and describes how the logging functionality can now also
be used in conjunction with HANA and the Planning Applications Kit (in memory planning on SAP
BW).
2. General Description of the Solution
Before the current version the BAdI could only be used in an ABAP environment. When used in a BW
on HANA environment with PAK (Planning Applications Kit) the logging would force the execution of
the entire planning model into ABAP and no planning functionality could be executed in HANA. With
the new version the BAdI still offers the old functionality and in addition is fully HANA compatible. Thus
planning functions and disaggregations in queries can also be executed in HANA when the logging is
used.
The logging BAdI is used for tracing the information about by whom and when some data has been
changed.
The old implementation class of the logging BAdI had three methods:
- one method for defining the structure used by the system to provide the records that are to
be locked,
- one method for defining whether a logging should be done for a specific InfoProvider (in
ABAP),
- one method that receives the records in the structure defined above and writes them to a
storage location (DSO or database table).
The new implementation adds two more methods:
- one method for defining whether a logging on database level should be done,
- one method that receives information about the records to be logged and that pushes these
records to a database table using database methods.
Thus the new methods correspond to the second and third method of the classical interface but are
used for logging on database level. We will go more into detail with the methods further down.
For further details on the functionality of the logging BAdI please have a look at the existing How to
Paper mentioned above. In the current paper we will deviate from the example in such a way that we
will not use a DataStore Object for storing the logging information but we will use a database table.
The database table contains all fields and key figures of the InfoCube or Data Store Object that is
logged. In addition it contains a field for the user, the date, the time, and for the saveid (important
when you use MultiProviders).
Let us have a look at the different methods of the BAdI Implementation. We will use the methods to
explain the behavior of the logging BAdI in the different environments.
When the logging is switched on for a given InfoProvider, then the system writes the changed records
with some user and system information (date, time, saveid) into a table that is later available in the
BAdI Implementation. From this (temporary) table the BAdI implementation needs to fill the (persistent)
logging table. Thus this temporary table establishes some sort of logical interface between the core
system and the BAdI implementation. As we want to make the implementation of the BAdI itself as
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 3
easy as possible the BAdI itself can define how this temporary handshake table should look like and
which information it should contain. This is done in the method:
IF_RSPLS_LOGGING_ON_SAVE~LOG_STRUCTURE.
The BAdI has to return the structure for handshake table and also tells the system which fields should
be filled (e.g. which field should be filled with the user name). It is a good idea to use the same
underlying structure for the handshake table as well as for the final logging table as in this case a
further transformation of the data is not necessary anymore.
The structure for the handshake table has to be known to the ABAP dictionary. Thus even if you
define the final logging table in HANA directly you still have to create the structure in the ABAP
dictionary.
The BAdI contains one method that indicates whether a logging should be done at all:
IF_RSPLS_LOGGING_ON_SAVE~LOG_DEFINED
and another method that indicates if – in addition – the logging should be done directly on the
database:
IF_RSPLS_LOGGING_ON_SAVE~LOG_DEFINED_DB.
Depending on what the underlying system is and which logging mechanism is implemented the
system will call the corresponding write method. There are two different write methods for filling the
final logging table:
IF_RSPLS_LOGGING_ON_SAVE~LOG_WRITE and
IF_RSPLS_LOGGING_ON_SAVE~LOG_WRITE_DB.
The IF_RSPLS_LOGGING_ON_SAVE~LOG_WRITE is called if the execution of the logging BAdI is
done in ABAP. This is the case if:
1. The underlying system is not using SAP HANA as a database and/or is not using the Planning
Applications Kit.
2. The method IF_RSPLS_LOGGING_ON_SAVE~LOG_DEFINED_DB returns a blank value (‘false’).
If the Planning Application Kit is used then the delta records will be transmitted to the ABAP
layer and the logging will be done there. This does not change the runtime behavior of the
planning functions – they are still executed in memory and also the buffer resides in the
HANA layer.
The advantage of using this option is that all existing logging BAdI implementations will run
without any changes being necessary. Also doing the write implementation in ABAP is
sometimes easier.
The disadvantage of this option is that the delta records need to be transported from the
HANA layer to the ABAP layer and thus we might have an impact on performance (depending
on the number of records).
In this case the method receives an internal ABAP table with the structure returned in the method
IF_RSPLS_LOGGING_ON_SAVE~LOG_STRUCTURE. The table is filled with the changed records
that are enhanced by the logging information. Depending on the target (final) logging table we can
either insert the records directly into the database table or will have to adapt the records accordingly.
If the logging is done in HANA directly then the system calls the method:
IF_RSPLS_LOGGING_ON_SAVE~LOG_WRITE_DB.
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 4
This method does not receive an internal (ABAP) table with the changed records but the name of a
temporary index in HANA that has a structure matching the structure returned before. This table
contains the delta records with the logging information. The records must be transferred into the final
logging table as the temporary table will be cleared regularly. Also the data must be transferred with
SQL methods as otherwise the data has to be moved to ABAP.
From the explanation above it is evident that it is advisable to use the same structure for the
handshake table as for the final logging table as this will make the coding in the write methods very
easy. Thus we will also use the same structure for both tables in this how to paper. Nevertheless
please keep in mind that this is not mandatory.
In our old how to paper we used a DataStore object for direct update for holding the logging
information. We do not recommend to use a DataStore object when directly updating the logging
information on the database (i.e. when you use IF_RSPLS_LOGGING_ON_SAVE~LOG_WRITE_DB
to update the logging table). When using the direct update in HANA then you cannot use the official
API to update the DataStore Object. Still one might think about writing to the underlying database
table directly. If you do this then you might cause system inconsistencies (e.g. with the Olap caching
mechanism). If you use the ‘old’ How to Paper solution then you should either continue using the
ABAP method in order to write your logging entries into the DataStore object or introduce a new
logging table that you fill directly in the HANA based method.
3. Prerequisites
The new version of the BAdI is delivered with SAP NetWeaver BW 7.30 SP9 and BW7.31 SP 7.
Alternatively you can implement note 1802658.
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 5
4. Step-by-Step Procedure
In this chapter we describe how the necessary underlying objects are created in the system. The
source code can be found in the appendix.
First we will create the necessary data elements, the structure, and the database table for holding the
log entries. The database table can either be created in the ABAP dictionary (via transaction se11,
se16, or se80) or directly in the database via an ABAP report. In both cases the ABAP runtime of the
logging BAdI has to know the structure of the handshake table. We can either create a structure
defining this table or create the database table in the dictionary.
When creating a database table in se16 we are restricted to 16 key fields. On the other hand such
tables can be easily maintained and viewed (including the content) from the ABAP transaction.
When you are using more than 16 key fields for the table (user, date, time, potentially saveid, all
necessary characteristics in the InfoCube) you have three options:
- Reduce the number of key fields in the database by eliminating unnecessary fields.
Unnecessary fields can be characteristics that are constant in the InfoCube (such as
0FISCVARNT, the fiscal year variant) or characteristics that can be derived.
- Create the logging table in se16 and add an additional (technical) field that is used as the
table key. Do not mark any other fields as keys. (see chapter 4.2)
- Do not create the database via se16 but directly in the database. Here you are freer on
setting keys in the table. (see chapter 4.3)
4.1 Create a Structure for the Interface Table
As explained above the logging BAdI needs the structure of the handshake table. The structure needs
to be known in the ABAP dictionary. If you want the structure of the handshake table to be identical to
the structure of the final logging table and if you create the final logging table in the ABAP dictionary
the structure is defined implicitly. In the method for returning the log structure you can simply return
the name of the database table and do not have to create a separate structure and can skip this step.
Note:
Not all InfoObjects in the InfoCube are usually necessary in the logging table and the
structure. The technical InfoObjects like record type (0RECORDTP) or request ID (0REQUID)
are purely technical and should not be used in the logging information.
Also navigational attributes do not bear any additional information (the value can be derived
from the underlying characteristic value). Thus we recommend not using them in the logging
information. If you do want to write the content of some navigational attributes into the logging
table then you will have to adopt our coding:
If a navigational attribute is used for several characteristics or also used a a characteristic in
the InfoCube then the default technical fieldname for all of them is the same. As we cannot
have the same technical fieldname for several columns in a table you will have to come up
with your own fieldnames for all of them and adapt the coding in the methods
IF_RSPLS_LOGGING_ON_SAVE~LOG_STRUCTURE and
IF_RSPLS_LOGGING_ON_SAVE~LOG_WRITE_DB.
As we assume that the information contained in navigational attributes is not necessary for the
logging we do not define fieldnames for navigational attributes in our mapping structure or
database table and do not fill any mapping information for the navigational attributes in the
method IF_RSPLS_LOGGING_ON_SAVE~LOG_STRUCTURE.
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 6
If you want the handshake table to be different from the final logging table or if you want to create the
final logging table directly in HANA then you have to create a structure in the ABAP dictionary.
Please go to transaction se80, choose a package and open the entry ‘dictionary object’. Use a right
mouse click on ‘structures’ and choose ‘create’.
In our structure we need fields for the predefined elements of the logging structure (user, date, time,
saveid), the characteristics, and the key figures. Remember that the field name cannot start with a
number, thus you cannot use the standard characteristic/key figure names as field names. Thus in our
case we use the standard BW fieldnames of the characteristics and key figures. Usually it is the
characteristic/key figure name without the leading 0. If in doubt you can go to transaction rsd1 and
display the InfoObject. When you have a look at the master data table you will see which fieldname
was used. Alternatively you can go to transaction se37 and run the function module
‘BAPI_IOBJ_GETDETAIL’ in test mode. You can enter the name of your InfoObject as
‘infoobject’ and will obtain the resulting field name in ‘l_s_details-fieldnm’.
Now we enter the corresponding data elements. For the user, date, and time we can use predefined
data elements, for the saveid we use the data element ‘SYSUUID_C’, and for the characteristics and
key figures we use the data elements generated by BW. The names of the data elements can be
found for each characteristic/key figure in transaction ‘rsd1’.
As an example we show a structure that corresponds to the structure of the database table in the next
chapter. We are using the same logic for the defining the field names from the InfoObject names.
Please note that for the saveid you can use the data element ‘SYSUUID_C’.
Keep in mind that using the saveid is not mandatory. The saveid is used to identify data that was
saved in the same step but is stored in different InfoCubes. If you do not save to several InfoCubes in
one step in your scenario then you do not have to include the saveid into the database table. You will
also have to adopt the coding in such a way that saveid is not used when returning the structure and
when writing the log entries onto the database table.
As we are using key figures with currencies or units and thus the respective domains also point to a
currency or unit field we have to set this information. Click on the tabe ‘Currency/quantity fields’. For
your key figures enter the name of your structure as reference table and the name of the currency or
unit field in your structure – in our case we only need a currency field. The field name is ‘currency’ (the
characteristic name is 0CURRENCY).
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 7
Activate your structure.
4.2 Create the Database Table as Data Dictionary
Object
Now we create our database table in the ABAP dictionary. If you want to or must create the table
directly in HANA then please skip this section.
Continue with transaction se11 (or se16), enter a name for the table, and press ‘Create’. Enter a name
for the table, a delivery class, and whether the entries can be changed.
Switch to the tab ‘Fields’ and enter the fields for the table. We use the same logic for the field names
and for the data elements as described in the section above.
We first want to show an example where we have less than 13 characteristics and thus less than 16
key fields in the database table. Thus we mark all fields for the characteristics, user, time, and date as
keys of the table. The key figures never have to be part of the key.
If wanted also add the saveid. You do not have to put it into the primary key of the table. Each record
in the logging table will be uniquely be determined by the user, date, time, and the set of all
characteristics in the table.
In our example we have used the characteristics 0CALYEAR, 0CALMONTH, 0CURRENCY,
0D_NW_PROD, 0D_NW_VERS, 0D_NW_SORG, 0D_NW_REGIO, and 0D_NW_CNTRY. The key
figures are 0D_NW_NETV, 0D_NW_TRNSP, and 0D_NW_PRDCS
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 8
As in the chapter above, you have to enter some information about the currency/quantity fields.
Choose the corresponding tab strip; enter the name of your table as reference table and the name of
the corresponding currency or unit field.
Finally set an appropriate enhancement category for your table and activate the table.
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 9
If you are using more than 13 characteristics in the logging table and thus end up with more than 16
key fields we can use an additional (technical) key field in the table and use it as the only key.
Please insert an field called ‘MYSYSUUID’ into the table. As corresponding data element use
‘SYSUUID_C’. This field will be filled by a unique id by the system and will serve as the only key field
in the table. Please make sure that no other fields are marked as key fields.
If you want to use another name for your (technical) key field you will habve to adopt the coding in the
implementing class accordingly. Please note the remark in the class implementation – in order to fill
the technical key (in our case ‘MYSYSUUID’) we use an sql function called ‘SYSUUID’. This name
should NOT be changed in the coding.
4.3 Create a Database Table directly in HANA
If you need more than 16 logical key fields and do not want to use a technical key as described above
you can create the database table directly in HANA. Here we have to keep in mind that the BW and
thus the logging BAdI implementation can only access tables in the BW related database schema. If
you start HANA studio then you can only create a table in this database schema if you are logged on
as the main database user used by the ABAP server/BW. Thus it is easier to use an ABAP report that
generates the database table in the correct schema from the application server.
Please go to transaction se38 and create a new program. Use the ABAP coding from the appendix.
Do not forget to activate the report.
Now you can execute the report. On the initial screen please enter the name of the handshake
structure you have created above and press the execute button. The report will read the definition of
the structure and generate a database table directly in HANA. The table contains the same fields as
the structure. As we do not use a primary key in our table the table can have more than 16 logical
keys.
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 10
As stated above the handshake table does not need to have the same structure as the final logging
table (though it usually makes sense). If you want the final logging table to have a structure different
from the handshake table then you have to create an additional structure matching the logging table
and run the report with this structure name. You will also have to adopt the coding of the logging BAdI
accordingly.
4.4 Create the Class for the Logging BAdI
Please go to transaction se24 (or transaction se80) and create a new class called ‘ZCL_LOG_BADI’.
As you are in a BW 7.30 (or higher) system you can easily copy and paste the class with all properties
and methods and their implementations.
Switch to the source code based mode of the class.
You now can simply copy and paste the class definition with all its coding from the appendix.
When you are done just switch back to the form-based (normal) mode and activate the class.
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 11
In the coding of all methods you will have to adopt the name(s) of your InfoCube(s), the strcutcture,
and the data target.
4.5 Create the Enhancement Spot Implementation
Create a New Enhancement Implementation
Go to the transaction se18. Enter the name of the enhancement spot (RSPLS_LOGGING_ON_SAVE)
and press the button ’Change’.
In the next screen choose the tab ‘Enhancement Implementations’. If there are already some
implementations for the BAdI you will find them here.
From the menu choose the button for creating a new enhancement spot implementation.
On the next screen enter a name and a description of your BAdI implementation.
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 12
Now enter the name of the implementation and the name of the class containing your implementation.
Also select the BAdI definition from the drop down box.
Set the properties of the implementation.
In the next screen you can set the properties of your implementation. Please check that your
implementation is set to active.
Now expand the node with for your BAdI implementation and click on ‘Filter Values’.
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 13
Now you can specify for which InfoCube your current BAdI implementation is called. For a new
combination please press the button ‘Combination’.
By double clicking on the ‘????’ in the line you will get a popup where you can enter the selection for
the InfoCube (use the name of your InfoCube).
Now save and activate your new implementation.
4.6 Test your Implementation/How to Debug
The easiest way to test your application is to start a plan query or a planning application, change some
numbers, save the data and check the logging table whether the log entry has been written correctly
into the database.
If you want to follow more in detail what is happening in your logging implementation you probably
want to debug the application. Unfortunately if you just set a break-point in one of your methods
writing the data to the logging table and change and save plan data (from any frontend) the system will
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 14
NOT stop at the break-point. The reason for this is that the logging BAdI is executed in the V2-update
task. In order to debug an update task you will have to use a special setting in the debugger.
The easiest way to debug your application is to set a break-point that is reached BEFORE the write
method of the logging BAdI is called, switch to the special debugging mode, and then continue until
you will stop in your write back method.
Call your class that implements the logging BAdI and set a break-point in the method
IF_RSPLS_LOGGING_ON_SAVE~LOG_STRUCTURE. This method will NOT be called in the update
task. Now set a second break-point at the actual coding you want to debug in method
IF_RSPLS_LOGGING_ON_SAVE~LOG_WRITE_DB.
Now execute your plan query or planning application. The system will stop at method where you
define the log structure (please remember – when using a web application or Analysis for Office you
will have to use an external break-point).
Now switch the update debugging on: in the new debugger choose the menu entry ‘Settings’, then
‘Change Debugger Profile/Settings’. On the popup for the debugger settings tag the flag ‘Update
Debugging’. Press ok.
Now continue with the program (by pressing F8). You can now change some data in your plan query
and save the data. The system will now stop in your implemented class.
If you are using the classical debugger then choose the menu entry ‘Settings’, then ‘Update
debugging’.
If you are encountering problems with the sql script then you can have a look at the catch statement at
the end of the write back implementation. When debugging the problem the object l_r_cx_root
contains information about the error and will also show the error message explaining the Hana error.
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 15
5. Appendix
5.1 ABAP Report for Creating HANA Table from
Structure
*&---------------------------------------------------------------------*
*& Report Z_CREATE_DB_TABLE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_CREATE_DB_TABLE.
DATA:
l_r_connection TYPE REF TO cl_sql_connection,
l_r_statement TYPE REF TO cl_sql_statement,
l_sql_statement TYPE string,
l_field_list type string,
l_r_cx_root TYPE REF TO CX_ROOT,
l_o_structdesc TYPE REF TO cl_abap_structdescr,
l_t_components TYPE abap_component_tab,
l_s_components LIKE LINE OF l_t_components,
l_target TYPE ADBC_NAME,
l_schema TYPE ADBC_NAME,
l_s_dd04l type dd04l,
l_s_dbdomain type DBDOMAIN,
l_r_elemdescr type ref to CL_ABAP_ELEMDESCR,
l_fieldname type string.
PARAMETERS: struct(20) type c.
* l_target = struct.
* the name of the schema consist of the prefix 'SAP' and the system name.
CONCATENATE 'SAP' sy-sysid into l_schema.
concatenate '"' l_schema '"."' struct '"' into l_target.
TRY.
* get the fields of the logging table
l_o_structdesc ?= cl_abap_typedescr=>describe_by_name( struct ).
l_t_components = l_o_structdesc->get_components( ).
* open the data abse connection
l_r_connection = cl_sql_connection=>get_connection( ).
* fill the sql statement
l_r_statement = l_r_connection->create_statement( ).
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 16
* sample statement:
*drop table ZIC_02_LOG;
*create column table ZIC_02_LOG
*(
* MYUSER nvarchar(12),
* MYDATE nvarchar(8),
* MYTIME nvarchar(6),
* CALYEAR nvarchar(4),
* CALMONTH nvarchar(6),
* CURRENCY nvarchar(5),
* UNIT nvarchar(3),
* [...]
* D_NW_QUANT decimal(17,3),
* D_NW_REB decimal(17,3),
* D_NW_TRNSP decimal(17,3),
* SAVEID nvarchar(32)
*
* );
loop at l_t_components into l_s_components.
*name is the name in the structure
* type is a class, help_id in the class contains the data element
l_r_elemdescr ?= l_s_components-type.
* get the ABAP information
select single * from dd04L into l_s_dd04l where rollname = l_r_elemde
scr->help_id.
* get the BD type
CALL FUNCTION 'DB_MAP_DDTYPE'
EXPORTING
DATATYPE = l_s_dd04l-datatype
* DBSYS = SY-DBSYS
DECIMALS = l_s_dd04l-decimals
LENG = l_s_dd04l-leng
* WITH_CHECK = ' '
* WITH_STRING = ' '
IMPORTING
DBDOMAIN = l_s_dbdomain
* TYPESTRING =
* EXCEPTIONS
* NOT_MAPPABLE = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
exit.
ENDIF.
clear l_fieldname.
concatenate '"' l_s_components-name '"' into l_fieldname.
if l_s_dbdomain-type = 'DECIMAL'.
concatenate
l_field_list
l_fieldname
l_s_dbdomain-type '(' l_s_dbdomain-length ',' l_s_dbdomain-
decimals '),'
into
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 17
l_field_list SEPARATED BY SPACE.
elseif l_s_dbdomain-type = 'INTEGER' or l_s_dbdomain-
type = 'DOUBLE'.
concatenate
l_field_list
l_fieldname
l_s_dbdomain-type ','
into
l_field_list SEPARATED BY SPACE.
else.
concatenate
l_field_list
l_fieldname
l_s_dbdomain-type '(' l_s_dbdomain-length '),'
into
l_field_list SEPARATED BY SPACE.
endif.
endloop.
shift l_field_list RIGHT DELETING TRAILING ','.
* make sure we have any fields at all!
check not l_field_list is INITIAL.
* clear the old table
concatenate
'drop table'
l_target
into l_sql_statement SEPARATED BY SPACE.
CATCH cx_root INTO l_r_cx_root.
MESSAGE E000(00) with 'Table creation failed.'.
exit.
ENDTRY.
try.
* execute the sql statement
CALL METHOD l_r_statement->execute_query
EXPORTING
statement = l_sql_statement.
CATCH cx_root INTO l_r_cx_root.
* MESSAGE E000(00) with 'Table creation failed.'.
* exit.
* If we have an error here then probably the data table does not exist yet.
So just continue.
ENDTRY.
try.
* build up the actual statement
clear l_sql_statement.
concatenate
'create column table'
l_target
'('
l_field_list
')'
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 18
into l_sql_statement SEPARATED BY SPACE.
* execute the sql statement
CALL METHOD l_r_statement->execute_query
EXPORTING
statement = l_sql_statement.
l_r_connection->close( ).
CATCH cx_root INTO l_r_cx_root.
MESSAGE E000(00) with 'Table creation failed.'.
exit.
ENDTRY.
Write: 'The table ', l_target, ' has been created successfully in schema ',
l_schema, '.' .
5.2 Class ZCL_LOG_BADI
class ZCL_LOG_BADI definition
public
final
create public .
public section.
*"* public components of class ZCL_LOG_BADI
*"* do not include other source files here!!!
interfaces IF_BADI_INTERFACE .
interfaces IF_RSPLS_LOGGING_ON_SAVE .
protected section.
*"* protected components of class ZCL_LOG_BADI
*"* do not include other source files here!!!
private section.
*"* private components of class ZCL_LOG_BADI
*"* do not include other source files here!!!
ENDCLASS.
CLASS ZCL_LOG_BADI IMPLEMENTATION.
* <SIGNATURE>--------------------------------------------------------------
-------------------------+
* | Instance Public Method ZCL_LOG_BADI-
>IF_RSPLS_LOGGING_ON_SAVE~LOG_DEFINED
* +------------------------------------------------------------------------
-------------------------+
* | [--->] I_INFOCUBE_NAME TYPE TN_INFOCUBE_NAME
* | [<-()] R_LOG_DEFINED TYPE RS_BOOL
* +------------------------------------------------------------------------
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 19
--------------</SIGNATURE>
method IF_RSPLS_LOGGING_ON_SAVE~LOG_DEFINED.
r_log_defined = rs_c_true.
endmethod.
* <SIGNATURE>--------------------------------------------------------------
-------------------------+
* | Instance Public Method ZCL_LOG_BADI-
>IF_RSPLS_LOGGING_ON_SAVE~LOG_DEFINED_DB
* +------------------------------------------------------------------------
-------------------------+
* | [--->] I_INFOCUBE_NAME TYPE TN_INFOCUBE_NAME
* | [<---] E_LOG_DEFINED_DB TYPE RS_BOOL
* +------------------------------------------------------------------------
--------------</SIGNATURE>
method IF_RSPLS_LOGGING_ON_SAVE~LOG_DEFINED_DB.
e_log_defined_db = rs_c_true.
endmethod.
* <SIGNATURE>--------------------------------------------------------------
-------------------------+
* | Instance Public Method ZCL_LOG_BADI-
>IF_RSPLS_LOGGING_ON_SAVE~LOG_STRUCTURE
* +------------------------------------------------------------------------
-------------------------+
* | [--->] I_INFOCUBE_NAME TYPE TN_INFOCUBE_NAME
* | [--->] I_T_MAP_PROPOSAL TYPE TN_T_MAP_PROPOSAL
* | [<---] E_STRUCTURE_NAME TYPE TN_STRUCTURE_NAME
* | [<---] E_T_MAP TYPE TN_T_MAP
* +------------------------------------------------------------------------
--------------</SIGNATURE>
method IF_RSPLS_LOGGING_ON_SAVE~LOG_STRUCTURE.
data: l_s_map type IF_RSPLS_LOGGING_ON_SAVE=>tn_s_map,
l_s_map_proposal type IF_RSPLS_LOGGING_ON_SAVE=>tn_s_map_proposal,
l_s_details TYPE bapi6108,
l_s_return TYPE bapiret2,
descr_ref TYPE ref to cl_abap_structdescr,
dref type ref to data,
l_atr TYPE RS_BOOL.
FIELD-SYMBOLS:
<fs> type any.
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 20
* check the name of your InfoCube here and set the correct structure
case i_infocube_name.
when 'GS_IC_01'.
e_structure_name = 'ZIC_01_LOG'.
when others.
exit.
endcase.
* get the list of fields in the mapping target structure
create data dref type (e_structure_name).
ASSIGN dref->* TO <fs>.
descr_ref ?= cl_abap_typedescr=>describe_by_data( <fs> ).
* simply do a one to one mapping -
as a data base field cannot start with '0' we use the standard
* field name of charatceristic/key figure
clear e_t_map[].
loop at i_t_map_proposal into l_s_map_proposal.
clear l_s_map.
case l_s_map_proposal-field_type.
when IF_RSPLS_LOGGING_ON_SAVE=>N_C_FIELD_TYPE-user.
l_s_map-iobj_name = l_s_map_proposal-iobj_name.
l_s_map-field_name = 'MYUSER'.
insert l_s_map into table e_t_map.
when IF_RSPLS_LOGGING_ON_SAVE=>N_C_FIELD_TYPE-date.
l_s_map-iobj_name = l_s_map_proposal-iobj_name.
l_s_map-field_name = 'MYDATE'.
INSERT l_s_map INTO TABLE e_t_map.
when IF_RSPLS_LOGGING_ON_SAVE=>N_C_FIELD_TYPE-time.
l_s_map-iobj_name = l_s_map_proposal-iobj_name.
l_s_map-field_name = 'MYTIME'.
INSERT l_s_map INTO TABLE e_t_map.
when IF_RSPLS_LOGGING_ON_SAVE=>N_C_FIELD_TYPE-saveid.
l_s_map-iobj_name = l_s_map_proposal-iobj_name.
l_s_map-field_name = 'SAVEID'.
INSERT l_s_map INTO TABLE e_t_map.
when IF_RSPLS_LOGGING_ON_SAVE=>N_C_FIELD_TYPE-characteristic
or IF_RSPLS_LOGGING_ON_SAVE=>N_C_FIELD_TYPE-keyfigure.
l_s_map-iobj_name = l_s_map_proposal-iobj_name.
clear: l_s_return, l_s_details, l_atr.
CALL FUNCTION 'BAPI_IOBJ_GETDETAIL'
EXPORTING
version = rs_c_objvers-active
infoobject = l_s_map_proposal-iobj_name
IMPORTING
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 21
details = l_s_details
return = l_s_return
IS_ATR = l_atr .
IF l_s_return IS INITIAL and l_atr is initial.
* check whether the InfoObject is used in the structure
read table descr_ref->components with key
name = l_s_details-fieldnm transporting no fields.
if sy-subrc = 0.
l_s_map-field_name = l_s_details-fieldnm.
INSERT l_s_map INTO table e_t_map.
endif.
ENDIF.
endcase.
ENDLOOP.
endmethod.
* <SIGNATURE>--------------------------------------------------------------
-------------------------+
* | Instance Public Method ZCL_LOG_BADI->IF_RSPLS_LOGGING_ON_SAVE~LOG_WRITE
* +------------------------------------------------------------------------
-------------------------+
* | [--->] I_INFOCUBE_NAME TYPE TN_INFOCUBE_NAME
* | [--->] I_STRUCTURE_NAME TYPE TN_STRUCTURE_NAME
* | [--->] I_REQUEST_ID TYPE RSREQUNR
* | [--->] I_T_LOGGING_DATA TYPE STANDARD TABLE
* +------------------------------------------------------------------------
--------------</SIGNATURE>
method IF_RSPLS_LOGGING_ON_SAVE~LOG_WRITE.
DATA: l_target TYPE tabname16.
* case i_infocube_name.
* when 'GS_IC_02'.
* l_target = 'ZIC_02_LOG'.
*
* when others.
* exit.
* endcase.
*
* insert (l_target) from table I_T_LOGGING_DATA.
endmethod.
* <SIGNATURE>--------------------------------------------------------------
-------------------------+
* | Instance Public Method ZCL_LOG_BADI-
>IF_RSPLS_LOGGING_ON_SAVE~LOG_WRITE_DB
* +------------------------------------------------------------------------
-------------------------+
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 22
* | [--->] I_INFOCUBE_NAME TYPE TN_INFOCUBE_NAME
* | [--->] I_STRUCTURE_NAME TYPE TN_STRUCTURE_NAME
* | [--->] I_REQUEST_ID TYPE RSREQUNR
* | [--->] I_LOGTAB_NAME TYPE TN_LOGTAB_NAME
* +------------------------------------------------------------------------
--------------</SIGNATURE>
method IF_RSPLS_LOGGING_ON_SAVE~LOG_WRITE_DB.
DATA:
l_r_connection TYPE REF TO cl_sql_connection,
l_r_statement TYPE REF TO cl_sql_statement,
l_sql_statement TYPE string,
l_field_list type string,
l_field_list2 type string,
l_r_cx_root TYPE REF TO CX_ROOT,
l_o_structdesc TYPE REF TO cl_abap_structdescr,
l_t_components TYPE abap_component_tab,
l_s_components LIKE LINE OF l_t_components,
l_name type string,
l_name2 type string.
DATA: l_target TYPE tabname16.
case i_infocube_name.
when 'GS_IC_01'.
l_target = 'ZIC_01_LOG'.
when 'GS_IC_02'.
l_target = 'ZIC_02_LOG'.
when 'GS_IC_03'.
l_target = 'ZIC_03_LOG'.
when others.
exit.
endcase.
TRY.
* get the fields of the logging table
l_o_structdesc ?= cl_abap_typedescr=>describe_by_name( l_target ).
l_t_components = l_o_structdesc->get_components( ).
* open the data abse connection
l_r_connection = cl_sql_connection=>get_connection( ).
* fill the sql statement
l_r_statement = l_r_connection->create_statement( ).
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 23
* target statement:
* INSERT INTO TARGET_NAME ( MYSYSUUID, MYMYUSER , MYDATE , MYTIME , CHAR1 ,
CHAR2 , ... , KYF1 , KYF2 )
* SELECT SYSUUID, MYUSER , MYDATE , MYTIME , CHAR1 , CHAR2 , ... , KYF1 , K
YF2 FROM I_LOG_TABLE
* fill a string with the names of the characteristics separated by ','
loop at l_t_components into l_s_components.
if l_s_components-name = 'MYSYSUUID'.
* Do NOT change l_name2 -
SYSUUID is the name of a predefined function in sql. This name is independ
ent of the
* name you have chosen for your guid in the target table (in our case MYSYS
UUID).
l_name = l_s_components-name.
l_name2 = 'SYSUUID'.
else.
clear: l_name, l_name2.
concatenate '"' l_s_components-name '"' into l_name.
l_name2 = l_name.
endif.
if l_field_list is initial.
l_field_list = l_name.
l_field_list2 = l_name2.
else.
concatenate l_field_list ',' l_name
into l_field_list SEPARATED BY SPACE.
concatenate l_field_list2 ',' l_name2
into l_field_list2 SEPARATED BY SPACE.
endif.
ENDLOOP.
* make sure we have any fields at all!
check not l_field_list is INITIAL.
* build up the actual statement
concatenate 'INSERT INTO'
l_target
'('
l_field_list
')'
'SELECT'
l_field_list2
'FROM'
I_LOGTAB_NAME
into l_sql_statement SEPARATED BY SPACE.
* execute the sql statement
CALL METHOD l_r_statement->execute_query
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
May 2014 24
EXPORTING
statement = l_sql_statement.
l_r_connection->close( ).
CATCH cx_root INTO l_r_cx_root.
MESSAGE A000(00) with 'LOGGING FAILED'.
ENDTRY.
endmethod.
ENDCLASS.
www.sdn.sap.com