cancel
Showing results for 
Search instead for 
Did you mean: 

How to select data from a Dynamic table in CDS view ABAP

former_member462348
Participant
0 Kudos
1,382

Hi Expats

have a requirement to perform a select on a dynamic table in CDS view.

Table has name like /01/MDG/SID(SID is the systemID in suffix) so that table name gets changed in QA and PROD based on the system ID.

So in this case, how I can perform a select data from this table using CDS view ? My Final table name will be /01/MDG/DEV, where DEV represent the Development system ID.

when this object is moved to QA, it has a table name like /01/MDG/QAS.

The requirement is to achieve this using CDS view.

Thanks
Rufus Samuel

Sandra_Rossi
Active Contributor
0 Kudos

That's weird to have different names. Do you have any idea why it's like that?

Not very practical, one solution would be to create one table + one view in DDIC with same names on 3 different environments, and reconnect the view at database level (not at DDIC level) to the right table.

Of course, that would be much better that you keep the same table name.

AbdelrahmanZaki
Participant
0 Kudos

Dear Rufus,

This could be handled using AMDP with table function; for more information please refer to this blog.

Regards,
Abdelrahman Zaki

Accepted Solutions (0)

Answers (1)

Answers (1)

SvenS
Participant
0 Kudos

Normally in ABAP you were able to use SY-SYSID, however if I remember correctly this is not possible anymore in CDS views, only session variables left are client, user, language and date. If I remember correctly we can use a lookup of table TADIR based on the Object = 'SYST' and PGMID = 'HEAD' to get the system of our current environment fetching the SRCSYSTEM column.

With another customer the environment names didn't align with the system names, so we had to hard code an if else to set the name (not the prettiest solution, but it did the job).