CDS Views: return most recent record

Hi,

I am new to CDS View and I am facing a simple problem I guess.

My CDS View entity is defined as:

define view entity ZV_SER03
as select from ZV_OBJK_1_MAX as objk
association [1] to ser03 on ser03.obknr = objk.obknr
{
key ser03.obknr,
objk.matnr,
ser03.datum,
ser03.uzeit
}
where
ser03.werk = objk.b_werk
and ser03.lagerort = objk.b_lager
and ser03.shkzg = ‘S’;

And here is an example of the result it returns:

matnr;obknr;datum;uzeit
0000000000002364065;32983;20270605;160321
0000000000002364065;33043;20230606;113445
0000000000006666666;33047;20240606;113526
0000000000066666666;33048;20230606;114025
0000000000007777777;33051;20230606;114117

From this example I would like to create a new CDS view entity that returns for each MATNR/OBKNR the most recent record, from the datum and uzeit fields.

The result from the example above should therefore be:

matnr;obknr;datum;uzeit
0000000000002364065;32983;20270605;160321
0000000000006666666;33047;20240606;113526
0000000000007777777;33051;20230606;114117

Thanks in advance for your help.

 

Scroll to Top