cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

built-in SQL-function instr(arg, sub): type issue

JohannesGilbert
Product and Topic Expert
Product and Topic Expert
0 Likes
4,257

Hi,

When using the built-in function instr() in an ABAP CDS view I face the issue that specifying a character literal that could also be a numeric literal result in a compilation error: "Funktion INSTR: Parameter an Position 2 hat den falschen Datentyp NUMC" Translated into english it would be like 'function INSTR: parameter at position 2 has the wrong data type NUMC'. The CDS view is defined as follows:

@AbapCatalog.sqlViewName: 'z_test_jg3'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'test 2'
define view Z_Test3 as select from vbak {
  //Key
  key vbak.vbeln as SalesDocument,
  instr(vbak.vbeln, '50') as test
}

As you can see literal '50' is used. If I change the literal to e.g. ' 50' or 'a50' is error is gone (of course). However, field vbeln of table vbak does only contain numeric values. Thus, the intention of this statement is to check if the vblen contains string '50'. Is there any possibility to either indicate that '50' should be interpreted as character literal? Or is there any other possibility or work-around?

Best Regards,

Johannes

View Entire Topic
anindya_bose
Active Contributor
0 Likes

Hi Johannes

Can you try assigning '50' to a variable type NVARCHAR and then use that variable in instr function ?

Something like.,   lv  := '50' ;

instr(vbak.vbeln, lv)

Cheers

Anindya

JohannesGilbert
Product and Topic Expert
Product and Topic Expert
0 Likes

Please be a bit more precise how this usage of an variable could be used in the initially posted CDS view.

anindya_bose
Active Contributor
0 Likes

I saw videos for CDS with Input Parameters, did  not test myself through .

How to create ABAP CDS Views with Input Parameters on SAP HANA - YouTube

Easier way could be using a SUBSTRING function to convert '50'  to character format before using in Instr function.

Like, Lars  I did not get INSTR function , may be a version problem.  I tried that with Replace function and it worked.

Here is my code :

**********************************************************************************

@AbapCatalog.sqlViewName: 'ZSQL_VIEW'

define view ZCDS_TEST

as select from /bic/azbsdoit100 as vbak

{

  key vbak.doc_number as SALES_DOC ,

  REPLACE (vbak.doc_number,'60', SUBSTRING ('50',1,2)) as test

    }

*********************************************************************************************

Can you try instr(vbak.vbeln, SUBSTRING ('50',1,2)) as test and share the result ?


**/bic/azbsdoit100 - this is my BW table, just used an alias vbak for this.



Cheers

Anindya