- In this post show will work with Etag in RAP.
- ETag with Manage Application
- Step 1: If you don't have timestamp field in your custom table then kinldy created timestamp field
- Step 2: Add created timestamp field into your Interface view with annotation
- Interface view Code:
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Root View for Sales order Head'
@Metadata.ignorePropagatedAnnotations: true
define root view entity ZR_SALESORDER_HEAD_M
as select from zms_sales_head as Head
composition [0..*] of ZI_SALESORDER_ITEM_M as _Item
{
key vbeln as SalesOrder,
audat as DocumentDate,
auart as OrderType,
vkorg as SalesOrganization,
vtweg as DistributionChannel,
spart as Division,
erdat as Erdat,
erzet as Erzet,
@Semantics.user.localInstanceLastChangedBy: true
ernam as Ernam,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
lastchanged as LastChangedAt,
_Item
}
- Step 3: Add timestamp field into the Projection view
- Projection view code:
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'ProjectionView for Sales order Header'
@Metadata.ignorePropagatedAnnotations: true
@Metadata.allowExtensions: true
define root view entity ZC_SALESORDER_HEAD_M
provider contract transactional_query
as projection on ZR_SALESORDER_HEAD_M
{
key SalesOrder,
DocumentDate,
OrderType,
SalesOrganization,
DistributionChannel,
Division,
Erdat,
Erzet,
Ernam,
LastChangedAt,
_Item : redirected to composition child ZC_SALESORDER_ITEM_M
}
- Step 4: Add etag to your Interface behavior definition, when we define etage for the perticular field then alway make that field in read only.
- Interface behavior definition code
managed implementation in class zbp_r_salesorder_head_m unique;
strict ( 2 );
define behavior for ZR_SALESORDER_HEAD_M alias Header
persistent table zms_sales_head
lock master
authorization master ( instance )
etag master LastChangedAt
{
create ( authorization : global );
update;
delete;
field ( readonly ) SalesOrder, Ernam, LastChangedAt;
association _Item { create; }
mapping for zms_sales_head //db table name
{
//CDS View field //DB Table field name
SalesOrder = vbeln;
DocumentDate = audat;
OrderType = auart;
SalesOrganization = vkorg;
DistributionChannel = vtweg;
Division = spart;
Erdat = erdat;
Erzet = erzet;
Ernam = ernam;
LastChangedAt = lastchanged;
}
}
define behavior for ZI_SALESORDER_ITEM_M alias Item
persistent table zms_sales_item
lock dependent by _Head
authorization dependent by _Head
etag dependent by _Head
{
update;
delete;
field ( readonly ) SalesOrder, Item;
association _Head;
mapping for zms_sales_item //db table name
{
//CDS View field //DB Table field name
SalesOrder = vbeln;
Item = posnr;
Material = matnr;
MaterialDescription = arktx;
Quantity = kwmeng;
Unit = vrkme;
Netpr = netpr;
Currency = waerk;
}
}
- Step5: Add etage in Projection behavior
- Projection Behavior definition code
projection;
strict ( 2 );
define behavior for ZC_SALESORDER_HEAD_M alias Header
use etag
{
use create;
use update;
use delete;
use association _Item { create; }
}
define behavior for ZC_SALESORDER_ITEM_M alias Item
use etag
{
use update;
use delete;
use association _Head;
}
- ETag with Unmanage Application => Comming soon