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

Concat function or equivalent for CDS view?

Former Member
0 Likes
14,330

Trying to create a CDS view and looking to combine multiple character fields (e.g. first_name + last_name) and am wondering if this is possible? Am on CRM NW 7.4 SP5 on HANA.

Using the arithmetic function gives me the following.

Data type CHAR is currently not supported in an arithmetic expression

Looking at the official documentation here, it doesn't appear to be included?

ABAP Keyword Documentation

I can always create a AMDP or even a HANA native view, just wondering if anyone has come across the same issue and found a solution within CDS view?

Thanks in advance,
Sean.

1 ACCEPTED SOLUTION
Read only

jasmin_gruschke
Product and Topic Expert
Product and Topic Expert
0 Likes
9,181

Hi Sean,

there's no concatenate function as of 7.4 SP5.

A workaround in OpenSQL (if that's the combination you use), you could use the columns of your choice in the projection list like (I use literals in the example for simplicity):

{

'a' as a,

'b' as b

}

and concatenate later by means of OpenSQL:

select
a && b from <cds_view> into ….

However, if you want to use the view in an ALV this does not help you, I know…

Cheers,

  Jasmin

16 REPLIES 16
Read only

jasmin_gruschke
Product and Topic Expert
Product and Topic Expert
0 Likes
9,182

Hi Sean,

there's no concatenate function as of 7.4 SP5.

A workaround in OpenSQL (if that's the combination you use), you could use the columns of your choice in the projection list like (I use literals in the example for simplicity):

{

'a' as a,

'b' as b

}

and concatenate later by means of OpenSQL:

select
a && b from <cds_view> into ….

However, if you want to use the view in an ALV this does not help you, I know…

Cheers,

  Jasmin

Read only

0 Likes
9,181

Thanks Jasmin, thanks for the confirmation and work around solution.

Much appreciated,

Sean.

Read only

Former Member
0 Likes
9,181

Hi,

Currently we're at support pack 7 for AS ABAP. But seems that it's still not possible right?

Actually I created an CDS view and wanted to use it within a FOR ALL ENTRIES comparing a documentnr and document item nr. With using both of the fields the performance was really low. But when I remove the document item nr, it was 8 times faster. So I wanted to create one field with the document and item number concatenated, so that I only have 1 field to compare within the FOR ALL ENTRIES.

Thanks in advance.

Regards,

Bart

Read only

0 Likes
9,181

Hi Bart,
the discussion was about concatenation of fields using Open SQL syntax, which is possible as of AS ABAP 7.4 SP05.
However, as I understand, you are asking about concatenation in a CDS view, right? This is possible, yet only as of Support Package 08.

Best,

  Jasmin

Read only

0 Likes
9,181

Will it also be possible to use such syntax in joins (concatenations, substrings,...)? I would like to do something like this :

@AbapCatalog.sqlViewName: 'ZV_CDS_INVC'

define view zcdsv_rbkp_bkpf as

select from rbkp as a inner join bkpf as b

                      on CONCAT(a.belnr,a.gjahr) = b.awkey

{

key a.belnr,

key a.gjahr }

If I do this directly on the database, this is not a problem.  In Open SQL I have to solve this with a for all entries and it would be much easier if I could use CDS for this (just finished the OpenSap course on Abap development on Hana and ready to go ).

Regards,

Freek

Read only

0 Likes
9,181

Hi Freek,

this functionality will surely come, but it will take some time until available.

Until then you can help yourself by creating two views: In the first view build a new column with the concatenation and then use this view and its column in a second view for the join condition.

Best Regards, Thomas

Read only

0 Likes
9,181

Hi Thomas,

Thank you for the information.  The work-around is definitely useful.

Regards,

Freek

Read only

0 Likes
9,181

Hi Thomas,

I have most recently come up with another issue with the concat function.  I have created a view to solve the problem above (the concat to fix the RBKP-BKPF join) as per your work around.  The problem that I'm now experiencing is that, while the concatenated field I created contains the key fields belnr and gjahr from the RBKP table, when I use this field in a query, no index is used on the database.  So my next question is :

- How can I get the query/CDS view to use an index on the underlying table?

- Can I create an index on the new column itself on the CDS view?

My view is this (I only kept the relevant columns)

@AbapCatalog.sqlViewName: 'zrbkp_concat'

@ClientDependent: true

@AbapCatalog.compiler.CompareFilter: true

@AccessControl.authorizationCheck: #CHECK

@EndUserText.label: 'CDS view on RBKP with BELNR/GJAHR concatenation'

define view Zcds_Rbkp_Concat as select from rbkp {

  key belnr,

  key gjahr,

  concat(belnr, gjahr) as awkey

}

Read only

0 Likes
9,181

Hi Freek,

you can neither build an index for a CDS view column nor can you force the database to reverse the concat function (when using the concatenated field in an ON condition or a WHERE condition) as the function is not bijektiv.

Rule of thumb: avoid expressions for key fields!

Best Regards, Thomas

Read only

klaus_herter
Employee
Employee
0 Likes
9,181

Hi Sean,

is your original request solved by the CONCAT function within the select list:

CONCAT(user.first_name, user.last_name) as ...

I was wondering the same way as you but this was the only thing that I found with a missing space ?

BEST, Klaus

Read only

jasmin_gruschke
Product and Topic Expert
Product and Topic Expert
0 Likes
9,181
Read only

0 Likes
9,181

Hi Jasmin,

we're on SP9 and I have a need to use CONCAT but I'm getting an error saying "this function or expression is not supported at this point". Any idea why that would be?

thanks,

Malcolm.

Read only

jasmin_gruschke
Product and Topic Expert
Product and Topic Expert
0 Likes
9,181

Hi Malcolm,
you are trying to use it in a CDS View (DDL Source) in the ABAP?

Where exactly do you try to use it? In the projection list, the ON condition of a JOIN/ASSOCIATION, in the WHERE clause, ...?

What's the exact error message, can you please paste it here (maybe even including the TRMSG message number - you can find it in the problems view after adding in the problems view this dedicated column).


Cheers,
  Jasmin

Read only

0 Likes
9,181

Hi Jasmin,

yes, CDS View in the ON condition of a JOIN.

and the error is "this function or expression ('CONCAT') is not supported at this point". I opened the problems view but can't see a message number.

thanks,

Malcolm.

Read only

jasmin_gruschke
Product and Topic Expert
Product and Topic Expert
0 Likes
9,181

Hi Malcolm,

to see the message ID, you'd have to click in the problems view on the "drop down" icon. There you can select "Configure Columns..." and move "ID" from the "Hidden" to "Shown" columns.

But comming to your issue. The CONCAT function is not allowed or let's say supported at that position. You can use a view on view as a workaround, i.e. a intermediat view "z_intermed_view" having the CONCAT('S', a.mc_short ) as prefixed_with_s in the projection list and then do a left outer join to z_intermed_view with prefixed_with_s in the ON condition.

Best,
  Jasmin

Read only

0 Likes
9,181

thanks Jasmin. That worked well.