cancel
Showing results for 
Search instead for 
Did you mean: 

How can i use db lookup expression with sort on additional field?

william_eastman
Advisor
Advisor
0 Kudos

using a db lookup (and maybe that is not the right expression type in this case), I want to select a single field (or table line) from a table, call it customer number, where I specify a value for selection parameter, call it product - but where I also want to select only the table entry where the date is most recent, call it creation date. Is this possible?

I cannot find a way to incorporate the creation date sort into the selection condition - and did not expect to be able to do so.

I have tried using select into a structure and then using the aggregation of maximum for creation date, but the returned value does not correspond to the correct line in the table.

I know I could select all entries and then do a table operation against the resulting table, but I was hoping for a way to do it in the single expression. How can it be done?

Accepted Solutions (0)

Answers (1)

Answers (1)

pokrakam
Active Contributor
0 Kudos

There are no hard rules as to what should be done in BRF, I would implement this as a procedure call expression and do the SELECT in a method. Or a DB lookup expression on a CDS view.

On a more general note, it does raise an interesting question of what belongs in the code or DB layer, and what belongs in a rule. In my experience I've seen overuse of BRFplus with very complex technical logic that should really be in code. Personally I believe something should go into the rule engine if it should be changeable and/or if it provides transparency (i.e. business-relevant). Rules can get complex enough, no need to clutter them with unnecessary technical detail.

In this case, selecting from a view MOST_RECENT_CUST_FOR_MATL is clear enough for anyone to understand, and highly unlikely that the date criteria needs to be edited. Therefore I'd avoid doing anything complex in BRFplus to achieve a simple result.

william_eastman
Advisor
Advisor
0 Kudos

thanks for the comment mike.pokraka I know I can do it in a procedure call. I want to do it in an expression though.