cancel
Showing results for 
Search instead for 
Did you mean: 

Populate row number in CDS View

PallaviU
Participant

Hello All,

I have a requirement to populate row numbers in CDS View. The data for the final CDS view will be populated from four other CDS views. My final view looks something like the one below. Example: The first two rows will come from the first CDS view, the next two rows from the second CDS view, and so on.

Final View

I tried to generate the row number using virtual elements in CDS but was not able to do it as I will not be using OData. publish annotation, and I need to view the result in SE16 only, not from the metadata.

I tried using the CDS table function to populate the row number (row_number in AMDP) but was able to populate the row number as mentioned below.

I need to have the row numbers continuously for the data from all the CDS views. But the row number is starting from the initial for every CDS view.

Please suggest an approach to having continuous row numbers for all the records.

Thanks in Advance

Pallavi U

Sandra_Rossi
Active Contributor
0 Kudos

Can't you create another CDS view to UNION all sets of data, and your main CDS view will be based on that UNION CDS view and use ROW_NUMBER?

PallaviU
Participant
0 Kudos

Hello Sandra,

As suggested I will create a UNION CDS View but how can I add ROW_NUMBER to a CDS View? Till now I adding ROW_NUMBER in CDS Table function only.

Thanks

Pallavi

Sandra_Rossi
Active Contributor
0 Kudos

Sorry, I meant:

  • "and your AMDP will query that UNION CDS view and use ROW_NUMBER."
PallaviU
Participant
0 Kudos

Hello Sandra,

Can I use a CDS View inside AMDP ? Also, I need to have an output in the CDS View. So, If am able to use CDS View inside AMDP to generate row number then again I need to use AMDP inside a CDS View to have a final output.

Thanks

Pallavi

Sandra_Rossi
Active Contributor
0 Kudos

I think that you have already everything to solve by yourself:

CDS view:

DEFINE VIEW ENTITY ... SELECT ... UNION SELECT ...

CDS table function:

define table function ... implemented by method ...;

AMDP method:

RETURN
    SELECT
    ...,
    ROW_NUMBER() over (partition by ...) AS ...,
    ...
    FROM <CDS view>

ABAP code:

SELECT ... FROM <CDS table function> ...
View Entire Topic
Sandra_Rossi
Active Contributor
0 Kudos

You can do:

CDS view:

DEFINE VIEW ENTITY ... SELECT ... UNION SELECT ...

CDS table function:

define table function ... implemented by method ...;

AMDP method:

RETURN
    SELECT
    ...,
    ROW_NUMBER() over (partition by ...) AS ...,
    ...
    FROM <CDS view>

ABAP code:

SELECT ... FROM <CDS table function> ...