· 4 years ago · Aug 31, 2021, 01:20 PM
1// AbapCatalog controls ABAP runtime env and dictionary
2//sqlViewName defines name of generated by dictionary SQL view
3@AbapCatalog.sqlViewName: 'zkhrccipark'
4//
5@AbapCatalog.compiler.compareFilter: true
6// defines behavior of the auth check.
7// runtime engines uses status of this annotation for auth check
8// NOT_REQUIRED means that auth check is execunted only if a DCL role exists for this CDS
9@AccessControl.authorizationCheck: #NOT_REQUIRED
10// just describtion for the vies, could be represented on UI
11@EndUserText.label: 'Park composite view'
12
13// ObjectModel annotations provide definition of structural and transactional aspects of business data model
14@ObjectModel: {
15// annotation defines performance parameters for CDS consuming
16usageType:{
17 // dataClass annotation has indicator role, so that consumers of this CDS can define suitable caching stratagies for the selected data
18 dataClass: #TRANSACTIONAL,
19 // describes which performance characteristics a CDS model has
20 serviceQuality: #A,
21 // every view assigned to a size category, which defines result set or the set of data to be calculated or searched while consuming
22 sizeCategory: #S
23},
24// enables transactional runtime support
25 transactionalProcessingEnabled: true,
26
27// defines the toot of the compositional hierarchy for the darft business object
28// to be crated (root of the BO tree I guess)
29 compositionRoot: true,
30
31 // specifies the database table for stroing active data entries
32 writeActivePersistence: 'zkhr_cc_park',
33
34 // alowing creation of new instances. EXTERNAL_CALCULATION making create property be calculated in a BOPF property determination
35 // it's like we making BOPF responsible for create activity
36 createEnabled: 'EXTERNAL_CALCULATION',
37 // alowing deletion. managing same as create
38 deleteEnabled: 'EXTERNAL_CALCULATION',
39 // alowing updating. managing same as updating
40 updateEnabled: 'EXTERNAL_CALCULATION',
41
42 // with this annotation we can define semantic key for the hole view.
43 // semantic key uses field value as human-readable key for more comfertable consuming
44 semanticKey: ['ParkID'],
45
46 // allows you to make objects drafts in the app
47 // and(!) enables draft mechanizm in all child nodes
48 draftEnabled: true,
49
50 // specifies the name of the datatable for storing draft data
51 // generates automatically after activation of the CDS BO view
52 // like shadow table for intemediate storage
53 writeDraftPersistence: 'zkhr_cc_park_d'
54}
55define view zkhr_cc_i_park
56 as select from zkhr_cc_p_park
57
58 // accociation to the child node of car
59 association [1..*] to zkhr_cc_i_car as _Car on $projection.ParkUUID = _Car.ParkUUID
60
61 // accociation to the child node of dates
62 association [0..*] to zkhr_cc_i_dates as _Dates on $projection.ParkUUID = _Dates.ParkUUID
63
64 // accociation to the child node of carscount, which provides about amount of cars in the park
65 association to zkhr_cc_i_carscount as _CarsCount on $projection.ParkUUID = _CarsCount.ParkUUID
66{
67 key ParkUUID,
68 // makes this element mandatory, if it's true, the field must be filled by the consumer while executing
69 // with EXTERNAL_CALCULATION we can define how the element is defined as mandatory
70 @ObjectModel.mandatory: true
71 ParkID,
72 ParkName,
73 Capacity,
74
75 // if readonly is true, then consumer not able to update the field
76 @ObjectModel.readOnly: true
77 _CarsCount.CarsCount as CarsCount,
78
79 // if readonly is true, then consumer not able to update the field
80 @ObjectModel.readOnly: true
81 case
82 when _CarsCount.CarsCount < Capacity then 'O'
83 else 'C'
84 end as ParkStatus,
85
86 // if readonly is true, then consumer not able to update the field
87 @ObjectModel.readOnly: true
88 case
89 when _CarsCount.CarsCount > 0 and _CarsCount.CarsCount <= div(Capacity, 2) then 3
90 when _CarsCount.CarsCount > div(Capacity, 2) and _CarsCount.CarsCount < Capacity then 2
91 when _CarsCount.CarsCount >= Capacity and _CarsCount.CarsCount <= Capacity then 1
92 else 0
93 end as CapacityCriticality,
94
95 // if readonly is true, then consumer not able to update the field
96 @ObjectModel.readOnly: true
97 'https://leverx.com/images/header/ic_logo.svg' as imageUrl,
98
99 // bounding system field value with this element throught Semantics
100 @Semantics.systemDateTime.createdAt: true
101 crea_date_time,
102
103 // bounding system field user value with this element throught Semantics
104 @Semantics.user.createdBy: true
105 crea_uname,
106
107 // bounding system field last changed value with this element throught Semantics
108 @Semantics.systemDateTime.lastChangedAt: true
109 lchg_date_time,
110
111 // bounding system field last changed by with this element throught Semantics
112 @Semantics.user.lastChangedBy: true
113 lchg_uname,
114
115 // with association annotation we defining association type in a compositional hierarchy
116 // in our case runtime engine for object processing is BOPF, and with enabled transationalprocessing it connects all linked objects with this annotation
117 // when we defining compositional hierarchy and want to connect sub views we must use TO_COMPOSITIONAL_CHILD
118 @ObjectModel.association.type: [#TO_COMPOSITION_CHILD]
119 _Car,
120 _Dates
121}
122