on 2016 Jan 19 9:27 AM
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
Request clarification before answering.
An easy way to bypass this issue is to use the following definition instead:
@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(replace(vbak.vbeln, '0', 'a'), '5a') as test
}Via this chained function usage at first zeros are replaced by some single, non-numeric character (you could also replace another number value). Secondly, function instr() could be used as initially intended. Note: Function replace() will need additional runtime. However, as I just needed to get this working and my code is neither performance ciritial nor there are other backdraws for my use-case, this is a fine solution for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 13 | |
| 8 | |
| 7 | |
| 5 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.