cancel
Showing results for 
Search instead for 
Did you mean: 

Reuse of Calculated Columns in CDS View

Hi,

I should use a calculated columns for other calcs in my CDS View, for example

Order.GrossValue as GrossValue,

Order.NetValue as NetValue,

GrossValue - NetValue = Gain

Gain / 1000 = Gain1000

Gain is not usable because is not known as column.

Is there any Annotation or can I know which is the best practice to reuse calc columns in the same CDS view.

Thank you

Accepted Solutions (1)

Accepted Solutions (1)

eralper_yilmaz
Participant

It is not possible to refer to a calculated field in an other calculated field unfortunately.

So you have to do the same calculation in the second field as well

For example, following code can be used in a CDS view

select 
  vbeln,
  netwr,
  mwsbk,
  netwr + mwsbk as total,
  ( netwr + mwsbk ) * 1000 as total1000
from vbrk

Answers (1)

Answers (1)

eralper_yilmaz
Participant
0 Kudos

Hello Antonio,

Instead of creating calculated values in CDS views, if possible you can define these values in tables as computed columns

Here is an example

create column table Table1 (
    Multiplicand int,
    Multiplier int,
    Product int as Multiplicand * Multiplier
);
insert into Table1 values (2,5);

select * from Table1;

Here is the result

Does it help?

Or you need it really on CDS views? If so, can you give more detail with a sample code

0 Kudos

Thanks but I need to calc the value in CDS, the only possible way is to create a CDS on top of the first one and calc the value.