Skip to Content

Calculated field in abap cds where clause


I am using calculated field in where clause. But it is giving error.

define view view1 as select from Table1 {



when Table1.field2 = '1' then Table1.field3

when Table1.field2 = '2' then Table1.field4

end as keyField

}where keyField > $session.system_date

Above code gives error 'Column keyField is not known'. I changed the where clause to as follows:

where $projection.keyField > $session.system_date

Now it gives error 'Table name $projection unknown or shadowed by an alias'.

Due to this problem, I have to create one more view on top of this view and then I can use keyField in where clause of new view. But just for this reason, creating a new view does not seems to be a good solution.



Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Aug 24, 2016 at 08:14 AM

    Hello Vinayak.

    Your WHERE clause must filter on a field from the table or view your are requesting from. KeyField is a field from your current view (view1). So if you need to filter on the field keyfield, another view on top of view1 is totally justified.

    Now, if you need to perform the filter before, your WHERE clause has to work with Table1.field3 AND Table1.field4.



    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.