SAP Knowledge Base Article - Public

3505739 - Duplicates in Custom CDS views joining Purchase order and Good receipt documents data

Symptom

There are duplicates in the custom CDS view when joining the Purchase Order and GR documents.

"Image/data in this KBA is from SAP internal systems, sample data, or demo systems. Any resemblance to real data is purely coincidental."

Environment

SAP S/4HANA Cloud Public Edition

Reproducing the Issue

A custom CDS view, YY1_POSCHDL, is created.

The custom CDS view utilizes the main data source I_PurchaseOrderAPI01, which is associated with I_PurOrdScheduleLineAPI01.

 

The join condition chosen is I_PurOrdScheduleLineAPI01.PurchaseOrder = I_PurchaseOrderAPI01.PurchaseOrder.

Please note that a warning appears indicating that the cardinality is likely "Zero or More".

 

In the Elements tab, select the following fields:

 

When the custom CDS view YY1_POSCHDL is previewed, a duplicate of the same Purchase Order ("4500023724") is encountered.

 

If the Elements tab is accessed and an entry is added, it will be noted that the Key includes PurchaseOrder, PurchaseOrderItem, and PurchaseOrderScheduleLine.

 

Select the key fields and add 

 

When the view is previewed, it is noted that the PurchaseOrderScheduleLine is different (001/002) for Purchase Order "4500023724".

 

Cause

  • An association to a data source has been made, but the full key is not used in the join condition.
  • The fields that differ are not exposed, resulting in the records appearing identical.
  • A field from an implicit association with To-Many cardinality is being exposed.

As per Join Condition | SAP Help Portal:

The Custom CDS Views app derives the cardinality suggestion from the number of key fields that are mapped: If all key fields are mapped, the suggestion is a “zero or one” cardinality. If not all key fields are mapped, the suggestion is is “zero or more” cardinality. You will be warned when the cardinality that you chose is suspicious. Choosing a wrong cardinality does not restrict your result set. It’s not a filter, but it can influence the way your association can be used. 

To make sure you have a real “to one” association, you should map all key fields of your associated data source. To do this, you can use the Add All Fields button.

 

How to check the key fields of a data source?

Custom CDS Views app > Elements Tab > Click on Add > Select "Show used" Yes > Expand primary data source and associations: The keys are marked in the Key column.

Use the "Propose Join Condition" as explained in Maintaining the Join Condition | SAP Help Portal 

 

How to check the cardinality of an implicit association in a data source?

Custom CDS Views app > Elements Tab > Click on Add > Select "Show used" Yes > Expand primary data source and associations: The cardinality is displayed next to the association tag in the Type column.

View Browser app > select view i.e. I_PurchaseOrderAPI01 > go to Cross Reference tab > check the Cardinality column. The cardinality for I_PurchaseOrderItemAPI01 is "0..*" (Zero or More).

Resolution

Select the key fields and add them to the Custom CDS View.

Keywords

Duplicated, Cds view, join condition , KBA , MM-PUR-GF-CE-2CL , Customer Enhancements (Public Cloud) , How To

Product

SAP S/4HANA Cloud Public Edition all versions