Application Development 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: 

Calculated field - CDS

f_allocca
Participant
0 Kudos

Hi Experts,

I'm using the CDS in hana studio, I need to have in final report a custom field ZFIELD like this:

IF budat => sy-datum AND budat =< (sy-datum + 30). ZFIELD = '+30D'

ELSEIF budat < sy-datum AND budat => (sy-datum - 30). ZFIELD = '-30D'

How can I have?

Thanks

1 ACCEPTED SOLUTION

fedaros
Employee
Employee
0 Kudos

Hi Francesco,

HANA CDS native ? Long time no see... In general documentation with syntax point to same behavior

https://help.sap.com/docs/SAP_HANA_PLATFORM/b3d0daf2a98e49ada00bf31b7ca7a42e/de9843e69bd14989b8a592c...

I didn't tested in CDS but I guess you can figure out with SQL sample below. Ignore the dummy party to create fake data and focus on zfield:

select *,
      case when budat >= current_date and budat <= (add_days(current_date,+30)) then '+30D'
           when budat <  current_date and budat >= (add_days(current_date,-30)) then '-30D'
           else ''
      end                                     as zfield
from 
(select current_date from dummy),
(select '20230305' as budat from dummy union
select '20230310' as budat from dummy union
select '20230311' as budat from dummy union
select '20230312' as budat from dummy union
select '20230315' as budat from dummy);

Result:

Regards, Fernando Da Rós

2 REPLIES 2

0 Kudos

fedaros
Employee
Employee
0 Kudos

Hi Francesco,

HANA CDS native ? Long time no see... In general documentation with syntax point to same behavior

https://help.sap.com/docs/SAP_HANA_PLATFORM/b3d0daf2a98e49ada00bf31b7ca7a42e/de9843e69bd14989b8a592c...

I didn't tested in CDS but I guess you can figure out with SQL sample below. Ignore the dummy party to create fake data and focus on zfield:

select *,
      case when budat >= current_date and budat <= (add_days(current_date,+30)) then '+30D'
           when budat <  current_date and budat >= (add_days(current_date,-30)) then '-30D'
           else ''
      end                                     as zfield
from 
(select current_date from dummy),
(select '20230305' as budat from dummy union
select '20230310' as budat from dummy union
select '20230311' as budat from dummy union
select '20230312' as budat from dummy union
select '20230315' as budat from dummy);

Result:

Regards, Fernando Da Rós