Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

4 Cookbook Index Table Adoption 20151020

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Data Model Changes Regarding SD Index Tables

Document Version

Status

Date

1.0

final

October 20, 2015

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

Table of Content
1

Data Model Changes


1.1

General Approach

1.1.1

Motivation

1.1.2

Related Dictionary Object

1.2

Compatibility Mode

1.2.1

Standard Deployment

1.2.2

How to Handle Enhancements

1.2.2.1

Defining Extension Views

1.2.2.2

Example: How toxtend VAPMA

1.2.2.2.1

CDS View Definition

1.2.2.2.2

Extension View

1.2.2.3

Example: How to Extend VAKPA

1.2.2.3.1

Specifics for partner views

1.2.2.3.2

CDS View definition

1.2.2.3.3

Extension View

2015 SAP SE

13

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

1 Data Model Changes


1.1 General Approach
1.1.1 Motivation
There are a number of database tables which, as a standard deployment, contain only redundant data that
originates from the corresponding document tables. These tables were originally introduced to accelerate
lookup processes for documents that are based on attributes distributed across various document tables (for
example, order header, order line item, and order partner assignment).
In S4/HANA, the database enables you to search for documents that refer to attributes from multiple tables
while efficiently handling distributed selectiveness. Therefore, the decision was made to remove these
redundant tables from the persistency layer, and replace it with views populated by the very same information.

1.1.2 Related Dictionary Object


Table
VAKPA
VAPMA
VLKPA
VLPMA
VRKPA
VRPMA

Short Description
Sales Index: Orders by Partner Function
Sales Index: Order Items by Material
SD Index: Deliveries by Partner Functions
SD Index: Delivery Items by Material
Sales Index: Bills by Partner Functions
SD Index: Billing Items per Material

S4/HANA provides a set of corresponding views. The following table shows which view (and DDL source)
corresponds to which table. The views listed are CDS views, which can be accessed directly in ABAP.
Table

CDS view

DDL source

VAKPA

V_VAKPA_CDS

V_VAKPA

VAPMA

V_VAPMA_CDS

V_VAPMA

VLKPA

V_VLKPA_CDS

V_VLKPA

VLPMA

V_VLPMA_CDS

V_VLPMA

VRKPA

V_VRKPA_CDS

V_VRKPA

VRPMA

V_VRPMA_CDS

V_VRPMA

The original tables will remain in the system and can, for example, be used for typing but will not be populated
with data. Inserts or any other modifying operations are no longer permitted in these tables.

2015 SAP SE

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

1.2 Compatibility Mode


1.2.1 Standard Deployment
In SD, we explicitly decided to replace all access processes to the original index tables with access processes
to the new views. These six tables support compatibility mode.. Each original index table is equipped with a
proxy object linking the CDS view to the index table.
Example for VAKPA:

In cases where the original index table is not enhanced, all select statements will automatically function just as
as before, meaning there is no need for any adoption.
However, since the persistency layer becomes obsolete, manipulating statements that access these tables are
not permitted.

1.2.2 How to Handle Enhancements


1.2.2.1 Defining Extension Views
Extension views can be used to enhance the compatibility views in order to populate with attributes. Before this
optimization, these attributes were stored in the material index or partner index tables.
Since there is no longer a persistency layer, the first step towards moving the enhancement attributes to extend
views is to decide to which of the actual database tables the compatibility views refer to the attributes that are to
be relocated. This relocation requires a custom build migration report that has to read the original index tables
before the compatibility views are introduced. It also has to move the data to the underlying sales document
tables, which now carry all attributes that make up the compatibility views.
The extension view must contain the very same attributes as the extension of the original index-table. Please be
aware that the sequence of the attributes must be the same as it is in the original tables (more precisely: in the
runtime object). If the extension views dont match any of these pre-requisites, they cannot be activated
because the runtime objects for both the actual index table and the compatibility view are not identical.
The following examples show how extension views for the index tables can be defined. There is a specific
example for material index table VAPMA and partner index table VAKPA.

2015 SAP SE

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

These examples are based on a DDIC object in the local namespace Z, but contain the very same information
as the actual tables.
For more information about extension views, see::
http://help.sap.com/abapdocu_740/en/index.htm?file=abencds_f1_extend_view.htm

2015 SAP SE

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

1.2.2.2 Example: How toxtend VAPMA


1.2.2.2.1

CDS View Definition

The following data definition represents the compatibility view for VAPMA:
@AbapCatalog.sqlViewName: 'Z_V_VAPMA_CDS'
@ClientDependent: true
@AbapCatalog.compiler.compareFilter: true
@EndUserText.label: 'compatiblity view for VAPMA'
define view Z_V_VAPMA as
select
from vbak as vbak
join vbap as vbap on
vbap.vbeln = vbak.vbeln
left outer join vbpa as vbpa on
vbpa.vbeln = vbap.vbeln
and vbpa.parvw = 'AG'
and vbpa.posnr = '000000'
{
vbak.mandt
vbap.matnr
vbak.vkorg
vbak.trvog
vbak.audat
vbak.vtweg
vbak.spart
vbak.auart
vbpa.kunnr
vbak.vkbur
vbak.vkgrp
vbak.bstnk
vbak.ernam
vbak.vbeln
vbap.posnr
vbap.werks
vbpa.adrnr

as mandt,
as matnr,
as vkorg,
as trvog,
as audat,
as vtweg,
as spart,
as auart,
as kunnr,
as vkbur,
as vkgrp,
as bstnk,
as ernam,
as vbeln,
as posnr,
as werks,
as adrnr,

case vbak.vbtyp
when 'A' then vbak.angdt
when 'B' then vbak.angdt
else vbak.guebg
end as datab,
case vbak.vbtyp
when 'A' then
case vbak.bnddt when '00000000' then '99991231'
else vbak.bnddt
end
when 'B' then
case vbak.bnddt when '00000000' then '99991231'
2015 SAP SE

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

else vbak.bnddt
end
else
case vbak.gueen when '00000000' then '99991231'
else vbak.gueen
end
end as datbi
}
1.2.2.2.2

Extension View

Example:
The original VAPMA table was extended by MATKL (from table VBAP), therefore MATKL must also be added to
the compatibility view as an extension view:

@AbapCatalog.sqlViewAppendName: 'Z_VAPMA_EXT_CDS'
@EndUserText.label: 'extension view to Z_V_VAPMA'
extend view Z_V_VAPMA with Z_V_VAPMA_EXT {
vbap.matkl as matkl
}
After activating the extension, an append view is automatically generated for view Z_V_VAPMA_CDS:

In the runtime object of the view the attribute MATKL is added to the end, similar to the original index table
VAPMA:

2015 SAP SE

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

1.2.2.3 Example: How to Extend VAKPA


1.2.2.3.1

Specifics for partner views

Extending VAPMA is straightforward, since the compatibility view for VAPMA comprises only one data definition
(one CDS view).
This is different for the partner-index compatibility views. VAKPA is used as an example VRKPA, and VLKPA
follow the same approach.
All partner-index views must comprise four different partner roles:

Customer

Supplier

Employee

Contact person

Unloading point

2015 SAP SE

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

For each of these roles (referring to an entry in table TPAR), a separate, distinct view is defined. This view is
specific to the partner role. This is necessary because ,depending on the role, different attributes from the VBPA
table are populated to the attribute KUNDE:

Customer vbpa.kunnr becomes KUNDE

Supplier vbpa.lifnr becomes KUNDE

Employee vbpa.pernr becomes KUNDE

Contact person vbpa.parnr becomes KUNDE

Unloading point vbpa.ablad becomes KUNDE

Each of these originating attributes is highly significant and must be used efficiently to scan VBPA when
searching for the corresponding rows. In order to ensure this, the assignment to the target attribute KUNDE
must be unconditionally, that means using a case expression in the attribute list, as shown the following code
snippet, is not possible:
case tpar.nrart
when 'KU' then cast(vbpa.kunnr as
when 'LI' then cast(vbpa.lifnr as
when 'AP' then cast(vbpa.parnr as
when 'PE' then cast(vbpa.pernr as
else cast(vbpa.ablad as abap.char (
end

abap.char
abap.char
abap.char
abap.numc
10 ))

(
(
(
(

10
10
10
10

))
))
))
))

as kunde ,

Any access to the view containing


where kunde ='<xyz>
would lead to an inefficient scanning of VBPA in terms of generating a sub-result set that contains all values for
KUNDE assigned from the multiple source attributes. This can easily lead to millions and millions of entries.
Based on this internal sub-result set, the actual look-up for the requested value would be processed.
Instead, each role-specific view only contains an unconditional assignment (for partner role customer, for
example):
vbpa.kunnr

as kunde,

The following chapters describe how the compatibility views for partner index tables are set up.
1.2.2.3.2

CDS View definition

The CDS view is a two-layer definition comprising 5 views (each for every partner role) on the lower level and
the actual compatibility view for VAKPA on the top-level.
1.2.2.3.2.1

Top-level view representing VAKPA

The following data definition represents the compatibility view for VAPMA:
@AbapCatalog.sqlViewName: 'V_VAKPA_CDS'
// Attribute KUNDE is populated from different source-attributes based on the value stored
in tpar.nrat, which is derived from parvw.
//
// UNION all for separate selects differentially on tpar.nrart with the specifically
populating attribute KUNDE shows
// better performance than populating KUNDE via the case expression in the attribute list.
//

2015 SAP SE

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

// This is because "transitivity" , which states the source-attributes that are populated
to KUNDE, is not taken into account
// when choosing the optimal access path with a given when condition on kunde, which would
literally lead to retrieving column kunde for all
// rows as an intermediate result set and subsequently filtering on kunde. Especially
single column indices on the source attributes are not used.
//
// Using UNION all instead represents choosing specific and optimal query plans, and also
utilizing single column indices, which outperform the case version
// by a factor of up to 50.
//
// This approach also holds true for:
//
- V_VLKPA_CDS
//
- V_VRKPA_CDS
define view v_vakpa as
select from V_VAKPA_KU
{
*
}
union all
select from V_VAKPA_LI
{
*
}
union all
select from V_VAKPA_AP
{
*
}
union all
select from V_VAKPA_PE
{
*
}
union all
select from V_VAKPA_AB
{
*
}

2015 SAP SE

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

The description of how to extend this type of partner-index compatibility views uses a simplified version of the
original views that only cover the partner roles customer and supplier. The other three roles follow the same
approach.
Example for top-view:
@AbapCatalog.sqlViewName: 'Z_V_VAKPA_CDS'
@ClientDependent: true
@AbapCatalog.compiler.compareFilter: true
@EndUserText.label: 'compatiblity view for VAKPA'
define view Z_V_VAKPA as
select from Z_V_VAKPA_KU
{
*
}
union all
select from Z_V_VAKPA_LI
{
*
}
Please notice that the attribute lists representing the attributes retrieved from the role-specific views are
generically declared using *. This is crucial for allowing this view to be extended.The following chapter provides
more details about this.
1.2.2.3.2.2

Lower-Level Views for Customer and Supplier

The following data definition represents the subview for customers:


@AbapCatalog.sqlViewName: 'Z_V_VAKPA_KU_CDS'
@ClientDependent: true
@AbapCatalog.compiler.compareFilter: true
@EndUserText.label: 'sub-view for customer'
define view Z_V_VAKPA_KU as
select distinct
from vbak as vbak
join vbpa as vbpa on
vbpa.vbeln

vbak.vbeln

join vbpa as vbpa_ag on


vbpa_ag.vbeln
and vbpa_ag.parvw
and vbpa_ag.posnr

=
=
=

vbak.vbeln
'AG'
'000000'

join tpar as tpar on


tpar.parvw = vbpa.parvw
and tpar.nrart = 'KU'
{
vbak.mandt
vbpa.kunnr
2015 SAP SE

as mandt,
as kunde,
10

DATA MODEL CHANGES REGARDING SD INDEX TABLES

vbpa.parvw
vbak.vkorg
vbak.trvog
vbak.audat
vbak.vkbur
vbak.vkgrp
vbak.vtweg
vbak.spart
vbak.auart
vbak.bstnk
vbpa_ag.kunnr
vbak.ernam
vbak.vbeln
vbpa_ag.adrnr
vbpa.adrnr

as
as
as
as
as
as
as
as
as
as
as
as
as
as
as

10/2015

parvw,
vkorg,
trvog,
audat,
vkbur,
vkgrp,
vtweg,
spart,
auart,
bstnk,
kunnr,
ernam,
vbeln,
adrnr_ag,
adrnr,

case vbak.vbtyp
when 'A' then vbak.angdt
when 'B' then vbak.angdt
else vbak.guebg
end as datab ,
case vbak.vbtyp
when 'A' then
case vbak.bnddt when '00000000' then '99991231'
else vbak.bnddt
end
when 'B' then
case vbak.bnddt when '00000000' then '99991231'
else vbak.bnddt
end
else
case vbak.gueen when '00000000' then '99991231'
else vbak.gueen
end
end as datbi
}
Please note that the parts highlighted in yellow make this view specific to the partner role customer

2015 SAP SE

11

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

The following data definition represents the subview for suppliers:


@AbapCatalog.sqlViewName: 'Z_V_VAKPA_LI_CDS'
@ClientDependent: true
@AbapCatalog.compiler.compareFilter: true
@EndUserText.label: 'sub-view for supplier'
define view Z_V_VAKPA_LI as
select distinct
from vbak as vbak
join vbpa as vbpa on
vbpa.vbeln

vbak.vbeln

join vbpa as vbpa_ag on


vbpa_ag.vbeln
and vbpa_ag.parvw
and vbpa_ag.posnr

=
=
=

vbak.vbeln
'AG'
'000000'

join tpar as tpar on


tpar.parvw = vbpa.parvw
and tpar.nrart = 'LI'
{
vbak.mandt
vbpa.lifnr
vbpa.parvw
vbak.vkorg
vbak.trvog
vbak.audat
vbak.vkbur
vbak.vkgrp
vbak.vtweg
vbak.spart
vbak.auart
vbak.bstnk
vbpa_ag.kunnr
vbak.ernam
vbak.vbeln
vbpa_ag.adrnr
vbpa.adrnr

as
as
as
as
as
as
as
as
as
as
as
as
as
as
as
as
as

mandt,
kunde,
parvw,
vkorg,
trvog,
audat,
vkbur,
vkgrp,
vtweg,
spart,
auart,
bstnk,
kunnr,
ernam,
vbeln,
adrnr_ag,
adrnr,

case vbak.vbtyp
when 'A' then vbak.angdt
when 'B' then vbak.angdt
else vbak.guebg
end as datab ,
case vbak.vbtyp
when 'A' then
case vbak.bnddt when '00000000' then '99991231'
else vbak.bnddt
end
when 'B' then
case vbak.bnddt when '00000000' then '99991231'
2015 SAP SE

12

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

else vbak.bnddt
end
else

end

case vbak.gueen when '00000000' then '99991231'


else vbak.gueen
end
as datbi

Please note that the parts highlighted in yellow make this view specific to the partner role supplier
1.2.2.3.3

Extension View

Extension views containing the set operation UNION (ALL) cannot be declared explicitly on the top-level view,
because its not possible to declare which attributes should belong to which UNION branch. Instead, the
extension must be declared on the lower-level views, which will be inherited by the top-level view, because the
attribute list from the lower-level views is generically populated using *.
Attention:
All extensions to the lower-level views must be identical in terms of sequence and type of the extending
attributes!

Example 1:
For all partner roles, the attribute LAND1 of table VBPA should be added to the compatibility view.

In order to achieve this, two extension views must be declared: one for customer and another one for suppliers.
Extension view for customers:
@AbapCatalog.sqlViewAppendName: 'Z_VKP_KU_EXT_CDS'
@EndUserText.label: 'extend view for sub-view customer'
extend view Z_V_VAKPA_KU with Z_V_VAKPA_KU_EXT {
vbpa.land1 as land1
}

2015 SAP SE

13

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

After activating the extension, an append view is automatically generated for view Z_V_VAKPA_KU_CDS:

2015 SAP SE

14

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

Extension view for suppliers:


@AbapCatalog.sqlViewAppendName: 'Z_VKP_LI_EXT_CDS'
@EndUserText.label: 'extend view for sub-view customer'
extend view Z_V_VAKPA_LI with Z_V_VAKPA_LI_EXT {
vbpa.land1 as land1
}
After activating the extension, an append view is automatically generated for view Z_V_VAKPA_LI_CDS

Attention:
You must also manually activate the top-level view to get the append view attributes into Z_V_VAKPA_CDS.

2015 SAP SE

15

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

For the top-level view, the extending attribute LAND1 is explicitly added to the view.

2015 SAP SE

16

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

In the runtime object of the view the attribute LAND1 is also added to the end.

Example 2:
In addition to Example 1, the attribute HITYP (customer hierarchy type) should only be added for the role
customer , while for the partner role supplier, it should remain as the initial one.
In order to achieve this, both lower-level views must be extended by the additional attribute HITYP.
Extension view for customers:
@AbapCatalog.sqlViewAppendName: 'Z_VKP_KU_EXT_CDS'
@EndUserText.label: 'extend view for sub-view customer'
extend view Z_V_VAKPA_KU with Z_V_VAKPA_KU_EXT {
vbpa.land1 as land1,
vbpa.hityp as hityp
}
For the customer view, the additional attribute can be added to LAND1 in a similar fashion:

2015 SAP SE

17

DATA MODEL CHANGES REGARDING SD INDEX TABLES

10/2015

Extension view for suppliers:


@AbapCatalog.sqlViewAppendName: 'Z_VKP_LI_EXT_CDS'
@EndUserText.label: 'extend view for sub-view customer'
extend view Z_V_VAKPA_LI with Z_V_VAKPA_LI_EXT {
vbpa.land1 as land1,
cast ('' as HITYP_KH) as hityp
}

Since for suppliers the attribute HITYP should remain as initial, the initial value must be cast to refer to data
element HITYP_KH as the target attribute HITYP ,to make sure that both attribute lists return an identical
structure.
In the runtime object for the top-level view, the attribute HITYP will be added to the end:

2015 SAP SE

18

You might also like