Homelab, Linux, JS & ABAP (~˘▾˘)~

[CAP] Select max with group by



entity myEntity {
        key ID: Integer;
        key seqNr: Integer;
        key createdAt: DateTime;

entity myEntityMaxSeqNr 
        as select from myEntity {
            count(seqNr) as maxSeqNr: Integer
        group by 

This can also be done using CQL like here.

[CAP] min and max functions

Since there is nothing in the official CAP documentation about min and max functions, I figured out the following syntax:

    const result1 = await cds.run(`SELECT *, MAX(seqNr) FROM ${myTable} LIMIT 1`) //returns array

    const result2 = await SELECT.one.from(myTable, [`MAX(seqNr)`]).columns('*') //returns object 

    const result3 = await SELECT.one.from(myTable).columns('MAX(seqNr)') //returns object containing only the max counter value

[CAP] CQL Expand Composition / Deep read

In the documentation they always use a star in string literals like this o => o.`*` to select all fields, but when running this it always failed. However, after some tests I found that this format works with brackets o => o.('*')


entity myEntity: cuid, managed {
    field1          : String;
    comp            : Composition of one myComposition;
aspect myComposition: cuid, managed {
    myCompField: String;
        const result = await SELECT.from(myEntity)
            .columns(e => {
                e.comp(c => c.myCompField) //expand composition, but only select 'myCompField'

Update 14.09.2023: is now fixed (#)