0% found this document useful (0 votes)
158 views5 pages

Complete Demo Code CDS Views

The document describes 6 CDS views that were created for a purchase order demo. The views include basic and composite views for purchase order headers and items that associate with basic views for suppliers, materials, and each other. Key fields, associations, and semantics are defined for each view.

Uploaded by

Arie 402
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
158 views5 pages

Complete Demo Code CDS Views

The document describes 6 CDS views that were created for a purchase order demo. The views include basic and composite views for purchase order headers and items that associate with basic views for suppliers, materials, and each other. Key fields, associations, and semantics are defined for each view.

Uploaded by

Arie 402
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Complete Demo code

Below we have the complete code used for the demo until now.

CDS views:
1. ZI_PurOrderHdr – Basic View
2. ZI_PurOrderItem – Basic View
3. ZI_pocust1 – Basic View
4. ZI_material1 – Basic View
5. ZI_PurOrderHdrEnhanced – Header Composite view
6. ZI_PurOrderItemEnh – Item Composite View

ZI_PurOrderHdr – Basic view


@AbapCatalog.sqlViewName: 'ZIPURHDR1'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Purchase Order Header'
@VDM.viewType: #BASIC
@OData.publish: true
@ClientHandling.type: #INHERITED
@ClientHandling.algorithm: #AUTOMATED
define view ZI_PurOrderHdr
as select from ekko
association [0..*] to ZI_PurOrderItem as _POItem on
$projection.PurchaseOrder = _POItem.PurchaseOrder
association [1..1] to zi_pocust1 as _POSupp on
$projection.Supplier = _POSupp.Supplier
{
key ebeln as PurchaseOrder,
bsart as PurOrderType,
ekorg as PurOrganization,
ekgrp as PurGroup,
lifnr as Supplier,
_POSupp.SupplierName as SupplierName,
waers as DocCurrency,
aedat as CreationDate,
rlwrt as TotalValue,
@ObjectModel.association.type: [#TO_COMPOSITION_CHILD]
_POItem,
_POSupp

}
where
ernam = $session.user
ZI_PurOrderItem – Basic View

@AbapCatalog.sqlViewName: 'ZIPURORDITEM'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Purchase Order Item'
define view ZI_PurOrderItem
as select from ekpo
association [1..1] to ZI_PurOrderHdr as _POHdr on
$projection.PurchaseOrder = _POHdr.PurchaseOrder
association [1..1] to ZI_material1 as _Material on
$projection.Material = _Material.Material
{
key ebeln as PurchaseOrder,
key ebelp as
PurchaseOrderItem,
matnr as Material,
_Material.MaterialType as MaterialTYpe,
txz01 as POItemText,
matkl as MaterialGroup,
werks as Plant,
lgort as
StorageLocation,
concat_with_space(werks, lgort, 1) as StorageDetails,
@Semantics.quantity.unitOfMeasure: 'OrderUnit'
menge as OrderQuantity,
@Semantics.unitOfMeasure: true
meins as OrderUnit,
netpr as NetPrice,
cast( netpr as abap.fltp(16) ) * 0.35 as TaxAmount,
netwr as NetOrderValue,
cast(netwr as abap.fltp(16)) * 0.75 as
DiscountedNetOrder,
ceil(cast(netwr as abap.fltp(16)) * 0.75) as
DiscountedRoundedNetOrd,
@ObjectModel.association.type: [#TO_COMPOSITION_PARENT,
#TO_COMPOSITION_ROOT]
_POHdr,
_Material
}
ZI_pocust1 – Basic View
@AbapCatalog.sqlViewName: 'ZIPOCUST12'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Supplier'
define view zi_pocust1
as select from lfa1
{
key lifnr as Supplier,
land1 as Region,
name1 as SupplierName
}

ZI_material1 – Basic View


@AbapCatalog.sqlViewName: 'ZIMAT1'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Material'
define view ZI_material1
as select from mara
{
key matnr as Material,
mtart as MaterialType,
meins as BaseUnit
}

ZI_PurOrderHdrEnhanced – Header Composite view


@AbapCatalog.sqlViewName: 'ZIPURHDRE'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Purchase Order hdr Composite'
@VDM.viewType: #COMPOSITE
define view ZI_PurOrderHdrEnhanced as select from ZI_PurOrderHdr
association [0..*] to ZI_PurOrderItemEnh as _POItem on
$projection.PurchaseOrder = _POItem.PurchaseOrder
{
key PurchaseOrder,
case (PurOrderType)
when 'RQ' then 'External Quotation'
when 'UB' then 'Stock transport order'
else 'Other order'
end as PurOrderTypeDesc,
PurOrganization,
PurGroup,
Supplier,
SupplierName,
DocCurrency,
CreationDate,
TotalValue,
currency_conversion( amount => TotalValue,
source_currency => DocCurrency,
target_currency => cast ('USD' as
waers),
exchange_rate_date => CreationDate
) as TotalUSDValue,
/* Associations */
_POItem
//_POSupp
}

ZI_PurOrderItemEnh – Item Composite View


@AbapCatalog.sqlViewName: 'ZIPURORDITME'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Composite View Purord item'
@VDM.viewType: #COMPOSITE
define view ZI_PurOrderItemEnh as select from ZI_PurOrderItem
association [1..1] to ZI_PurOrderHdrEnhanced as _POHdr on
$projection.PurchaseOrder = _POHdr.PurchaseOrder
{
key PurchaseOrder,
key PurchaseOrderItem,
Material,
MaterialTYpe,
POItemText,
MaterialGroup,
Plant,
StorageLocation,
StorageDetails,
@Semantics.quantity.unitOfMeasure: 'OrderUnit'
OrderQuantity,
@Semantics.unitOfMeasure: true
OrderUnit,
NetPrice,
TaxAmount,
NetOrderValue,
DiscountedNetOrder,
DiscountedRoundedNetOrd,
/* Associations */
//_Material,
@ObjectModel.association.type: [#TO_COMPOSITION_PARENT,
#TO_COMPOSITION_ROOT]
_POHdr
}

You might also like