How to...Create a Characteristic Relationship type SQL

SAP NetWeaver
SAP
NetWeaver
How-To
Guide
How-To Guide
How to...Create a Characteristic
Relationship type SQL-script
Applicable Releases:
SAP NetWeaver BW 7.40, SP5 and higher; Note 2396898
SAP HANA 1.0
Version 1.0
December 2016
© Copyright 2016 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
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...Create a Characteristic Relationship type SQL-script
Table of Contents
1.
Scenario ................................................................................................................................ 2
2.
General Description of the Solution .................................................................................. 2
3.
Step by Step Solution.......................................................................................................... 3
3.1
Create an ABAP Class Implementing the Characteristic Relationships in ABAP ........ 3
3.2
Create the Characteristic Relationships in Transaction RSPLAN ................................ 3
3.3
Concepts of SQL-script based Relationships ............................................................... 4
3.4
Create the Parameter Structure ................................................................................... 5
3.5
Use Script Tool to Enhance the ABAP CLASS with SQL-script ................................... 6
3.6
Fill the Parameters........................................................................................................ 7
3.7
Implement the Business Logic in the AMDPs .............................................................. 8
3.8
4.
3.7.1
Check Method .................................................................................................. 9
3.7.2
Create Method ................................................................................................. 9
3.7.3
Derive Method ................................................................................................ 10
Test your Characteristic Relationship ......................................................................... 10
Coding Example................................................................................................................. 13
December 2016
1
How to...Create a Characteristic Relationship type SQL-script
1.
Scenario
In almost every planning project in SAP BPC 10.1 Embedded model (or PAK) it is necessary to use
characteristic relationships to control the consistency of the data in the system. And quite often it is
necessary to use exits for those relationships as the special relationships cannot be modeled in
hierarchies, attributes, or DSO’s.
Now when you are using ABAP exits for the characteristic relationships unfortunately the system
cannot evaluate the relationships in HANA and thus the execution of the entire planning application
will be forced to ABAP (see note 1637199). In this paper we describe how this behavior can be
changed by using SQL-script coding for the characteristic relationships.
2.
General Description of the Solution
Before we go into detail and describe how you implement your characteristic relationships in SQLscript we want to remind you of an option how you still can use your ABAP exits without forcing the
system to do all the work in ABAP.
In some cases it is necessary to use an exit in order to fulfill the business requirements but the
number of records returned from the ABAP exit is reasonably small. In this case the system reads all
the necessary data into ABAP, executes the ABAP exit for the relationship, and sends the result as a
table to HANA. Then this table is used to perform the actual relationship on HANA. Now how can you
force the system to execute the described behavior? You simply have to add the interface
IF_RSPLS_CR_EXIT_HDB to your class the relationships are based on, implement the two methods
in the interface (IF_RSPLS_CR_EXIT_HDB~GET_SQLSCRIPT_INFO and
IF_RSPLS_CR_EXIT_HDB~GET_SQLSCRIPT_PARAMETERS) but leave the implementations empty.
The system will detect that situation and will show the above behavior. This ‘ABAP fallback’ will in
many cases allow you to simply continue using your ABAP implementations of the characteristic
relationships without the need to do any SQL-script programming. You will find more information on
this approach in SAP note 1956085 containing also more detailed information in which cases this
fallback will lead to good results and a further implementation in SQL-script is not necessary. So when
you already have an ABAP exit implementation simply have a look at the prerequisites and try out the
ABAP fallback. If the performance is good then you are fine and do not have to dig deeper into SQLscript programming. If not – or provided you are just curious to learn how you can do the
implementation in SQL-script – then please enjoy the rest of this How to paper.
We want to illustrate the way to proceed with a simple system example. Let us assume we use a
characteristic for material group and a characteristic for material. Obviously each material is contained
in exactly one material group. We could simply model the relationship between the two characteristics
by an attribute or a DSO but in our case we want to use this simple example for illustrating the
techniques for SQL-script based characteristic relationships.
December 2016
2
How to...Create a Characteristic Relationship type SQL-script
3.
Step by Step Solution
3.1 Create an ABAP Class Implementing the
Characteristic Relationships in ABAP
Well – this might come as a complete surprise to you. Didn’t you want to learn about the
implementation of characteristic relationships in SQL-script? Well – yes. But there are several reasons
you should start with the implementation in ABAP:
- When you execute certain planning functions (ABAP exit or planning functions with several
conditions, see note 1637199) the system switches from in-memory execution to ABAP
execution. In these cases the same checks must be performed as in the case of an in-memory
execution.
- When creating and checking (visible) cells in input enabled queries the system still uses ABAP
coding and thus the information about the valid combinations must be available in ABAP.
When an automatic disaggregation is executed in a query the system calls the SQL-script
methods (if available).
- When you are not yet on BW 7.50 SP4 then the create method is not yet available in HANA
and must be implemented in ABAP anyway.
- You need an ABAP wrapper class to implement the SQL-script logic. This is similar to the
case of planning functions with SQL-script exits (see How to... Use SQLScript for Planning
Functions in PAK). This class will hold the ABAP implementation of the relationship as well as
a function module returning the name of the SQL-script methods. Even if these methods could
be implemented in HANA directly it definitely makes sense to implement the SQL-script coding
in an AMDP (ABAP managed database procedure) contained in your ABAP class.
For more information on AMDP’s please have a look at the system documentation, at the blog How to
debug ABAP Managed Database Procedures using ADT – Basics, or at the paper How To...Use Data
from Another Aggregation Level in a PAK SQL-Script Procedure - Implemented as an AMDP Example.
The easiest way to implement such an ABAP class for a characteristic relationship is to open and copy
the shipped class CL_RSPLS_CR_EXIT_BASE. It contains all necessary interfaces (for the ABAP
implementation) and (empty) methods. You just have to implement your business logic in the check,
create, and derive methods in your class. You can find a simple example in our sample class in
chapter 4.
Remark: In our sample coding we have adopted the coding of the delivered class a bit. In the
delivered class we use an ‘internal’ buffer. With note 1067433 we have introduced the ‘external’
buffering which we use in our sample coding. So we have adopted the list of attributes of our class
and have deleted the coding for the internal buffering at the end of the constructor.
3.2 Create the Characteristic Relationships in
Transaction RSPLAN
Open the transaction ‘rsplan’ and go to the InfoProvider maintenance. Change to the tab
‘Characteristic Rels’ and create your relationship. Press the ‘Create’ button, select the check box ‘with
derivation’, select the type ‘Exit’ from the drop down box, and enter the name of your exit class.
December 2016
3
How to...Create a Characteristic Relationship type SQL-script
Now specify the source and target characteristics of the relationship. In our case we use the material
as source and the material group as target.
Save your settings. You can now test your characteristic relationship – either by creating a manual
step in a planning sequence, a planning function, or a query.
3.3 Concepts of SQL-script based Relationships
Before we start to implement our SQL-script methods we have to understand the concepts. In ABAP
you create a class the implements the interface ‘IF_RSPLS_CR_METHODS’ and implement its
methods ‘CHECK’, ‘DERIVE’, and ‘CREATE’. Now when you look at the interface you will find
additional methods – ‘CHECK_HBD’, ‘DERIVE_HBD’, and ‘CREATE_HBD’. One might be tempted to
implement these methods and call some SQL-script methods from there. This is unfortunately the
wrong approach. These methods are NOT used to implement custom logic of SQL-script based
characteristic relationships.
Instead you have to implement the interface ‘IF_RSPLS_CR_EXIT_HDB’ in your class. This interface
contains two methods: ‘GET_SQLSCRIPT_INFO’, and ‘GET_SQLSCRIPT_PARAMETERS’.
In the method ‘GET_SQLSCRIPT_INFO’ you return the names of the SQL-script methods
implementing the check, the derive, and the create. The actual business logic is then contained in the
SQL-script methods themselves which will be called by the system when needed. You can implement
the methods directly in HANA but most probably you want to implement them as AMDPs directly in
your ABAP class.
In order to come up with the correct results in your SQL-script methods you might need additional
information in SQL-script. You can define your own parameters when defining the SQL-script
methods. But what should be filled into those parameters? This is up to you – when the system calls
the SQL-script methods it will first call the (ABAP) method ‘GET_SQLSCRIPT_PARAMETERS’. You
can fill your information into the parameters and the system will make sure that the SQL-script
methods receive this information. If you do not need any parameters then an empty implementation of
this method will be enough.
In this paper we will use an example with additional parameters. We will elaborate where you have to
deviate from our example if you do not need parameters.
December 2016
4
How to...Create a Characteristic Relationship type SQL-script
3.4 Create the Parameter Structure
Obviously this step is only necessary if you want to use parameters. In order to define the technical
types of the parameters you will have to create a structure in the ABAP dictionary.
Open transaction se11 and enter a name for your structure (as Data type). Press ‘Create’.
On the popup choose ‘Structure’.
Enter a name for the structure. Now you can decide how many parameters you will need in your SQLscript methods – each component of the structure will be one parameter in the SQL-script method. In
our example we need only one parameter and thus one component. As we want to transmit a
selection (that will result in a where clause) we call the parameter ‘I_WHERE’ and use the data type
‘STRING’.
Remark: in your structure you can only use elementary data types (no tables). The SQL-script method
will receive a list of elementary parameters.
In order to be able to use the built-in type you have to click on the corresponding button first.
Enter the type and a description and activate the structure.
December 2016
5
How to...Create a Characteristic Relationship type SQL-script
3.5 Use Script Tool to Enhance the ABAP CLASS with
SQL-script
Now we can create the ABAP wrapper for our SQL-script methods. You can create the ABAP class by
hand inserting all necessary interfaces and methods. What is way more advisable is to use the report
‘RSPLS_SQL_SCRIPT_TOOL’ that offers a number of services around SQL-script functionality in the
system. It can be used to create coding samples for SQL-script planning functions, data slices, and
also characteristic relationships.
Just start transaction se38 and run the report. Change to the tab ‘Sample Characteristic
Relationships/Data Slices’. Choose the radio button ‘Characteristic Relationships’ and enter the name
of your InfoProvider and the sequential number of the characteristic relationship you want to work on
(if you have only one relationship then just enter 1).
Make sure that the flag ‘With coding hints’ is set. Finally (but only if you want to use parameters) enter
the name of the structure you have just defined and press F8/execute.
The system will generate some sample coding you can insert in your class you have created for the
ABAP exits. Please note that the yellow fields are navigation enabled – you can jump directly by
clicking to the InfoProvider definition, the ABAP class, or the definition of the involved characteristics.
In order to insert the coding into your existing class you have to open the class either in the BW
backend (se80 or se24) or in the new eclipse based ABAP modelling tools. When using the ABAP
way you have to switch to the source code-based mode.
December 2016
6
How to...Create a Characteristic Relationship type SQL-script
Please note in addition that the template generated by our report uses AMDPs and maintaining
AMDPs is technically not allowed in the ABAP environment (only in the new eclipse based ABAP
modeler).
There is a work around though – if you want to still edit the class in ABAP go to your user parameters
(su01) and add the parameter ‘SEO_SOURCEBASED_AMDP’. Then you can maintain those classes
also in ABAP.
Now go ahead and insert the coding into the proper areas (public section of class definition and class
implementation) of your class (see also chapter 4 for the example). You should copy also the
commented coding as we will need it later as well (for example for easily using the data selection, see
below).
Remark: the type tn_s_chas is used as a basis of the (incoming or outgoing) tables of the AMDPs. It
consists of fields matching the characteristics used in the characteristic relationship, the types
correspond to the ABAP types of the characteristics.
The actual SQL-script coding is contained in the three AMDPs ‘AMDP_CHECK’, ‘AMDP_CREATE’,
and ‘AMDP_DERIVE’. Please notice that all three methods have an importing parameter ‘i_where’
that we have defined with our parameter structure.
3.6 Fill the Parameters
Again this chapter is only important if you are using parameters in your SQL-script methods. So what
do we want to transmit in the parameter? Especially for the create methods it is very interesting to
know the selection for which the new combinations should be generated. If you generate new
combinations outside the selection in ABAP and these combinations are used in a planning function
then you will even run into an error (in queries the system should apply a filter after the generation). In
HANA the system is more forgiving (the system applies a filter on the generated records) but still by
definition you should not return characteristic combinations outside the selection and – by the way - it
does not make sense to generate say thousands of combinations that will not be used anyway as they
are not in the selection. Luckily the system provides us with the information about the selection but we
have to make sure that the SQL-script methods receive the information.
Before working on filling the parameter you should check that the parameter is known to the system.
Make sure that the name and the type of the parameter is made known to the system in the method
‘get_sqlscript_info’:
e_parameter_name = 'CRDEMOSTRUC'.
Also make sure that you have also copied and uncommented the following line (in the public section of
the definition of the class):
DATA: n_tsx_seldr TYPE rsdd_tsx_seldr.
Now navigate to the method ‘set_selection’ and make sure the content looks like:
n_tsx_seldr = i_tsx_seldr.
December 2016
7
How to...Create a Characteristic Relationship type SQL-script
This moves the selection received by the system into an internally available table.
Now navigate to the method ‘get_sqlscript_parameters’. Here you prepare the selection
information and move it into the parameter.
We receive the selection information in the internal table n_tsx_seldr. This table is unfortunately
somewhat clumsy. Luckily in the sample implementation of the class for characteristic relationships
CL_RSPLS_CR_EXIT_BASE there is a method that transfers the structure into a more useful one
(method ‘SELDR_TO_RANGE’, see example in chapter 4).
You could fill in the information from the system into the parameter pretty much as it is and then try to
adapt the information in SQL-script. But it is much easier to prepare the information already in ABAP
in a format that SQL-script can use more easily. Remember that we want to use the selection
information in order to make sure that the result of the characteristic relationships is filtered by these
restrictions. There is a very handy command in SQL-script that applies a where clause to a table using
a string as the content of the where clause. Thus it makes sense to transmit the result of the selection
into a string that can be used directly in a where clause. The content of the parameter should look like:
(“/BIC/ZD_MAT” = ‘000100’ or “/BIC/ZD_MAT” = ‘000101’)
and “/BIC/ZD_MTLGRP” = ‘ABC’
Again see chapter 4 for our sample implementation.
Remark: In the derive method and also in the check method the system will only provide records that
lie within the selection of the planning filter. Thus the selection of the filter is only relevant for the
create method and the system will call the method ‘set_selection’ only when a derivation is
called. Thus in the other cases you should not rely on the information in n_tx_seldr as it might be
outdated. You might wonder why we transmit the parameters not only in the SQL-script create-method
but also in the other cases. But keep in mind that using the selection from the filter is just one example
for a parameter. You might need the ABAP system date in your derivation to derive time dependent
information or you might need the ABAP system user in order to perform some user dependent
checks.
3.7 Implement the Business Logic in the AMDPs
Now it is finally time to implement the SQL-script logic itself. We have to be aware of some important
differences to ABAP exit relationships.
First make sure that the system receives the correct names of the AMDP methods in method
‘get_sqlscript_info’:
e_procedure_name_create = 'ZCL_DEMO_CR=>AMDP_CREATE'.
e_procedure_name_check = 'ZCL_DEMO_CR=>AMDP_CHECK'.
e_procedure_name_derive = 'ZCL_DEMO_CR=>AMDP_DERIVE'.
Now go ahead, locate the different AMDP methods in your class and implement the SQL-script coding
directly in there. There is no need to program the methods natively in HANA.
Please keep in mind that when you return a combination no field value for a characteristic value is
allowed to be ‘NULL’ (this is the special marker the data base uses for a data value that does not exist
on the data base). ABAP does not know this concept and all values have to contain the correct but
potentially initial value – matching the definition of the characteristic. For most characteristics (all
characteristics of type character string) the correct initial value is ‘ ‘ (“blank”). For characteristics that
are based on integers (especially the time characteristics) the initial value consists of a correct number
of ‘0’, for example:
December 2016
8
How to...Create a Characteristic Relationship type SQL-script
Characteristic
Type
Initial Value
0FISCPER3
NUMC, length 3
000
0CALYEAR
NUMC, length 4
0000
0FISCPER
NUMC, length 7
0000000
0COSTCENTER
CHAR, length 10
3.7.1
(blank, not NULL)
Check Method
In ABAP exit the check method just receives one combination and has to return the information
whether the record is ok or not. In SQL-script we do not want to have such single calls as this would
be harmful for the performance but the check method receives a list of all records that are to be
checked and has to return a list of all allowed records.
So the simplest implementation would be to just return all received records – that means all records
are regarded as valid:
e_t_chas = select * from :i_t_chas;
In our example we have a different approach – we build up a (hard coded) list of all allowed records.
Please note that the returning table e_t_chas has to be filled by a select statement. As you cannot
insert records into the table e_t_chas with some ‘insert’ statement we use a trick by selecting from
the system defined table ‘dummy’:
e_t_chas = select
'COPA101002' as "/BIC/ZD_MAT" ,
'000000100' as "/BIC/ZD_MTLGRP" from dummy
union select
'COPA102302' as "/BIC/ZD_MAT" ,
'000000100' as "/BIC/ZD_MTLGRP" from dummy
[…];
3.7.2
Create Method
This method is quite similar to the method in the ABAP exit. You have to return a list of all possible
combinations. There is currently one difference between the ABAP and the HANA implementation: in
ABAP you are not allowed to return combinations that lie outside the selection. In SQL-script exits this
is possible but does not really make sense. Thus you should rather use the filter in your create method
in order to restrict the combinations to the selection. Have a look at our example in chapter 4 how you
can use the parameter that we have filled in order to filter the result by the selection.
Remark: As also noted in our documentation you should make sure that the different methods of the
characteristic relationships return consistent results: every records that is regarded as valid in the
check method should also be created by the create methods and derived accordingly in the derive
method. If this is not the case (‘asymmetric relationships’) the system cannot guarantee that
relationships coded in ABAP will always lead to the same results as relationships coded in SQL-script.
We have to admit that our example is quite simple and not optimal in such respect as it first creates
combinations and later deletes the ones not in the selection. In a real scenario you would probably
have many more records and thus would use the filter in order to make sure that unnecessary
combinations are not created in the first place.
Here is the way how we can easily filter a table by the selection we have filled into the parameter:
December 2016
9
How to...Create a Characteristic Relationship type SQL-script
e_t_chas = apply_filter(:l_t_chas, :i_where);
3.7.3
Derive Method
Here we again have a different behavior from the ABAP exits. Whereas the ABAP exit is called for
each single combination and you have to fill in the missing characteristics in SQL-script exits you have
to return a list comprising all incoming combinations but with filled target characteristics. Our sample
coding is again very similar our check-method.
3.8 Test your Characteristic Relationship
Finally you can go ahead and test your characteristic relationship. In most cases it is simpler to test
your characteristic relationships using the test environment provided by a planning sequence. You can
create a formula or a planning function type generate combination in order to test the different
methods. It also makes sense to insert some steps of type ‘manual input’ so you can check the
created records. The reason why planning functions are more apt for first test is that is easier to see
(and control) whether the ABAP or SQL-script implementation is used. Remember a query uses ABAP
in certain situations and SQL-script in others (see above). If you have created a planning function that
can run in-memory (see note 1637199) you can simply execute it in your test sequence in order to
execute the SQL-script implementation (transaction rsplan).
Now if you want to test the ABAP methods you can just execute your planning function step in trace
mode as this mode is always executed in ABAP.
At the bottom of the screen you can see some system messages – either that the planning functions
was executed successfully or if not the information that some records did not comply with the
characteristic relationships.
December 2016
10
How to...Create a Characteristic Relationship type SQL-script
Hopefully your characteristic relationships work the way you expect. But how can you search for errors
in your code?
In ABAP this is simple – just set a break-point in the method you want to debug (session break-point if
you run your tests from transaction rsplan, external break-point if you test for example in a query in
an Analysis for Office workbook). But what about the AMPDs?
When you are on SAP NetWeaver 7.50 or higher then luckily debugging AMDPs is nearly as simple as
debugging normal ABAP methods (see also How to debug ABAP Managed Database Procedures
using ADT – Basics). But you have to use the eclipse based ABAP modelling tools.
Start the ABAP modelling tool and log on to your ABAP system. Navigate to your class and to the
method you want to debug.
Now click on the bar to the left of the coding and call the context menu. Choose ‘Toggle Breakpoint’.
This will automatically activate the AMDP debugger and an (external) break-point.
December 2016
11
How to...Create a Characteristic Relationship type SQL-script
You can go back to transaction ‘rsplan’ or say to an Analysis for Office workbook and perform your
test. The system will automatically stop in the AMDP debugger. Here you can have a look at all the
parameters and tables in the AMDP and can go through the method step by step.
If you are using an older version of SAP NetWeaver debugging in SQL-script is also possible but more
complicated. When an AMDP is executed for the first time a SQL-script procedure is created in HANA.
You can use standard debugging in HANA studio to check how your SQL-script methods work (see
Tutorial: How to Debug an ABAP Managed Database Procedure).
December 2016
12
How to...Create a Characteristic Relationship type SQL-script
4.
Coding Example
CLASS zcl_demo_cr DEFINITION
PUBLIC
CREATE PROTECTED .
*"* public components of class CL_RSPLS_CR_EXIT_BASE
*"* do not include other source files here!!!
PUBLIC SECTION.
TYPE-POOLS abap .
TYPE-POOLS rsd .
INTERFACE if_rspls_cr_types LOAD .
INTERFACES
INTERFACES
INTERFACES
INTERFACES
INTERFACES
INTERFACES
if_rspls_char_relation .
if_rspls_cr_methods .
if_rspls_cr_types .
if_rspls_cr_exit .
if_amdp_marker_hdb .
if_rspls_cr_exit_hdb .
ALIASES n_is_derive
FOR if_rspls_char_relation~n_is_derive .
ALIASES n_ts_chas
FOR if_rspls_char_relation~n_ts_chas .
TYPES:
BEGIN OF tn_s_chas,
/bic/zd_mat
TYPE /bic/oizd_mat,
/bic/zd_mtlgrp TYPE /bic/oizd_mtlgrp,
END OF tn_s_chas.
TYPES:
tn_t_chas TYPE STANDARD TABLE OF tn_s_chas
WITH DEFAULT KEY.
DATA n_basic_prov TYPE rsinfoprov READ-ONLY .
DATA n_step TYPE rspls_step READ-ONLY .
DATA n_dateto TYPE rspls_cr_dateto READ-ONLY .
METHODS amdp_check
IMPORTING
VALUE(i_t_chas) TYPE tn_t_chas
VALUE(i_where) TYPE string
EXPORTING
VALUE(e_t_chas) TYPE tn_t_chas.
METHODS amdp_create
IMPORTING
December 2016
13
How to...Create a Characteristic Relationship type SQL-script
VALUE(i_where) TYPE string
EXPORTING
VALUE(e_t_chas) TYPE tn_t_chas.
METHODS amdp_derive
IMPORTING
VALUE(i_t_chas) TYPE tn_t_chas
VALUE(i_where) TYPE string
EXPORTING
VALUE(e_t_chas) TYPE tn_t_chas.
METHODS constructor
IMPORTING
!i_basic_prov TYPE rsinfoprov
!i_step
TYPE if_rspls_cr_types=>tn_step
!i_is_derive
TYPE rs_bool
!i_ts_cha_role TYPE if_rspls_cr_types=>tn_ts_cha_role
!i_dateto
TYPE rspls_cr_dateto
RAISING
cx_rspls_failed .
PROTECTED SECTION.
*"* protected components of class CL_RSPLS_CR_EXIT_BASE
*"* do not include other source files here!!!
TYPES to_r_is_valid TYPE REF TO char1 .
INTERFACE if_rspls_cr_types LOAD .
TYPES to_r_mesg TYPE REF TO if_rspls_cr_types=>tn_s_mesg .
DATA o_r_strucdescr TYPE REF TO cl_abap_structdescr .
DATA n_tsx_seldr TYPE rsdd_tsx_seldr.
CLASS-METHODS get_instance_o
IMPORTING
!i_basic_prov
TYPE rsinfoprov
!i_step
TYPE if_rspls_cr_types=>tn_step
!i_is_derive
TYPE rs_bool
!i_ts_cha_role
TYPE if_rspls_cr_types=>tn_ts_cha_role
!i_dateto
TYPE rspls_cr_dateto
!i_clsname
TYPE seoclsname OPTIONAL
RETURNING
VALUE(r_r_instance) TYPE REF TO if_rspls_char_relation
RAISING
cx_rspls_failed .
METHODS seldr_to_range
IMPORTING
!i_tsx_seldr TYPE rsdd_tsx_seldr
EXPORTING
December 2016
14
How to...Create a Characteristic Relationship type SQL-script
!e_t_range
TYPE rsdri_t_range .
PRIVATE SECTION.
*"* private components of class CL_RSPLS_CR_EXIT_BASE
*"* do not include other source files here!!!
TYPES:
BEGIN OF tp_sx_instance,
basic_prov TYPE rsinfoprov,
ts_cha_role TYPE if_rspls_char_relation~tn_ts_cha_role,
r_instance TYPE REF TO if_rspls_char_relation,
END OF tp_sx_instance .
TYPES:
tp_tsx_instance TYPE SORTED TABLE OF tp_sx_instance
WITH NON-UNIQUE KEY basic_prov
INITIAL SIZE 0 .
CLASS-DATA p_tsx_instance TYPE tp_tsx_instance .
ENDCLASS.
CLASS ZCL_DEMO_CR IMPLEMENTATION.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DEMO_CR->AMDP_CHECK
* +------------------------------------------------------------------------------------------------+
* | [--->] I_T_CHAS
TYPE
TN_T_CHAS
* | [--->] I_WHERE
TYPE
STRING
* | [<---] E_T_CHAS
TYPE
TN_T_CHAS
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD amdp_check BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY.
*
using <used table>.
* implement something meaningful
e_t_chas = select
'COPA101002' as "/BIC/ZD_MAT" ,
'000000100' as "/BIC/ZD_MTLGRP"
from dummy
union select
'COPA102302' as "/BIC/ZD_MAT" ,
'000000100' as "/BIC/ZD_MTLGRP"
from dummy
union select
'COPA500101' as "/BIC/ZD_MAT" ,
'000000101' as "/BIC/ZD_MTLGRP"
December 2016
15
How to...Create a Characteristic Relationship type SQL-script
from dummy
union select
'COPA500100' as "/BIC/ZD_MAT" ,
'000000101' as "/BIC/ZD_MTLGRP"
from dummy
union select
'COPA500122' as "/BIC/ZD_MAT" ,
'000000102' as "/BIC/ZD_MTLGRP"
from dummy
union select
'COPA500120' as "/BIC/ZD_MAT" ,
'000000102' as "/BIC/ZD_MTLGRP"
from dummy;
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DEMO_CR->AMDP_CREATE
* +------------------------------------------------------------------------------------------------+
* | [--->] I_WHERE
TYPE
STRING
* | [<---] E_T_CHAS
TYPE
TN_T_CHAS
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD amdp_create BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY.
*
using <used table>.
* implement something meaningful
*e_t_chas = APPLY_FILTER( :i_t_chas, :i_where );
l_t_chas =
select
'COPA101002' as "/BIC/ZD_MAT" ,
'000000100' as "/BIC/ZD_MTLGRP"
from dummy
union select
'COPA102302' as "/BIC/ZD_MAT" ,
'000000100' as "/BIC/ZD_MTLGRP"
from dummy
union select
'COPA500101' as "/BIC/ZD_MAT" ,
'000000101' as "/BIC/ZD_MTLGRP"
from dummy
December 2016
16
How to...Create a Characteristic Relationship type SQL-script
union select
'COPA500100' as "/BIC/ZD_MAT" ,
'000000101' as "/BIC/ZD_MTLGRP"
from dummy
union select
'COPA500122' as "/BIC/ZD_MAT" ,
'000000102' as "/BIC/ZD_MTLGRP"
from dummy
union select
'COPA500120' as "/BIC/ZD_MAT" ,
'000000102' as "/BIC/ZD_MTLGRP"
from dummy;
e_t_chas = apply_filter(:l_t_chas, :i_where);
*e_t_chas = select * from :l_t_chas;
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DEMO_CR->AMDP_DERIVE
* +------------------------------------------------------------------------------------------------+
* | [--->] I_T_CHAS
TYPE
TN_T_CHAS
* | [--->] I_WHERE
TYPE
STRING
* | [<---] E_T_CHAS
TYPE
TN_T_CHAS
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD amdp_derive BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY.
*
using <used table>.
* implement something meaningful
e_t_chas = select
'COPA101002' as "/BIC/ZD_MAT" ,
'000000100' as "/BIC/ZD_MTLGRP"
from dummy
union select
'COPA102302' as "/BIC/ZD_MAT" ,
'000000100' as "/BIC/ZD_MTLGRP"
from dummy
union select
'COPA500101' as "/BIC/ZD_MAT" ,
'000000101' as "/BIC/ZD_MTLGRP"
from dummy
December 2016
17
How to...Create a Characteristic Relationship type SQL-script
union select
'COPA500100' as "/BIC/ZD_MAT" ,
'000000101' as "/BIC/ZD_MTLGRP"
from dummy
union select
'COPA500122' as "/BIC/ZD_MAT" ,
'000000102' as "/BIC/ZD_MTLGRP"
from dummy
union select
'COPA500120' as "/BIC/ZD_MAT" ,
'000000102' as "/BIC/ZD_MTLGRP"
from dummy;
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DEMO_CR->CONSTRUCTOR
* +------------------------------------------------------------------------------------------------+
* | [--->] I_BASIC_PROV
TYPE
RSINFOPROV
* | [-->] I_STEP
TYPE
IF_RSPLS_CR_TYPES=>TN_STEP
* | [--->] I_IS_DERIVE
TYPE
RS_BOOL
* | [-->] I_TS_CHA_ROLE
TYPE
IF_RSPLS_CR_TYPES=>TN_TS_CHA_
ROLE
* | [--->] I_DATETO
TYPE
RSPLS_CR_DATETO
* | [!CX!] CX_RSPLS_FAILED
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD constructor.
*---------------------------------------------------------------------*
* --> i_basic_prov
basis infoprovider
* --> i_step
step of characteristic relation
* --> i_is_derive
flag, derive or only check combination
* --> i_ts_cha_role
characteristics and their role
* --> i_dateto
date: valid to ( or char. relationsships)
*---------------------------------------------------------------------*
DATA:
l_s_cha_role
l_s_chas
l_r_cha_prop
l_t_comp
l_s_comp
December 2016
TYPE
TYPE
TYPE
TYPE
TYPE
if_rspls_char_relation=>tn_s_cha_role,
if_rspls_char_relation=>tn_s_chas,
REF TO if_rsd_cha_prop,
cl_abap_structdescr=>component_table,
cl_abap_structdescr=>component,
18
How to...Create a Characteristic Relationship type SQL-script
l_ts_chanm
l_r_struc
l_idx
l_ts_chanm_s
TYPE
TYPE
TYPE
TYPE
rsd_ts_chanm,
REF TO cl_abap_structdescr,
i,
rsd_ts_chanm.
FIELD-SYMBOLS:
<l_s_buf> TYPE any,
<l_char>
TYPE char1,
<l_s_mesg> TYPE if_rspls_cr_types=>tn_s_mesg.
if_rspls_char_relation~n_basic_prov = i_basic_prov.
n_basic_prov
n_step
n_is_derive
n_dateto
=
=
=
=
i_basic_prov.
i_step.
i_is_derive.
i_dateto.
* fill internal view of characteristics for characteristic relationship
* and create a data structure containing these characteristics
LOOP AT i_ts_cha_role INTO l_s_cha_role.
l_s_chas-iobjnm = l_s_cha_role-iobjnm.
l_s_chas-role
= l_s_cha_role-role.
*
we want characteristic values in internal format
*
--> leave field 'is_sid' of l_s_chas empty
l_r_cha_prop = cl_rsd_iobj_prop_cache=>get_cha( l_s_chas-iobjnm ).
*
l_r_cha_prop contains the meta data for the actual infoobject:
*
ATTENTION: method GET_FIELD_NAME contains the fieldname of BW
*
generated data structures, e.g. for reference characteristics
*
the names used in master data tables may be different !
l_s_chas-fieldnm = l_r_cha_prop->get_field_name( ).
INSERT l_s_chas INTO TABLE if_rspls_char_relation~n_ts_chas.
*
create the data structure at run time using the data element:
l_s_comp-name = l_s_chas-fieldnm.
l_s_comp-type = l_r_cha_prop->get_datadescr( ).
APPEND l_s_comp TO l_t_comp.
*
fill key of buffer table:
INSERT l_s_chas-fieldnm INTO TABLE l_ts_chanm.
IF l_s_chas-role = 'S'.
INSERT l_s_chas-fieldnm INTO TABLE l_ts_chanm_s.
ENDIF.
ENDLOOP.
* now a type description of the data records can be created:
o_r_strucdescr = cl_abap_structdescr=>get( p_components = l_t_comp
p_strict
= abap_false ).
*use external buffering
IF_RSPLS_CHAR_RELATION~N_USE_EXTERNAL_BUFFER = ABAP_TRUE.
ENDMETHOD.
December 2016
19
How to...Create a Characteristic Relationship type SQL-script
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Static Protected Method ZCL_DEMO_CR=>GET_INSTANCE_O
* +------------------------------------------------------------------------------------------------+
* | [--->] I_BASIC_PROV
TYPE
RSINFOPROV
* | [-->] I_STEP
TYPE
IF_RSPLS_CR_TYPES=>TN_STEP
* | [--->] I_IS_DERIVE
TYPE
RS_BOOL
* | [-->] I_TS_CHA_ROLE
TYPE
IF_RSPLS_CR_TYPES=>TN_TS_CHA_
ROLE
* | [--->] I_DATETO
TYPE
RSPLS_CR_DATETO
* | [--->] I_CLSNAME
TYPE
SEOCLSNAME(optional)
* | [<()] R_R_INSTANCE
TYPE REF TO IF_RSPLS_CHAR_RELATION
* | [!CX!] CX_RSPLS_FAILED
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_instance_o.
*---------------------------------------------------------------------*
* --> i_basic_prov
basis infoprovider
* --> i_step
step of characteristic relation
* --> i_is_derive
flag, derive or only check combination
* --> i_ts_cha_role
characteristics and their role
* --> i_dateto
date: valid to ( or char. relationsships)
* --> i_clsname
class name, used for subclasses
* <-- r_r_instance
existing or new instance
*---------------------------------------------------------------------*
DATA: l_exists
l_sx_instance
l_clsname
l_r_ex
TYPE
TYPE
TYPE
TYPE
abap_bool,
tp_sx_instance,
seoclsname,
REF TO cx_rspls_failed.
FIELD-SYMBOLS: <l_sx_instance> TYPE tp_sx_instance.
* the instance table is sorted by basic_prov
* scan the relevant records by ts_cha_role
l_exists = abap_false.
LOOP AT p_tsx_instance ASSIGNING <l_sx_instance>
WHERE basic_prov = i_basic_prov.
IF <l_sx_instance>-ts_cha_role = i_ts_cha_role.
l_exists = abap_true.
r_r_instance = <l_sx_instance>-r_instance.
EXIT.
ENDIF.
ENDLOOP.
IF l_exists = abap_false.
l_sx_instance-basic_prov = i_basic_prov.
l_sx_instance-ts_cha_role = i_ts_cha_role.
December 2016
20
How to...Create a Characteristic Relationship type SQL-script
TRY.
IF i_clsname IS INITIAL.
l_clsname = 'CL_RSPLS_CR_EXIT_BASE'.
ELSE.
l_clsname = i_clsname.
ENDIF.
CREATE OBJECT l_sx_instance-r_instance TYPE (l_clsname)
EXPORTING
i_basic_prov
= l_sx_instance-basic_prov
i_step
= i_step
i_is_derive
= i_is_derive
i_ts_cha_role
= l_sx_instance-ts_cha_role
i_dateto
= i_dateto.
CATCH cx_rspls_failed INTO l_r_ex.
RAISE EXCEPTION l_r_ex.
ENDTRY.
INSERT l_sx_instance INTO TABLE p_tsx_instance.
r_r_instance = l_sx_instance-r_instance.
ENDIF.
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DEMO_CR>IF_RSPLS_CHAR_RELATION~CREATE_DATA_REF
* +------------------------------------------------------------------------------------------------+
* | [<-()] R_R_CHAS
TYPE REF TO DATA
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_rspls_char_relation~create_data_ref.
*---------------------------------------------------------------------*
* <-- r_r_chas structure with infoobjects and fieldnames
*
as defined in table n_ts_chas
*---------------------------------------------------------------------*
CREATE DATA r_r_chas TYPE HANDLE o_r_strucdescr.
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DEMO_CR-
December 2016
21
How to...Create a Characteristic Relationship type SQL-script
>IF_RSPLS_CHAR_RELATION~SET_SELECTION
* +------------------------------------------------------------------------------------------------+
* | [--->] I_TSX_SELDR
TYPE
RSDD_TSX_SELDR
* | [--->] I_PREFETCH
TYPE
RS_BOOL(optional)
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_rspls_char_relation~set_selection.
* I_TSX_SELDR contains information about the selection in the current
* context of a planning query or a planning function; this method can
* be helpful to prefetch data needed in the relation
* I_PREFETCH contains a hint that a prefetch of resources might
* improve performance, e.g. to a avoid a record based DB access
n_tsx_seldr = i_tsx_seldr.
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DEMO_CR>IF_RSPLS_CR_EXIT_HDB~GET_SQLSCRIPT_INFO
* +------------------------------------------------------------------------------------------------+
* | [<---] E_DB_SCHEMA_NAME
TYPE
STRING
* | [<---] E_PROCEDURE_NAME_CHECK
TYPE
STRING
* | [<---] E_PROCEDURE_NAME_DERIVE
TYPE
STRING
* | [<---] E_PROCEDURE_NAME_CREATE
TYPE
STRING
* | [<---] E_PARAMETER_NAME
TYPE
TYPENAME
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_rspls_cr_exit_hdb~get_sqlscript_info.
e_procedure_name_create = 'ZCL_DEMO_CR=>AMDP_CREATE'.
e_procedure_name_check = 'ZCL_DEMO_CR=>AMDP_CHECK'.
e_procedure_name_derive = 'ZCL_DEMO_CR=>AMDP_DERIVE'.
* here you can return a name of a DDIC structure in which you can pass par
ameters to the SQL-script
e_parameter_name = 'CRDEMOSTRUC'.
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DEMO_CR>IF_RSPLS_CR_EXIT_HDB~GET_SQLSCRIPT_PARAMETERS
* +------------------------------------------------------------------------------------------------+
* | [<---] E_S_PARAMETER
TYPE
ANY
* +------------------------------------------------------------------------
December 2016
22
How to...Create a Characteristic Relationship type SQL-script
--------------</SIGNATURE>
METHOD if_rspls_cr_exit_hdb~get_sqlscript_parameters.
*
e.g. use n_tsx_seldr to calculate a wherecondition to be used in the apply_filter HANA Function
*
DATA: l_where_1 TYPE string,
*
l_s_<DDIC Type> TYPE <DDIC Type>, " with component i_where_1
*
l_where_1 = `"<field_name_1>" = '<value_1> AND "<field_name_2>" = '<va
lue_2>'`.
*
l_s_<DDIC Type>-i_where_1 = l_where_1.
*
MOVE-CORRESPONDING l_s_<DDIC Type> TO e_s_parameter.
DATA: l_s_crdemostruc TYPE crdemostruc.
DATA: l_t_range TYPE rsdri_t_range,
l_s_range LIKE LINE OF l_t_range,
l_mark
TYPE c.
CALL METHOD me->seldr_to_range
EXPORTING
i_tsx_seldr = n_tsx_seldr
IMPORTING
e_t_range
= l_t_range.
* first insert the selection for material; we assume we just use single val
ues
LOOP AT l_t_range INTO l_s_range WHERE chanm = 'ZD_MAT'.
CHECK l_s_range-sign = 'I' AND l_s_range-compop = 'EQ'.
IF l_s_crdemostruc-i_where IS INITIAL.
l_s_crdemostruc-i_where = ' ( '.
ELSE.
CONCATENATE l_s_crdemostruc-i_where ' OR ' INTO l_s_crdemostruci_where.
ENDIF.
CONCATENATE l_s_crdemostruc-i_where ` "/BIC/ZD_MAT" = '`
l_s_range-low `'`
INTO l_s_crdemostruc-i_where.
ENDLOOP.
IF l_s_crdemostruc-i_where IS NOT INITIAL.
CONCATENATE l_s_crdemostruc-i_where ' ) ' INTO l_s_crdemostruci_where.
ENDIF.
LOOP AT l_t_range INTO l_s_range WHERE chanm = 'ZD_MTLGRP'.
CHECK l_s_range-sign = 'I' AND l_s_range-compop = 'EQ'.
IF l_s_crdemostruc-i_where IS INITIAL.
l_s_crdemostruc-i_where = ' ( '.
ELSE.
IF l_mark IS INITIAL.
l_mark = 'X'.
December 2016
23
How to...Create a Characteristic Relationship type SQL-script
CONCATENATE l_s_crdemostruci_where ' AND ( ' INTO l_s_crdemostruc-i_where.
ELSE.
CONCATENATE l_s_crdemostruc-i_where ' OR ' INTO l_s_crdemostruci_where.
ENDIF.
ENDIF.
CONCATENATE l_s_crdemostruc-i_where ` "/BIC/ZD_MTLGRP" = '`
l_s_range-low `'`
INTO l_s_crdemostruc-i_where.
ENDLOOP.
IF l_s_crdemostruc-i_where IS INITIAL.
l_s_crdemostruc-i_where = '?'.
ELSE.
CONCATENATE l_s_crdemostruc-i_where ' ) ' INTO l_s_crdemostruci_where.
ENDIF.
MOVE-CORRESPONDING l_s_crdemostruc TO e_s_parameter.
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Static Public Method ZCL_DEMO_CR=>IF_RSPLS_CR_EXIT~GET_INSTANCE
* +------------------------------------------------------------------------------------------------+
* | [--->] I_BASIC_PROV
TYPE
RSINFOPROV
* | [-->] I_STEP
TYPE
IF_RSPLS_CR_TYPES=>TN_STEP
* | [--->] I_IS_DERIVE
TYPE
RS_BOOL
* | [-->] I_TS_CHA_ROLE
TYPE
IF_RSPLS_CR_TYPES=>TN_TS_CHA_
ROLE
* | [--->] I_DATETO
TYPE
RSPLS_CR_DATETO
* | [--->] I_CLSNAME
TYPE
SEOCLSNAME(optional)
* | [<()] R_R_INSTANCE
TYPE REF TO IF_RSPLS_CHAR_RELATION
* | [!CX!] CX_RSPLS_FAILED
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_rspls_cr_exit~get_instance.
*---------------------------------------------------------------------*
* --> i_basic_prov
basis infoprovider
* --> i_step
step of characteristic relation
* --> i_is_derive
flag, derive or only check combination
* --> i_ts_cha_role
characteristics and their role
* --> i_dateto
date: valid to ( or char. relationsships)
* --> i_clsname
class name, used for subclasses
December 2016
24
How to...Create a Characteristic Relationship type SQL-script
* <-- r_r_instance
existing or new instance
*---------------------------------------------------------------------*
DATA: l_r_ex TYPE REF TO cx_rspls_failed.
TRY.
CALL METHOD get_instance_o
EXPORTING
i_basic_prov = i_basic_prov
i_step
= i_step
i_is_derive
= i_is_derive
i_ts_cha_role = i_ts_cha_role
i_dateto
= i_dateto
i_clsname
= i_clsname
RECEIVING
r_r_instance = r_r_instance.
CATCH cx_rspls_failed INTO l_r_ex.
RAISE EXCEPTION l_r_ex.
ENDTRY.
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DEMO_CR->IF_RSPLS_CR_METHODS~CHECK
* +------------------------------------------------------------------------------------------------+
* | [--->] I_S_CHAS
TYPE
ANY
* | [<--] E_T_MESG
TYPE
IF_RSPLS_CR_TYPES=>TN_T_MESG
* | [<---] E_IS_VALID
TYPE
RS_BOOL
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_rspls_cr_methods~check.
*---------------------------------------------------------------------*
* --> i_s_chas
characteristics combination
* <-- e_t_mesg
messages
* <-- e_is_valid flag, record is valid or not
*---------------------------------------------------------------------*
CLEAR e_t_mesg.
FIELD-SYMBOLS: <mat>
TYPE any,
<matgrp> TYPE any.
ASSIGN COMPONENT '/BIC/ZD_MAT' OF STRUCTURE i_s_chas TO <mat>.
ASSIGN COMPONENT '/BIC/ZD_MTLGRP' OF STRUCTURE i_s_chas TO <matgrp>.
December 2016
25
How to...Create a Characteristic Relationship type SQL-script
IF <mat>
<mat>
<mat>
<mat>
<mat>
<mat>
= 'COPA101002' AND <matgrp> = '000000100' OR
= 'COPA102302' AND <matgrp> = '000000100' OR
= 'COPA500101' AND <matgrp> = '000000101' OR
= 'COPA500100' AND <matgrp> = '000000101' OR
= 'COPA500122' AND <matgrp> = '000000102' OR
= 'COPA500120' AND <matgrp> = '000000102'.
e_is_valid = rs_c_true.
ELSE.
e_is_valid = rs_c_false.
ENDIF.
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DEMO_CR->IF_RSPLS_CR_METHODS~CHECK_HDB
* +------------------------------------------------------------------------------------------------+
* | [<---] E_T_LOOKUP_ATTRIBUTE
TYPE
TREXT_LOOKUPATTRIBUTE
* | [<--] E_T_MESG
TYPE
IF_RSPLS_CR_TYPES=>TN_T_MESG
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_rspls_cr_methods~check_hdb.
RAISE EXCEPTION TYPE cx_rsr_x_message
EXPORTING
text = 'IF_RSPLS_CR_METHODS~CHECK_HDB-01-'.
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DEMO_CR->IF_RSPLS_CR_METHODS~CREATE
* +------------------------------------------------------------------------------------------------+
* | [--->] I_TSX_SELDR
TYPE
RSDD_TSX_SELDR
* | [-->] I_TS_CHANM
TYPE
RSD_TS_CHANM(optional)
* | [<--] E_T_MESG
TYPE
IF_RSPLS_CR_TYPES=>TN_T_MESG
* | [<---] E_TH_CHAS
TYPE
HASHED TABLE
* | [!CX!] CX_RSPLS_FAILED
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_rspls_cr_methods~create.
*---------------------------------------------------------------------*
* --> i_tsx_seldr
selection criteria
December 2016
26
How to...Create a Characteristic Relationship type SQL-script
* <-- e_t_mesg
messages
* <-- e_th_chas
valid combinations
* <<- cx_rspls_failed exception
*---------------------------------------------------------------------*
CLEAR e_t_mesg.
CLEAR e_th_chas.
DATA: l_r_struct TYPE REF TO
FIELD-SYMBOLS: <s_line> TYPE
<mat>
TYPE
<matgrp> TYPE
data.
any,
any,
any.
CREATE DATA l_r_struct LIKE LINE OF e_th_chas.
ASSIGN l_r_struct->* TO <s_line>.
ASSIGN COMPONENT '/BIC/ZD_MAT' OF STRUCTURE <s_line> TO <mat>.
ASSIGN COMPONENT '/BIC/ZD_MTLGRP' OF STRUCTURE <s_line> TO <matgrp>.
<mat> = 'COPA101002'.
<matgrp> = '000000100'.
INSERT <s_line> INTO TABLE e_th_chas.
<mat> = 'COPA102302'.
<matgrp> = '000000100'.
INSERT <s_line> INTO TABLE e_th_chas.
<mat> = 'COPA500101'.
<matgrp> = '000000101'.
INSERT <s_line> INTO TABLE e_th_chas.
<mat> = 'COPA500100'.
<matgrp> = '000000101'.
INSERT <s_line> INTO TABLE e_th_chas.
<mat> = 'COPA500122'.
<matgrp> = '000000102'.
INSERT <s_line> INTO TABLE e_th_chas.
<mat> = 'COPA500120'.
<matgrp> = '000000102'.
INSERT <s_line> INTO TABLE e_th_chas.
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DEMO_CR->IF_RSPLS_CR_METHODS~CREATE_HDB
December 2016
27
How to...Create a Characteristic Relationship type SQL-script
* +------------------------------------------------------------------------------------------------+
* | [--->] I_TSX_SELDR
TYPE
RSDD_TSX_SELDR
* | [-->] I_TS_CHANM
TYPE
RSD_TS_CHANM(optional)
* | [<--] E_T_MESG
TYPE
IF_RSPLS_CR_TYPES=>TN_T_MESG
* | [<---] E_TH_CHAS
TYPE
HASHED TABLE
* | [<---] E_INDEX_ID
TYPE
TREXD_INDEX_ID
* | [<---] E_VIEW_ID
TYPE
TREXD_PLAN_VIEW
* | [<---] E_T_NAME_MAP
TYPE
TREXT_PE_NAME_MAP_SET
* | [<---] E_T_QUERY_ENTRY
TYPE
TREXT_QUERY_ENTRIES
* | [!CX!] CX_RSPLS_FAILED
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_rspls_cr_methods~create_hdb.
RAISE EXCEPTION TYPE cx_rsr_x_message
EXPORTING
text = 'IF_RSPLS_CR_METHODS~CREATE_HDB-01-'.
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DEMO_CR->IF_RSPLS_CR_METHODS~DERIVE
* +------------------------------------------------------------------------------------------------+
* | [<--] E_T_MESG
TYPE
IF_RSPLS_CR_TYPES=>TN_T_MESG
* | [<-->] C_S_CHAS
TYPE
ANY
* | [!CX!] CX_RSPLS_FAILED
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_rspls_cr_methods~derive.
*---------------------------------------------------------------------*
* <-- e_t_mesg
messages
* <-> c_s_chas
characteristic combination: source and target
*
fields included; do not change the source
*
fields
* <<- cx_rspls_failed exception
*---------------------------------------------------------------------*
CLEAR e_t_mesg.
FIELD-SYMBOLS: <mat>
TYPE any,
<matgrp> TYPE any.
ASSIGN COMPONENT '/BIC/ZD_MAT' OF STRUCTURE c_s_chas TO <mat>.
ASSIGN COMPONENT '/BIC/ZD_MTLGRP' OF STRUCTURE c_s_chas TO <matgrp>.
CASE <mat>.
December 2016
28
How to...Create a Characteristic Relationship type SQL-script
WHEN 'COPA101002'.
<matgrp> = '000000100'.
WHEN 'COPA102302'.
<matgrp> = '000000100'.
WHEN 'COPA500101'.
<matgrp> = '000000101'.
WHEN 'COPA500100'.
<matgrp> = '000000101'.
WHEN 'COPA500122'.
<matgrp> = '000000102'.
WHEN 'COPA500120'.
<matgrp> = '000000102'.
ENDCASE.
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DEMO_CR->IF_RSPLS_CR_METHODS~DERIVE_HDB
* +------------------------------------------------------------------------------------------------+
* | [<---] E_T_LOOKUP_ATTRIBUTE
TYPE
TREXT_LOOKUPATTRIBUTE
* | [<--] E_T_MESG
TYPE
IF_RSPLS_CR_TYPES=>TN_T_MESG
* | [!CX!] CX_RSPLS_FAILED
* +-------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_rspls_cr_methods~derive_hdb.
RAISE EXCEPTION TYPE cx_rsr_x_message
EXPORTING
text = 'IF_RSPLS_CR_METHODS~DERIVE_HDB-01-'.
ENDMETHOD.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Instance Protected Method ZCL_DEMO_CR->SELDR_TO_RANGE
* +------------------------------------------------------------------------------------------------+
* | [--->] I_TSX_SELDR
TYPE
RSDD_TSX_SELDR
* | [<---] E_T_RANGE
TYPE
RSDRI_T_RANGE
* +-------------------------------------------------------------------------------------</SIGNATURE>
December 2016
29
How to...Create a Characteristic Relationship type SQL-script
METHOD seldr_to_range.
*---------------------------------------------------------------------*
* --> i_tsx_seldr
selection table (contains here only cart. product
*
selection with CHAVLs but in complex OLAP format)
* <-- e_t_range
selection table in simple range table format
*---------------------------------------------------------------------*
DATA: l_s_range TYPE rsdri_s_range,
l_s_rng
TYPE rrrangesid.
FIELD-SYMBOLS: <l_sx_seldr> TYPE rsdd_sx_seldr.
CLEAR e_t_range.
LOOP AT i_tsx_seldr ASSIGNING <l_sx_seldr>.
l_s_range-chanm = <l_sx_seldr>-chanm.
LOOP AT <l_sx_seldr>-range-range INTO l_s_rng.
l_s_range-sign
= l_s_rng-sign.
l_s_range-compop = l_s_rng-opt.
l_s_range-low
= l_s_rng-low.
l_s_range-high
= l_s_rng-high.
APPEND l_s_range TO e_t_range.
ENDLOOP.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
December 2016
30