For each object number in JEST table I want to get a single status that I consider my main status.
The main problem is that some status that in my case I consider unique like I0076 (deletion flag) can be active at the same time than others like created (I0001). In this scenario I would like to use GROUP BY objnr and then use a CASE in the status where I0076 always overrides any other status.
Is that possible with ABAP CDS or SQL? Or do I have to write ABAP code (AMDP or post processing) to solve this?
Input:
+-------+-------+
| OBJNR | STAT |
+-------+-------+
| OBJ1 | I0001 |
| OBJ1 | I0076 |
| OBJ2 | I0001 |
+-------+-------+
Output:
+-------+-------+
| OBJ1 | I0076 |
| OBJ2 | I0001 |
+-------+-------+
You can build your status priority in your CDS view definition with aggregation on
CASEcondition andCOALESCE. If your statuses are split into two groups of mutually exclusive statuses (say "overriding" and "non-overriding"), then it is enough to have only oneCOALESCEand oneCASE.Like this:
If you can have more than one status in each group, then you can nest as much
coalesceas you need putting the highest priority statuses first (because in CDScoalescefunction accepts only two arguments, but in SQL it can have many).Of course, it will need to be updated for new statuses, but because CDS syntax is limited, I do not see lightweight options.
For more robust solution you can create another CDS view which will contain status priority with the structure:
where each overriding statuses will be placed with higher priority and priority should uniquely identify status. It may be taken from some Z table where you directly put priority or from customizing settings if they are available or from your coded AMDP (for example, substringing last 3 characters and ordering by them via
row_number()function).Then you need to have two views joined with that view:
MAX( PRIORITY ) as FINAL_STATUSUPD: If you always have overriding status (
I0076in your case) after any general status (I0001), then you can useLEFT OUTER JOINwith the sameJESTtable filtered in-place. Below DDL source was successfully activated in SAP_ABA 750 SP 08.