cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Adding a Calculated field from Item-level to Sales Order Fiori app

RaminS
Active Participant
2,544

We need to add a column to the Sales Order table in F1873, which is the total of amounts of a specific item type.

The CDS view for this table is: C_SalesOrderWl_F1873

which selects from the header of Sales Orders, with association to Items. I created an extension for this CDS view to do the calculations, but realized Virtual Elements don't work for anything but project views.

RaminS_0-1718311834119.png

How else can I extend an SAP cds view to display an item-level field that needs calculations, in the Sales Order table without the use of Virtual Elements? Do Table Functions work in a CDS extension?

We are on S/4HANA 2020.

Thanks in advance.

 

 

Accepted Solutions (1)

Accepted Solutions (1)

RaminS
Active Participant

The issue was that the syntax is only valid for RAP, with projection views. For non-RAP versions, the syntax is the same but you don't use "virtual" in front of the column.

An example can be found in C_Customer360_F2187:

RaminS_0-1718396919266.png

 

@objectModel.virtualElement
@ObjectModel.virtualElementCalculatedBy: "ABAP:class_name"
cast( '' as <type> ) as colname

Have to be careful these days when reading SAP documents, to make sure it's the right version, with so many versions and frameworks around.

Answers (2)

Answers (2)

junwu
SAP Champion
SAP Champion

it is not first time you didn't respect my answer.

 

RaminS
Active Participant

Your answer would confuse more than clarify. You use the wrong cds view example, and you pasted the code without using the code tag, and not even include the column line. That's the difference between RAP and non-RAP syntax. You didn't even include that part in your answer, and didn't bother clarifying it. Answers have to be clear and not crypted.  It would have  taken 2 minutes to edit and correct your answer when I asked you to,  why wouldn't you?

junwu
SAP Champion
SAP Champion

just take a look at the C_SalesOrderWl_F1873 regarding how the virtual element is implemented.

the one you are trying to use is for RAP.

 

@ui.hidden: true

@Semantics.text:true

@ObjectModel.virtualElement: true

@ObjectModel.virtualElementCalculatedBy: 'ABAP:CL_SD_SLSORD_UI_PARTNER_UTIL'

cast('' as ad_namtext ) as SalesEmployeeName,

RaminS
Active Participant
0 Likes

Thanks. I'm not sure what you mean by "just take a look at the C_SalesOrderWl_F1873 regarding how the virtual element is implemented".

Our version of that CDS view does not have a virtual element. And we don't have CL_SD_SLSORD_UI_PARTNER_UTIL in our system.

Where can I see that example?

Thanks

RaminS
Active Participant
0 Likes

I found a CDS view that does use Virtual Elements, C_Customer360_F2187. And used that example to build my extension.

 

RaminS_0-1718375484594.png

 

Thanks for the hint JunWu. 😊

junwu
SAP Champion
SAP Champion
0 Likes
if your issue is solved, please select the correct answer to close the thread.
RaminS
Active Participant
0 Likes

If you want to edit your answer and correct the cds view you are referring to, I will mark it as correct answer. But right now the CDS view you mention, C_SalesOrderWl_F1873, does not have a virtual element. So it is not correct.

junwu
SAP Champion
SAP Champion
0 Likes
my bad, i was looking at s4 2022, that cds does have virtual element, but anyway, my answer already contains the correct the syntax for the virtual element, don't u see it?