09-18-2020 1:45 PM
Hi,
I have a CDS View defined as part of an API within ABAP. Now an API consumer wants to include the fields of the CDS View into a structure.
Unfortunately it isn't possible to include the CDS View itself but only the resulting database view. This results in an ATC warning and might be problematic if SAP changes the way CDS Views are realized in ABAP.
Has somebody else faced this problem? And what was the solution?
I see two possible solutions:
1. The consumer has to define a new CDS View which refers to the API CDS view and add the needed fields there. This won't solve the issue, because also a table type for that structure was created.
2. Don't include the fields, but copy them into the structure. This results in reduced maintainability because you then have to add new fields to both structures.
(Of course there is a third way: stop using CDS Views. Try to use normal DB Views instead)
09-30-2020 8:30 AM
Hi David,
You cannot update the structure as this is a separate object.
In this case, better option is to create a type in ABAP and refer there the CDS Entity, so that it automatically stays in sync with the entity changes.
Thanks and regards,
Harish B
09-18-2020 1:52 PM
Hi David,
API based CDS views are not supposed to be used for any other purpose as they may undergo many changes.
You may go for option 2 or 3. Regarding option 1, I am not able to visualize the issue that you may face regarding type? I am assuming you are defining your own CDS view - What do you mean by refer to - Extend view or select from - not advisable anyway for both ways?
Gaurav
09-18-2020 2:00 PM
Thank you for your quick reply.
"API" might have been a bit misleading.
I have defined the CDS View as part of an API for a component I have implemented. Not a standard SAP API.
With "referring" I meant either "select from" or "extend" I did not think further on how to realize this approach since I am also not very convinced of this approach 🙂
09-18-2020 2:59 PM
"Include the fields into a structure" - you mean DDIC structure? purpose of this structure?
09-25-2020 2:10 PM
Hi David,
You can create a structure which is exactly same as cds view and use it instead of database view for fields in strcture or
you can then write either create a new structure or create a new type in ABAP and use the DDLS Name there.
In this way, you use only CDS view.
Regards,
Harish B
09-25-2020 2:17 PM
Hi Harish,
so you suggest creating a structure which is excactly like the CDS View and use it instead of the generated view?
So then I'd always have to bear in mind to also update the structure, when I add a field to the CDS view.
Do I get your suggestion right?
Regards, David
09-30-2020 8:30 AM
Hi David,
You cannot update the structure as this is a separate object.
In this case, better option is to create a type in ABAP and refer there the CDS Entity, so that it automatically stays in sync with the entity changes.
Thanks and regards,
Harish B
09-30-2020 10:21 AM
Ahh now I get it. You mean
TYPES BEGIN OF ty_my_type.
INCLUDE TYPE my_cds_entity.
TYPES END OF ty_my_type.
DATA my_data TYPE ty_my_type.
Yes that works 🙂 Thank you