Skip to Content

Get all data that match to the regex.

Jan 15 at 12:53 PM


avatar image

Hi all

How to create a CDS that select all KUNNR from table KNA1 that Customer Number starts for example with 'A%'.

I could use LIKE in the where clause but the RHS of the condition have to be static. It should depends on the input parameter.

Is it possible to do it with CDS?


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Horst Keller
Jan 15 at 01:16 PM
Show 4 Share
10 |10000 characters needed characters left characters exceeded

Which built-in function can I use to build the regex for where clause?

For example, String Functions can not be used in the where clause.



Read carefully the documentation. It's not obvious for novices, so read the pages several times. You'll get to that one -> ABAP CDS - cond_expr, WHERE. Of course, there's no regular expression around, but LEFT (for instance) is equivalent to LIKE 'A%'.


I tried as following:

@AbapCatalog.sqlViewName: 'ZAMPAYERINFO'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Read payer information'
define view zam_payer_info
  with parameters
    p_payer :kunnr
  as select distinct from knvp
    join                  kna1 on knvp.kunnr = kna1.kunnr
  key knvp.kunnr as Payer,
      kna1.name1 as Name

where knvp.kunnr = left (:p_payer, 10)

But it does not work at all. What am I doing wrong?



After looking at the doc, carefully :), I'm not sure whether you can parameterize it. But as I said in your other thread, I don't know CDS. If I read the doc, I see that CDS is for defining "semantic data models". So, I guess that "LIKE :parameter" in the CDS is not possible because it's "not semantic enough", and it should be done only in the ABAP SELECT. Or maybe, it will be possible to do it in a future release.