on 2022 Feb 14 10:36 AM
Dear CAP team,
I would like to come with an additional proposal for this amazing framework.
So we have enums right now:
type Rating : Integer enum {
Best = 5;
Good = 4;
Avg = 3;
Poor = 2;
Worst = 1;
}
which we can use as a type and it's already great.
entity Reviews {
key ID : UUID;
rating : Rating;
}<br>
However what could be really cool if we could use also those values as constants in our model.
Just for example
view BestReviews as select from Reviews where rating = Rating.Best
or even like that
entity as select from SapEvents {
Events.SAP as source,
...
} union all select from NonSapEvents {
Events.NON_SAP as source
}
type Events : Integer enum {
SAP = 1;
NON_SAP = 2;
}
This way we can avoid of hardcoded values in our models in constant fields, where and joins conditions and navigation paths. It will help to refactor code also quickly and will help to search for references in the code faster.
What do you think?
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alex. Thanks for you reply. Well - for sure in JS we have unlimited capabilities.
However this post was about pure CDS modelling part. It's quite simple to declare enums of course. However is not possible to use them in the model as join or filter conditions. That's make usage of enums very limited.
So currently even having enums - we still have to use literals there. I hope CAP team will come with some solution - and here is just the proposal 😃
User | Count |
---|---|
66 | |
11 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.