on 04-14-2021 12:48 PM
Hi everyone,
I'm currently working on a very simple CAP Service for exam purposes next month and have a question regarding creating a Field which is calculated from values of other fields.
Here’s what I'm working with:
My schema is very simple (needs to be for this exam) --> I'm looking to have the field totalFree in entity "Place" calculated as the sum of all currentlyFree from the entity "Zone".
So if I have four Zone entities and each has the value 10 in "currentlyFree" "totalFree" in Place will be calculated and be 40.
I've done a bit of research and found this Blog Post regarding the issue. I'm just not sure how to do this in my case.
Here is my cat-service.cds file, where I presume the changes would have to be made.
Any help would be appreciated 🙂
Greetings
Jaden
Hi, we do not support calculated elements in entities (yet). Please do your calculations in views.
This is basically a variation of DJs blogpost: Replace 'null' with your expression:
entity E {
key id: Integer; Price: Integer; Quantity: Integer;
};
view V as select from E
{
Price,
Price * Quantity as PriceQuantity: Integer
};
For more complex expressions CASE may be your friend (but I don't want to spoil all the fun with your exam 😉
Regards, Hans-Joachim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Hans-Joachim,
Figured it out works like a charm now.
Thanks for the help!
User | Count |
---|---|
83 | |
11 | |
8 | |
8 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.