Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ABAP CDS equivalent for string_agg function from HANA SQLScript ?

Former Member
9,157

Is there any equivalent in ABAP CDS for string_agg function from HANA SQLScript?

Or there is a way using CDS to accomplish transformation of rows into a concatenated string?

I saw that there is a possibility to create a CDS table function implemented by an AMDP but i didn't see any example of calling this cds table function from another CDS view. Is this possible? Can somebody help me with an example?

Note:

string_agg - concatenates rows into a string separated by a delimiter

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
5,913

Hi Mustafa,

The only solution is to implement the query in a AMDP using string_agg.

This amdp method can be explosed by table function in CDS.

This table function can be called from a CDS view.

Here is an example:

AMDP:

METHOD GET_CONCAT BY DATABASE FUNCTION FOR HDB LANGUAGE SQLSCRIPT OPTIONS READ-ONLY USING

    /TABLE 

   RETURN

     select

        mandt,     

        key,

        STRING_AGG( field)  AS concat

     from "TABLE"

     group by mandt, key

  ENDMETHOD.

CDS TABLE FUNCTION:

define table function tf_concat

returns {

    mandt : syst_mandt; 

    key      : raw

    concat : abap.sstring( 1333 );

}

  implemented by method

    AMDP=>GET_CONCAT;

CDS VIEW:

define view v_concat

as select from tf_concat{

    mandt,

    key,

    concat

};

Best regards,

Andrei

3 REPLIES 3
Read only

msadik
Explorer
0 Likes
5,913

Hi Andrei;

i have the same issue. did u find any solution to this

thanks

Read only

Former Member
0 Likes
5,914

Hi Mustafa,

The only solution is to implement the query in a AMDP using string_agg.

This amdp method can be explosed by table function in CDS.

This table function can be called from a CDS view.

Here is an example:

AMDP:

METHOD GET_CONCAT BY DATABASE FUNCTION FOR HDB LANGUAGE SQLSCRIPT OPTIONS READ-ONLY USING

    /TABLE 

   RETURN

     select

        mandt,     

        key,

        STRING_AGG( field)  AS concat

     from "TABLE"

     group by mandt, key

  ENDMETHOD.

CDS TABLE FUNCTION:

define table function tf_concat

returns {

    mandt : syst_mandt; 

    key      : raw

    concat : abap.sstring( 1333 );

}

  implemented by method

    AMDP=>GET_CONCAT;

CDS VIEW:

define view v_concat

as select from tf_concat{

    mandt,

    key,

    concat

};

Best regards,

Andrei

Read only

0 Likes
5,913

Hi Andrei;

it works. thank you so much.