a month ago - last edited 3 weeks 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
Hello @bharatbajaj
In S/4HANA you can find a Demo Package in the package tree with hundreds of CDS View example.
You can check it out here... I found this example. Maybe it helps.
BR, Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Martin,
Thanks for sharing this, I already tried this approach of using CURR_TO_DECFLOAT_AMOUNT, but then I get annoying error :
Also, I tried another apporach by casting DMBTR as Dec(23,2), that finally worked:
However, now I have another problem. I want to do the same for another amount field WRBTR, and i want to use the same 'calculatedUnit' for this fields as well. but then it cries that the 'calculatedUnit' can be used only once (see below). This is illogical in my opinion as why would the system not allow to use a unit as reference for multiple fields?
That means, for each Amount field calculation, I need a separate calculatedUnit (having the same or different value).
(honestly I don't understand why we even need this calculatedUnit and can't use the CURR reference instead, as the calculated value (dmbtr_per_menge) is an amount and not a quantity)
Just to emphasis the challange here, my real use case it to convert atleast 15 cost fields from KEPH table (say KST001...KST015 ) to get per unit cost for materials in business report. So with this approach, I need to create 15 'calculatedUnit' fields in the CDS having the same value (say EUR / KG).
This is not CLEAN ABAP in my opinion, and I am still looking for a better and simpler way of achieving this.
Regards,
Bharat Bajaj
User | Count |
---|---|
77 | |
10 | |
10 | |
10 | |
10 | |
9 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.