on 09-16-2020 8:26 AM
You are using ABAP CDS Views?
If yes, you can use a CDS Table function (as suggested in the answer before). Instead of the RANK function you can use the Window Aggregate Function MAX too to determine the max value to be able to compare it against the price.
Another simple approach without using a CDS Table function is to define an additional CDS view which provides the maximum value for the category (with a simple max on the price grouped by the category). The in your view which should provide your result you can join that additional view. With a case you can compare the Price with the joined maxium Price and set the value of your "Max ?" column.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi florian.pfeffer
I am using ABAP CDS Views.
I tried it with two views, but unfortunately I can't get it right.
The problem is, if two categories happen to have the same price, the wrong result will come out. For example,
if category A has the max value 5
Category B has the max value 7
And it then has a product in category B with the value 5, it is marked as max because the 5 of category A in the view with the maximum values.
Can you please help me?
Maybe my code can help to explain:
define view ztt_products
as select from database as db
cross join database2 as db2
association [0..1] to ztt_max as t_max on t_max.key = db.product_id
{
key db.product_id as key,
@UI.lineItem.position: 20
@UI.lineItem.label: 'Price'
db.price as price ,
@UI.lineItem.position: 30
@UI.lineItem.label: 'max?'
case
when db.price = t_max.maxvalue then 'yes'
else 'no'
end as isMax,
@UI.lineItem.position: 40
@UI.lineItem.label: 'Category'
db2.categroy as productCat
}
group by db2.category,db.product_id,db.productname, db.price, t_max.maxvalue
define view ztt_max as select from database as db
{
key db.product_id as key,
max(db.price) as maxvalue
}
group by db.product_id
Hi,
due to if I don't put the product_id in the group by, an error comes: The column "product_id" is not in the GROUP BY list includet". And I need the id for the association.
I forgot the category
Now my second view looks like:
define view ztt_max as select from database as db
{
key db.product_id as key,
max(db.price) as maxvalue
}
group by db.category, db.product_id
If you still see something wrong, what should I improve or change?
User | Count |
---|---|
69 | |
8 | |
8 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.