Skip to Content
author's profile photo Former Member
Former Member

CDS View - delete entries with duplicate key

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    Posted on Jan 16, 2017 at 08:27 PM

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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Sep 23, 2017 at 08:44 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 02, 2018 at 12:48 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.