Skip to Content

What does the error shown in the image mean (Duplicate resource)?

screen-shot-2018-12-14-at-162548.pngI am trying to build a cds view by joining two tables vbap and prcd_elements. I encounter the error shown in image when I publish it as a Odata service and access it from browser. The code for my cds view is shown below.

@AbapCatalog.sqlViewName:'Z_VBAP_PRCD_ELEM'

@AbapCatalog.compiler.compareFilter:true

@AbapCatalog.preserveKey:true

@AccessControl.authorizationCheck:#CHECK

@EndUserText.label:'SALES ITEM with condition table'

@OData.publish:true

define view Z_VBAP_JOIN_PRCD_ELEMENTS as select from vbap

left outer join prcd_elements

on vbap.posnr = prcd_elements.kposn {

key vbap.posnr,

vbap.mwsbp as Total_Tax_Amount,//Total tax amount at line item level for billing document

vbap.fixmg as Delivery_Date_Sales_order,

prcd_elements.kposn,

prcd_elements.kbetr as Tax_Rate,// tax rate

prcd_elements.kschl,

prcd_elements.kawrt as Tax_Base_Amount,// tax base amount

prcd_elements.kwert as Tax_Amount,// tax amount

case

when prcd_elements.kschl='XR1' then 'state tax rate'

when prcd_elements.kschl='XR2' then 'county tax rate'

when prcd_elements.kschl='XR3' then 'city tax rate'

when prcd_elements.kschl='XR4'then'tax level 4 jurisdiction'

else'which tax jurisdiction?'

end as taxjurisdiction

}

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Best Answer
    Dec 15, 2018 at 08:51 PM

    Hi Amruth,

    the problem is in your DDL source Code since the entries are not unique using the key that you have defined.

    If you press F8 in ABAP in Eclipse to view the content of your CDS view you will see multiple entries having the same key field vbap.posnr.

    You have to add the remaining key field of table VBAP (vbeln) and all key fields of prcd_elements that are part of the structure

    prcs_elements_key

    as shown in the changed DDL source code below.

    The field kposn was already part of your data definition but not marked as a key field so I have commented it out at the original position.

    As a result the following request will work

    /sap/opu/odata/sap/Z_VBAP_JOIN_PRCD_ELEMENTS_CDS/Z_VBAP_JOIN_PRCD_ELEMENTS(vbeln='2',posnr='000010',knumv='0000000002',kposn='000010',stunr='020',zaehk='001')?$format=json<br>

    with the new key fields highlighted in red.

    Fortunately, I had an instance of the SAP S/4HANA 1809 fully activated appliance at hand that is provided by the team of my colleague Joerg Wolf to test my code.

    Best Regards,

    Andre

    @AbapCatalog.sqlViewName:'Z_VBAP_PRCD_ELEM'
    @AbapCatalog.compiler.compareFilter:true
    @AbapCatalog.preserveKey:true
    @AccessControl.authorizationCheck:#CHECK
    @EndUserText.label:'SALES ITEM with condition table'
    @OData.publish:true
    define view Z_VBAP_JOIN_PRCD_ELEMENTS as select from vbap
    left outer join prcd_elements
    on vbap.posnr = prcd_elements.kposn {
    key vbap.vbeln,
    key vbap.posnr,
    key prcd_elements.knumv,
    key prcd_elements.kposn,
    key prcd_elements.stunr,
    key prcd_elements.zaehk,
    vbap.mwsbp as Total_Tax_Amount,//Total tax amount at line item level for billing document
    vbap.fixmg as Delivery_Date_Sales_order,
    //prcd_elements.kposn,
    prcd_elements.kbetr as Tax_Rate,// tax rate
    prcd_elements.kschl,
    prcd_elements.kawrt as Tax_Base_Amount,// tax base amount
    prcd_elements.kwert as Tax_Amount,// tax amount
    case
    when prcd_elements.kschl='XR1' then 'state tax rate'
    when prcd_elements.kschl='XR2' then 'county tax rate'
    when prcd_elements.kschl='XR3' then 'city tax rate'
    when prcd_elements.kschl='XR4'then'tax level 4 jurisdiction'
    else'which tax jurisdiction?'
    end as taxjurisdiction 
    }
    
    

    When Performing a GET request on the entity set (with a $top=2 ;-)) you will see that the Elements have the same key field posnr but the whole key is different.


    Add comment
    10|10000 characters needed characters exceeded