cancel
Showing results for 
Search instead for 
Did you mean: 

CDS View - delete entries with duplicate key

Former Member

Hello,

does someone know if there is a way to remove entries that have the same key from a CDS View? Distinct or Group By actually removes only duplicate entries, not entries that have just a duplicate key. Is there a way to use the select "DISTINCT" on only the key fields?

Thank you and best regards,

Cristina

former_member328158
Discoverer
0 Kudos

Hello Cristina,

I have the same issue.

Can you please provide the Source code of the solution ?

Accepted Solutions (1)

Accepted Solutions (1)

I think we can use Group by and Having count clause to remove duplicate entry.

Former Member
0 Kudos

It worked, thank you!

Former Member
0 Kudos

Can you please mention how to delete duplicate records using Group by and Having count .

周建华
Participant
0 Kudos

Example

Example

former_member328158
Discoverer
0 Kudos

I had the same issue and I found a solution.

My requirement was that I had to read the Planned Goods Issue date, Actual Goods Issue date and Delivery creation date from the delivery for every Sales Order Item from the Document flow (VBFA) , but only of the first delivery Item.

Solution :

@AbapCatalog.sqlViewName: 'ZISODELDOCFLOW'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType: #BASIC
@EndUserText.label: 'Relation Sales Order Delivery'
define view ZI_SODELDOCFLOW as select distinct from vbfa
association [0..1] to I_DeliveryDocument as _Del on $projection.DeliveryDocument = _Del.DeliveryDocument
{
key vbfa.vbelv as SalesDoc,
key vbfa.posnv as SalesDocItem,
key vbfa.vbeln as DeliveryDocument,
min (vbfa.posnn) as DeliveryItem,
min(_Del.PlannedGoodsIssueDate) as PlannedGoodsIssueDate,
min(_Del.ActualGoodsMovementDate) as ActualGoodsIssueDate,
min(_Del.CreationDate) as DeliveryCreationDate
}
where ( vbfa.vbtyp_v = 'C' or //ORDER
vbfa.vbtyp_v = 'I' ) and //ORDER W/O CHANGE
vbfa.vbtyp_n = 'J' //DELIVERY
group by vbfa.vbelv,
vbfa.posnv,
vbfa.vbeln

Answers (2)

Answers (2)

sanju_joseph
Participant
0 Kudos

it is a combination of min and group by clause that does the filter, for example if i don't want to have business partner repeated for different role.
then i have to use

min ( tb003t.role ) as xyz and i should not use tb003t.role in group clause ,which is also the way above code works.

former_member328158
Discoverer
0 Kudos

I had the same issue and I found a solution.

My requirement was that I had to read the Planned Goods Issue date, Actual Goods Issue date and Delivery creation date from the delivery for every Sales Order Item from the Document flow (VBFA) , but only of the first delivery Item.

Solution :

@AbapCatalog.sqlViewName: 'ZISODELDOCFLOW'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType: #BASIC
@EndUserText.label: 'Relation Sales Order Delivery'
define view ZI_SODELDOCFLOW as select distinct from vbfa
association [0..1] to I_DeliveryDocument as _Del on $projection.DeliveryDocument = _Del.DeliveryDocument
{
key vbfa.vbelv as SalesDoc,
key vbfa.posnv as SalesDocItem,
key vbfa.vbeln as DeliveryDocument,
min (vbfa.posnn) as DeliveryItem,
min(_Del.PlannedGoodsIssueDate) as PlannedGoodsIssueDate,
min(_Del.ActualGoodsMovementDate) as ActualGoodsIssueDate,
min(_Del.CreationDate) as DeliveryCreationDate
}
where ( vbfa.vbtyp_v = 'C' or //ORDER
vbfa.vbtyp_v = 'I' ) and //ORDER W/O CHANGE
vbfa.vbtyp_n = 'J' //DELIVERY
group by vbfa.vbelv,
vbfa.posnv,
vbfa.vbeln