4 Cookbook Index Table Adoption 20151020
4 Cookbook Index Table Adoption 20151020
4 Cookbook Index Table Adoption 20151020
Document Version
Status
Date
1.0
final
10/2015
Table of Content
1
General Approach
1.1.1
Motivation
1.1.2
1.2
Compatibility Mode
1.2.1
Standard Deployment
1.2.2
1.2.2.1
1.2.2.2
1.2.2.2.1
1.2.2.2.2
Extension View
1.2.2.3
1.2.2.3.1
1.2.2.3.2
1.2.2.3.3
Extension View
2015 SAP SE
13
10/2015
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
10/2015
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.
2015 SAP SE
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
10/2015
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
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
10/2015
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
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:
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 ,
as kunde,
The following chapters describe how the compatibility views for partner index tables are set up.
1.2.2.3.2
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
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
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
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
vbak.vbeln
=
=
=
vbak.vbeln
'AG'
'000000'
as mandt,
as kunde,
10
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
10/2015
vbak.vbeln
=
=
=
vbak.vbeln
'AG'
'000000'
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
10/2015
else vbak.bnddt
end
else
end
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
10/2015
After activating the extension, an append view is automatically generated for view Z_V_VAKPA_KU_CDS:
2015 SAP SE
14
10/2015
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
10/2015
For the top-level view, the extending attribute LAND1 is explicitly added to the view.
2015 SAP SE
16
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
10/2015
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