06-27-2022 7:36 AM
Hi Experts,
As I understand its not possible to cast CHAR to DEC based on documentation from SAP.
My requirement is to get the difference of 2 fields, one is an amount, the other is a CHAR type field. When I try to do the arithmetic expression, error is being raised that it you cannot subtract CHAR from amount field. This is why I want to cast the CHAR into an amount field with decimals. How can I do this? Are there any workaround?
Thanks and regards,
Rowie Formaran
07-06-2022 9:54 AM
Hi All,
This has been resolved. i used a table function and used function to_decimal to convert.
06-27-2022 9:14 AM
Just for reference, here is the link to ABAP Documentation which says that CHAR can be converted only to CHAR, SSTRING, NUMC, CLNT, LANG, DATS, TIMS, UNIT, CUKY, and ACCP.
06-27-2022 1:06 PM
06-27-2022 1:17 PM
Hi Thorsten,
NUMC doesn't have decimals right? What if the CHAR value has decimals?
06-27-2022 1:37 PM
I have tried following sql in the HANA SQL console.
I'm not sure, if this also works with CDS views.
select 0.000 + '12.34' from dummy
08-10-2023 2:11 PM
Thanks for your hint. I know it is not really relevant here but I needed this to convert a timestamp field in char format to the actual timestamp format in CDS.
cast ( cast ( CharTimestampField as abap.numc( 14 ) ) as timestamp ) as TimestampField,
08-10-2023 2:50 PM
pramod.teewaree You're right, probably not relevant, so, why not posting it as a new question + answer? (anyway, you may go to the CAST documentation and you can see all permitted conversions)
07-06-2022 9:54 AM
Hi All,
This has been resolved. i used a table function and used function to_decimal to convert.
09-28-2023 2:57 PM
Hi,
As direct casting of char to currency is not possible, we need to cast char to numc first and then to currency. So, I converted Char to Currency , by concatenating '.00' to char value , then casting it to numc , an again casting it to Currency.
cast( cast(concat(amountchar, '.00') as abap.numc(30) ) as wrbtr_z) as Amountcurrency
Hope this helps.
12-06-2023 2:08 PM