on 2024 Sep 10 2:09 PM - last edited a month ago
Dear community members,
I need to create a CDS view entity with a calculated filed as CURR / QUAN to get the per unit amount.
For Example: CDS VIEW ENTITY on BSEG which should have ( DMBTR(type CURR) / MENGE(type QUAN) ) AS UNIT_PRICE
Sounds like a very simple requirement but I am facing multiple issue with this.
To start with, I get below error message:
"Data type CURR is not supported at this position, see long text"
then I tried with casting CURR field as DEC(23.2), but then I got below error :
"Element <XXXXX> : missing CALC-reference annotation Semantics.quantity.unitOfMeasure"
it was surprising to see that it prompted to user UOM reference, instead of Currency reference, but nevertheless, I tried with the UoM reference, but then again a different error :
"<XXXXX>: Reference Field MEINS has a wrong data type"
then I tried to CAST the MEINS as abap.char(3) to use it as reference for calculated field, but then a different error this time, and this is really annoying this it didn't allow casting a text value into CHAR.
I also tried to google this error message and found some conversion function but then I get different errors:
1. Using function : GET_NUMERIC_VALUE
"Element DMBTR has an invalid reference field"
2. using function : CURR_TO_DECFLOAT_AMOUNT
"Element DMBTR has an invalid reference field"
I tried few more ways but none of them is working for me and I really wonder how can this be so challanging to achieve AMOUNT / QUANTITY in CDS VIEW ENTITY, which is a very basic arithmetic operation.
Same arithmetic calculation works perfectly well in ABAP code (as we have done that for decades), so now I am thinking to use Virtual elememt in CDS, but I want to achieve with the CDS approach first, without making use of ABAP layer.
Any tips to solve this ?
regards,
Bharat Bajaj
So I have finally managed to solve this problem by using the CAST expressions on both the AMOUNT and QUANTITY fields. That ofcouse needs the refernece to the Currency Code as well.
Here is the correct CAST expression I used to achieve the Amount per Unit:
@Semantics.amount.currencyCode: 'rfccur'
cast( cast(dmbtr as abap.dec( 23, 2 )) / menge as abap.dec( 23, 2 )) as dmbtr_per_menge
Explanation :
Note : if I didn't use the 2nd CAST expression (in point 4 above), then I would be getting the below error :
I found this approach much simpler and cleaner, compared to using the other CDS Functions and the CalculatedUnit, which anyway didn't work for me.
Hope this would help others who have similar requirement.
Regards,
Bharat Bajaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
71 | |
11 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.