SAP Knowledge Base Article - Public

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

Symptom

Why do I see duplicates in my custom CDS view when I join the Purchase Order and the GR documents. 

See the example and potential similar cause as is explained bellow.

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

Reproducing the Issue

You create a custom CDS view YY1_POSCHDL

The custom CDS view has main data source I_PurchaseOrderAPI01 with association to I_PurOrdScheduleLineAPI01

 

You choose join condition I_PurOrdScheduleLineAPI01.PurchaseOrder = I_PurchaseOrderAPI01.PurchaseOrder.

Please notice a warning appears: Cardinality is likely "Zero or More"

 

In the Elements tab, you have selected the following fields:

 

When you preview the custom CDS view YY1_POSCHDL, you get a duplicate of the same Purchase Order ("4500023724"):

 

If go to the Elements tab > add, you will notice that the Key includes PurchaseOrder, PurchaseOrderItem and PurchaseOrderScheduleLine

 

Select the key fields and add them

 

When you preview the view, you will noticed that PurchaseOrderScheduleLine is different(001/002) for Purchase Order "4500023724":

 

Cause

  • You have made an association to a data source and you haven't used the full key in the join condition.
  • You are not exposing the fields that are different and the records look equal.
  • You are exposing a field from an implicit association (primary or secondary data source) that has To-Many cardinality.

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.

You can 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 , Customer Enhancements , How To

Product

SAP S/4HANA Cloud Public Edition 2402