Application Development 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: 

how can one select data similar to SQL WHERE LIKE from a parameter value

former_member267947
Participant
0 Kudos

Hi all

I have the following CDS:

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

that the compiler complains:

Comparison value of LIKE condition must be a character-type literalZAM_PAYER_INFO (Data Definition)

As you can see on the CDS code, I am using character-type.

I understand, what LIKE statement do, for example:

@AbapCatalog.sqlViewName: 'ZAMPAYERINFO'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Read payer information'
define view zam_payer_info
  with parameters
    p_payer : abap.char(10)
  as select distinct from knvp
    join                  kna1 on knvp.kunnr = kna1.kunnr
{
  key knvp.kunnr as Payer,
      kna1.name1 as Name
}
where
  knvp.kunnr like 'a%'

Search all kunnr that starts with a. But my problem is, how to combine it with input parameter p_payer, at the end it should be LIKE %p_payer, where p_payer will be replace through the value that I passed.

What can be wrong?

Thanks

9 REPLIES 9

horst_keller
Product and Topic Expert
Product and Topic Expert

Please read the documentation ...

It is as close as F1.

0 Kudos

zero_coder I don't know CDS, but I guess this sentence of the documentation applies to your question: "Only character-like literals without domain prefix are allowed for rhs." (refer to the definition of "literals")

Maybe you want to post another question like "how can one select data similar to SQL WHERE LIKE from a parameter value ..."

0 Kudos

What is domain prefix mean?

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

Oh my, follow the link to literals ...

0 Kudos

horst.keller I read the doc several times and could not figure out, what is wrong with the code above.

Is there a way to build character-like literals with P_PAYER. A character literal 'character_literal' is a character string enclosed in quotation marks. How can I build it with P_PAYER character literal?

Thanks

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

Seems that you don't understand the concept of literals.

Aha. It has to be like '%a' otherwise it is not possible, it can not derive from a parameter?
How can I create a select for "Give me all customers, that the name starts with a f"?

Thanks

Sandra_Rossi
Active Contributor
0 Kudos

Please don't post your reply via "Submit your Answer", which is reserved to people giving a possible answer to your initial question. Moreover, people are not notified of your reply.

Instead, use "Comment on this answer". If too late as is the case here, you may convert your Answer into a Comment via Actions -> "Convert to Comment".

former_member267947
Participant
0 Kudos

But I could rewrite the CDS to:

@AbapCatalog.sqlViewName: 'ZAMPAYERINFO'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Read payer information'
define view zam_payer_info
  with parameters
    p_payer : abap.char(10)
  as select distinct from knvp
    join                  kna1 on knvp.kunnr = kna1.kunnr
{
  key knvp.kunnr as Payer,
      kna1.name1 as Name
}
where
  knvp.kunnr like 'a%'

That would mean, give all entity an kunnr starts with a. My problem is, how to substitute it with p_payer input parameter?
Thanks