12-03-2019 9:53 PM
We are on Netweaver 7.5. I am just starting with using CDS for production application. I have a simple CDS view where I am using CAST. In ADT I get a warning:
CAST USRID from CHAR to type NUMC: target type length too small, loss of data poss.
The source field only should ever have the target type and length. I have tested with various bad data and am fine with how it is handled (truncated).
Is it possible to suppress the warning? Is there something like a pragma for this purpose? Or is it considered a bad idea to never ever ever do, meaning I should change the view and handle the cast outside CDS? (that last doesn't sound right ...)
Please be gentle with me, as I said I am just getting started with these. 🙂
Thanks!
12-04-2019 12:46 PM
Got it ... use substring first:
cast( substring( usrid, 1, 8 ) as abap.numc( 8 ) ) as my_field,
this solves the syntax warning and gives the expected result.
Thanks to anyone who gave some thought to this, I hope my resolution is helpful to you.
12-03-2019 10:11 PM
Hi,
you should read cast_expr, Conversion Rules
Source types CHAR and SSTRING
12-04-2019 12:02 AM
Thanks for the link. Yes, it is a syntax warning as I am doing it, but I think I do want the result field in the view to be cast to the shorter type. Since that field in the result set is expected to be a PERNR, it will be used as a PERNR, potentially to select from another PA table in a next step of a program.
The question is whether there is a different way to do it that gets the result but avoids the syntax error? Or can I just suppress the syntax error with something like a pragma that says, "hey, I've thought about this and I really want to do it?"
12-04-2019 12:46 PM
Got it ... use substring first:
cast( substring( usrid, 1, 8 ) as abap.numc( 8 ) ) as my_field,
this solves the syntax warning and gives the expected result.
Thanks to anyone who gave some thought to this, I hope my resolution is helpful to you.