Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
anjan_paul
Active Contributor
2,037

Steps:

1. Create Data Base table for PO Header.

@EndUserText.label : 'PO Header'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zpo_header {

  key client : abap.clnt not null;
  key pono   : ebeln not null;
  pocompany  : bukrs;
  podate     : abap.dats;
  podesc     : abap.char(20);
  postatus   : abap.char(1);

}

2. Create PO Item Database table.

@EndUserText.label : 'PO Item'
@AbapCatalog.enhancement.category : #EXTENSIBLE_ANY
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zpo_item {

  key client : abap.clnt not null;
  @AbapCatalog.foreignKey.screenCheck : false
  key pono   : ebeln not null
    with foreign key [1..*,1] zpo_header
      where client = zpo_item.client
        and pono = zpo_item.pono;
  key poitem : ebelp not null;
  @Semantics.quantity.unitOfMeasure : 'zpo_item.unit'
  quantity   : abap.quan(10,0);
  unit       : abap.unit(3);

}

3. Create Base CDS Header view.

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Base view for po'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{ 
serviceQuality: #X, 
sizeCategory: #S, 
dataClass: #MIXED 
} 

define root view entity z_po_header_base as select from zpo_header
{
    key pono as Pono,
    pocompany as Pocompany,
    podate as Podate,
    podesc as Podesc,
    postatus as Postatus
    
}

4. Create Base CDS item view.

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Base view for po item'
@Metadata.ignorePropagatedAnnotations: true
define root view entity z_po_item_base as select from zpo_item

{
    key pono as Pono,
    key poitem as Poitem,
    @Semantics.quantity.unitOfMeasure : 'Unit'
    quantity as Quantity,
    unit as Unit
}

5. Create Composite Header CDS view.

@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Composit view for po'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
    serviceQuality: #X,
    sizeCategory: #S,
    dataClass: #MIXED
}
define root  view entity z_po_header_composit as select from z_po_header_base
 composition [1..*] of z_po_item_composit as _item
   
{
    key Pono,
    Pocompany,
    Podate,
    Podesc,
    Postatus,
    _item
}

6. Create Composite Item CDS view.

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Composit view for po item'
@Metadata.ignorePropagatedAnnotations: true
define view entity z_po_item_composit as select from z_po_item_base
association to parent z_po_header_composit as _header
    on $projection.Pono = _header.Pono
{
    key Pono,
    key Poitem,
     @Semantics.quantity.unitOfMeasure : 'Unit'
   Quantity,
    Unit,
    _header 
}

 

7. Create Consumption CDS Header view.

@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Consumption view for po'
@Metadata.ignorePropagatedAnnotations: true
@Metadata.allowExtensions: true
@ObjectModel.usageType:{
    serviceQuality: #X,
    sizeCategory: #S,
    dataClass: #MIXED
}
define root view entity z_po_header_consumption  
provider contract transactional_query
as projection on z_po_header_composit
{
    key Pono,
    Pocompany,
    Podate,
    Podesc,
    Postatus,
    /* Associations */
    _item : redirected to composition child z_po_item_consumption 
}

8. Create Consumption Item CDS view.

@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Consumption view for po item'
@Metadata.ignorePropagatedAnnotations: true
@Metadata.allowExtensions: true
@ObjectModel.usageType:{
    serviceQuality: #X,
    sizeCategory: #S,
    dataClass: #MIXED
}
define view entity z_po_item_consumption 
as projection on z_po_item_composit

{
    key Pono,
    key Poitem,
 
   @Semantics.quantity.unitOfMeasure : 'Unit'
    Quantity,
    Unit,
    /* Associations */
    _header : redirected to parent z_po_header_consumption
}

9. Create Metadata Extension for Header.

@Metadata.layer: #CUSTOMER 
annotate entity z_po_header_consumption
    with 
{
    @ui.facet: [{ 
purpose: #STANDARD, 
position: 10, 
label: 'Header', 
type: #IDENTIFICATION_REFERENCE 
}, 
{ 
purpose: #STANDARD, 
position: 20, 
label: 'Item', 
type: #LINEITEM_REFERENCE, 
targetElement: '_item' 
}] 
@UI.selectionField: [{ position: 10 }]
@UI.lineItem: [{ position: 10, label: 'PO No' }] 
@UI.identification: [{ position: 10, label: 'Po NO' }] 
Pono; 
@UI.selectionField: [{ position: 20 }]
@UI.lineItem: [{ position: 20, label: 'Company' }] 
@UI.identification: [{ position: 20, label: 'Company' }] 
Pocompany; 
@UI.selectionField: [{ position: 30 }]
@UI.lineItem: [{ position: 30, label: 'PO Date' }] 
@UI.identification: [{ position: 30, label: 'PO Date' }] 
Podate; 
@UI.lineItem: [{ position: 40, label: 'Desc' }] 
@UI.identification: [{ position: 40, label: 'Desc' }] 
Podesc; 
@UI.lineItem: [{ position: 50, label: 'Status' }] 
@UI.identification: [{ position: 50, label: 'Status' }] 
Postatus; 
    
}

10.  Create Metadata extension for Item .

@Metadata.layer: #CUSTOMER
annotate entity z_po_item_consumption
    with 
{
    @ui.facet: [{ 
purpose: #STANDARD, 
position: 10, 
label: 'Item', 
type: #IDENTIFICATION_REFERENCE 
}] 
@UI.lineItem: [{ position: 10, label: 'Po no' }] 
@UI.identification: [{ position: 10, label: 'Po no' }] 
Pono; 
@UI.lineItem: [{ position: 20, label: 'Item' }] 
@UI.identification: [{ position: 20, label: 'Item' }] 
Poitem; 
@UI.lineItem: [{ position: 30, label: 'Quantity' }] 
@UI.identification: [{ position: 30, label: 'Quantity' }] 
Quantity; 
@UI.lineItem: [{ position:40, label: 'Unit' }] 
@UI.identification: [{ position: 40, label: 'Unit' }] 
Unit; 
    
}

11. Create Behavior Definition of Composite view.

managed implementation in class zbp_po_header_composit unique;
strict ( 2 );

define behavior for z_po_header_composit //alias <alias_name>
persistent table zpo_header
lock master
authorization master ( instance )
//etag master <field_name>
{
  create;
  update;
  delete;
  association _item { create; }
}

define behavior for z_po_item_composit //alias <alias_name>
persistent table zpo_item
lock dependent by _header
authorization dependent by _header
//etag master <field_name>
{
  update;
  delete;
  field ( readonly ) Pono;
  association _header;
}

12. Create Projection Behavior Definition.

projection;
strict ( 2 );

define behavior for z_po_header_consumption //alias <alias_name>
{
  use create;
  use update;
  use delete;

  use association _item { create; }
}

define behavior for z_po_item_consumption //alias <alias_name>
{
  use update;
  use delete;

  use association _header;
}

13. Create Service Definition.

@EndUserText.label: 'Service Definition fo PO Header'
define service Z_SV_PO_HEADER {
  expose z_po_header_consumption;
  expose z_po_item_consumption;
}

14. Create Service Binding.

anjan_paul_1-1750548575837.png

 

15. Now Application can be run from Preview. Header and Item can be created .

anjan_paul_2-1750548645413.png

anjan_paul_3-1750548679744.png

16. Records created in Header and Item table.

anjan_paul_4-1750548764141.png

 

anjan_paul_5-1750548793518.png

 

 

 

 

1 Comment