Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Best practice for using CDS Views in structures

davidhenn
Explorer
0 Likes
8,118

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)

1 ACCEPTED SOLUTION
Read only

harishbokkasam1
Product and Topic Expert
Product and Topic Expert
0 Likes
5,775

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

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

7 REPLIES 7
Read only

GK817
Active Contributor
0 Likes
5,775

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

Read only

0 Likes
5,775

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 🙂

Read only

GK817
Active Contributor
0 Likes
5,775

"Include the fields into a structure" - you mean DDIC structure? purpose of this structure?

Read only

harishbokkasam1
Product and Topic Expert
Product and Topic Expert
0 Likes
5,775

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

Read only

0 Likes
5,775

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

Read only

harishbokkasam1
Product and Topic Expert
Product and Topic Expert
0 Likes
5,776

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

Read only

0 Likes
5,775

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