Skip to Content

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Dec 01, 2017 at 07:56 AM

    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
    
    
    Add comment
    10|10000 characters needed characters exceeded

  • Oct 26, 2017 at 06:38 AM

    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

    Add comment
    10|10000 characters needed characters exceeded