- In this post will show you how to create Draft functionality in RAP Application.
- Step 1: Open the Interface view behavior definition and add key workd as with Drft , draft table and create draft table, total etag, with draft into create as show in below:
- Interface view Behavior definition code:
managed;
strict ( 2 );
with draft;
define behavior for ZR_SALESORDER_HEAD_M alias Header
implementation in class zbp_r_salesorder_head_m unique
persistent table zms_sales_head
draft table zdt_sales_head
lock master
total etag LastChangedAt
authorization master ( instance )
etag master LastChangedAt
{
create ( authorization : global );
update;
delete;
field ( readonly ) SalesOrder, Ernam, LastChangedAt;
association _Item { create; with draft; }
draft action Activate optimized;
draft determine action Prepare;
draft action Edit;
draft action Resume;
draft action Discard;
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
implementation in class zbp_i_salesorder_item_m unique
persistent table zms_sales_item
draft table zdt_sales_item
lock dependent by _Head
authorization dependent by _Head
etag dependent by _Head
{
update;
delete;
field ( readonly ) SalesOrder, Item;
association _Head {with draft;}
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;
}
}
- Step 2: Creation of draft table: Write the “draft table <Table Name> and place the cursor on
the table name and quick the shortcut as “Clrl+Shift+1, it shows shortcut
popup, click on Create table
- Header Draft table
- Item Draft table
- Step 3: Open the projection view behavior definition and write brloe code
- Projection view Behavior definition code:
projection;
strict ( 2 );
use draft;
define behavior for ZC_SALESORDER_HEAD_M alias Header
use etag
{
use create;
use update;
use delete;
use association _Item { create; with draft; }
use action Edit;
use action Activate;
use action Discard;
use action Prepare;
use action Resume;
}
define behavior for ZC_SALESORDER_ITEM_M alias Item
use etag
{
use update;
use delete;
use association _Head{ with draft; }
}