首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用S/4 Hana Cloud对API_PRODUCT_SRV标准WhiteListed API执行深度插入操作

问无法使用S/4 Hana Cloud对API_PRODUCT_SRV标准WhiteListed API执行深度插入操作
EN

Stack Overflow用户
提问于 2019-03-08 04:29:12
回答 2查看 1K关注 0票数 1

我已经完成了对API_PRODUCT_SRV服务的读取和更新操作。

现在,在对API_PRODUCT_SRV (Product它有许多关联)进行深度插入时,我得到了以下错误。

代码语言:javascript
复制
“errordetails”: [

{
“code”: “API_PRD_MSG/004”,
“message”: “Provide atleast one description for the product.”,
“propertyref”: “”,
“severity”: “error”,
“target”: “”
}
]

我发现了一个深潜博客

https://blogs.sap.com/2017/12/07/step-20-with-s4hana-cloud-sdk-create-and-deep-insert-with-the-virtual-data-model-for-odata/comment-page-1/#comment-453020

它解释了使用servlet进行深度插入(即使用HttpServletReq),后者提供rest服务。

但是我使用的是来自模型的CreateRequest类,它生成odata服务,所以我不能使用博客中提供的类似代码。

我已经添加了代码和有效载荷供您阅读。

创建操作代码

代码语言:javascript
复制
@Create(serviceName = "ProductService", entity = "Products")
    public CreateResponse create(CreateRequest req) throws ODataException {
        Product toCreate = new ModelMapper().map(req.getMapData(), Product.class);          
        Product created = new DefaultProductMasterService().createProduct(toCreate)
                .execute(new ErpConfigContext("K4XS4SDKDest"));
        return CreateResponse.setSuccess().setData(created).response();
    }

使用的有效载荷:

代码语言:javascript
复制
{
  "Product" : "BALL",
    "ProductType" : "ZHLB",
    "CrossPlantStatus" : "",
    "CrossPlantStatusValidityDate" : null,
    "CreationDate" : "\/Date(1499731200000)\/",
    "CreatedByUser" : "11279380",
    "LastChangeDate" : "\/Date(1550448000000)\/",
    "LastChangedByUser" : "HWV87616",
    "IsMarkedForDeletion" : false,
    "ProductOldID" : "",
    "GrossWeight" : "0.000",
    "PurchaseOrderQuantityUnit" : "",
    "SourceOfSupply" : "",
    "WeightUnit" : "KG",
    "NetWeight" : "0.000",
    "CountryOfOrigin" : "",
    "CompetitorID" : "",
    "ProductGroup" : "01",
    "BaseUnit" : "EA",
    "ItemCategoryGroup" : "",
    "ProductHierarchy" : "",
    "Division" : "",
    "VarblPurOrdUnitIsActive" : "",
    "VolumeUnit" : "",
    "MaterialVolume" : "0.000",
    "ANPCode" : "0",
    "Brand" : "",
    "ProcurementRule" : "",
    "ValidityStartDate" : null,
    "LowLevelCode" : "",
    "ProdNoInGenProdInPrepackProd" : "",
    "SerialIdentifierAssgmtProfile" : "",
    "SizeOrDimensionText" : "",
    "IndustryStandardName" : "",
    "ProductStandardID" : "",
    "InternationalArticleNumberCat" : "",
    "ProductIsConfigurable" : false,
    "IsBatchManagementRequired" : false,
    "ExternalProductGroup" : "",
    "CrossPlantConfigurableProduct" : "",
    "SerialNoExplicitnessLevel" : "",   
    "ManufacturerPartProfile" : "",
    "ChangeNumber" : "",
    "MaterialRevisionLevel" : "",
    "HandlingIndicator" : "",
    "WarehouseProductGroup" : "",
    "WarehouseStorageCondition" : "",
    "StandardHandlingUnitType" : "",
    "SerialNumberProfile" : "",
    "AdjustmentProfile" : "",
    "PreferredUnitOfMeasure" : "",
    "IsPilferable" : false,
    "IsRelevantForHzdsSubstances" : false,
    "QuarantinePeriod" : "0",
    "TimeUnitForQuarantinePeriod" : "",
    "QualityInspectionGroup" : "",
    "AuthorizationGroup" : "",
    "HandlingUnitType" : "",
    "HasVariableTareWeight" : false,
    "MaximumPackagingLength" : "0.000",
    "MaximumPackagingWidth" : "0.000",
    "MaximumPackagingHeight" : "0.000",
  "to_Description": {
    "results": [
     {
        "Product" : "BALL",
        "Language" : "EN",
        "ProductDescription" : "Pipes for machines"
      }
    ]
  }
}

请帮助我如何修改我的代码,以便在使用SAP应用程序编程模型(CreateRequest类)时,使用SAP /4HANACloudSDK进行深度插入?

日志文件:

代码语言:javascript
复制
Product(super=VdmObject(customFields={}, changedOriginalFields={LowLevelCode=null, ProductGroup=null, SizeOrDimensionText=null, CreatedByUser=null, CountryOfOrigin=null, Product=null, ProductStandardID=null, IsPilferable=null, VolumeUnit=null, WarehouseProductGroup=null, WarehouseStorageCondition=null, MaterialVolume=null, ManufacturerPartProfile=null, CrossPlantStatus=null, TimeUnitForQuarantinePeriod=null, GrossWeight=null, InternationalArticleNumberCat=null, SourceOfSupply=null, ProductType=null, ItemCategoryGroup=null, ProcurementRule=null, BaseUnit=null, ProductOldID=null, VarblPurOrdUnitIsActive=null, LastChangedByUser=null, Brand=null, MaximumPackagingWidth=null, QuarantinePeriod=null, PurchaseOrderQuantityUnit=null, ProductHierarchy=null, AuthorizationGroup=null, StandardHandlingUnitType=null, MaterialRevisionLevel=null, ExternalProductGroup=null, CrossPlantConfigurableProduct=null, MaximumPackagingLength=null, HasVariableTareWeight=null, ANPCode=null, ProdNoInGenProdInPrepackProd=null, WeightUnit=null, IsMarkedForDeletion=null, CompetitorID=null, QualityInspectionGroup=null, IsBatchManagementRequired=null, IsRelevantForHzdsSubstances=null, Division=null, SerialIdentifierAssgmtProfile=null, AdjustmentProfile=null, PreferredUnitOfMeasure=null, SerialNoExplicitnessLevel=null, HandlingIndicator=null, HandlingUnitType=null, NetWeight=null, ProductIsConfigurable=null, IndustryStandardName=null, SerialNumberProfile=null, ChangeNumber=null, MaximumPackagingHeight=null}), product=BELL, productType=ZHLB, crossPlantStatus=, crossPlantStatusValidityDate=null, creationDate=null, createdByUser=11279380, lastChangeDate=null, lastChangedByUser=HWV87616, lastChangeDateTime=null, isMarkedForDeletion=false, productOldID=, grossWeight=0.000, purchaseOrderQuantityUnit=, sourceOfSupply=, weightUnit=KG, netWeight=0.000, countryOfOrigin=, competitorID=, productGroup=01, baseUnit=EA, itemCategoryGroup=, productHierarchy=, division=, varblPurOrdUnitIsActive=, volumeUnit=, materialVolume=0.000, aNPCode=0, brand=, procurementRule=, validityStartDate=null, lowLevelCode=, prodNoInGenProdInPrepackProd=, serialIdentifierAssgmtProfile=, sizeOrDimensionText=, industryStandardName=, productStandardID=, internationalArticleNumberCat=, productIsConfigurable=false, isBatchManagementRequired=false, externalProductGroup=, crossPlantConfigurableProduct=, serialNoExplicitnessLevel=, productManufacturerNumber=null, manufacturerNumber=null, manufacturerPartProfile=, changeNumber=, materialRevisionLevel=, handlingIndicator=, warehouseProductGroup=, warehouseStorageCondition=, standardHandlingUnitType=, serialNumberProfile=, adjustmentProfile=, preferredUnitOfMeasure=, isPilferable=false, isRelevantForHzdsSubstances=false, quarantinePeriod=0, timeUnitForQuarantinePeriod=, qualityInspectionGroup=, authorizationGroup=, handlingUnitType=, hasVariableTareWeight=false, maximumPackagingLength=0.000, maximumPackagingWidth=0.000, maximumPackagingHeight=0.000, erpConfigContext=null, toDescription=null, toPlant=null, toProductBasicText=null, toProductInspectionText=null, toProductProcurement=null, toProductPurchaseText=null, toProductQualityMgmt=null, toProductSales=null, toProductSalesTax=null, toProductStorage=null, toProductUnitsOfMeasure=null, toSalesDelivery=null)
{ "written_at":"2019-03-11T03:56:27.923Z","written_ts":918343802814688,"component_id":"e8c99eff-1a4e-4266-ba2a-fc099399100c","component_name":"FNpy7mXtvln0dnT1-FinalTestApp-srv","DCComponent":"","organization_name":"-","component_type":"application","space_name":"dev","component_instance":"0","organization_id":"-","correlation_id":"-","CSNComponent":"","space_id":"a78252bf-72bf-479c-b761-8260de0c776e","Application":"FNpy7mXtvln0dnT1-FinalTestApp-srv","container_id":"10.0.138.113","type":"log","logger":"com.sap.cloud.sdk.service.prov.api.util.ProcessorHelper","thread":"http-nio-0.0.0.0-3000-exec-7","level":"ERROR","categories":[],"msg":"The endpoint responded with HTTP error code 400.\nProvide atleast one description for the product.\nFull error message: \n{\n  \"error\": {\n    \"code\": \"API_PRD_MSG/004\",\n    \"message\": {\n      \"lang\": \"en\",\n      \"value\": \"Provide atleast one description for the product.\"\n    },\n    \"innererror\": {\n      \"application\": {\n        \"component_id\": \"LO-MD-MM\",\n        \"service_namespace\": \"/SAP/\",\n        \"service_id\": \"API_PRODUCT_SRV\",\n        \"service_version\": \"0001\"\n      },\n      \"transactionid\": \"C16DD240C7520010E005C7E648BC12F5\",\n      \"timestamp\": \"20190311035627.5989630\",\n      \"Error_Resolution\": {\n        \"SAP_Transaction\": \"For backend administrators: run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more details\",\n        \"SAP_Note\": \"See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)\"\n      },\n      \"errordetails\": [\n        {\n          \"code\": \"API_PRD_MSG/004\",\n          \"message\": \"Provide atleast one description for the product.\",\n          \"propertyref\": \"\",\n          \"severity\": \"error\",\n          \"target\": \"\"\n        }\n      ]\n    }\n  }\n}","stacktrace":["java.lang.reflect.InvocationTargetException","\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)","\tat 

my-service.cds

代码语言:javascript
复制
    using API_PRODUCT_SRV  from '../srv/external/csn/API_PRODUCT_SRV.json';
    service ProductService {

      entity Products as Projection on API_PRODUCT_SRV.A_ProductType {
       key Product,
       ProductType,
       CreationDate,
       CrossPlantStatus,
       CrossPlantStatusValidityDate,
        CreatedByUser,
        LastChangeDate,
        LastChangedByUser,
        IsMarkedForDeletion,
        ProductOldID,
        GrossWeight,
        PurchaseOrderQuantityUnit,
        SourceOfSupply,
        WeightUnit,
        NetWeight,
        CountryOfOrigin,
        CompetitorID,
        ProductGroup,
        BaseUnit,
        ItemCategoryGroup,
        ProductHierarchy,
        Division,
        VarblPurOrdUnitIsActive,
        VolumeUnit,
        MaterialVolume,
        ANPCode,
        Brand,
        ProcurementRule,
        ValidityStartDate,
        LowLevelCode,
        ProdNoInGenProdInPrepackProd,
        SerialIdentifierAssgmtProfile,
        SizeOrDimensionText,
        IndustryStandardName,
        ProductStandardID,
        InternationalArticleNumberCat,
        ProductIsConfigurable,
        IsBatchManagementRequired,
        ExternalProductGroup,
        CrossPlantConfigurableProduct,
        SerialNoExplicitnessLevel,
        ProductManufacturerNumber,
        ManufacturerPartProfile,
        ChangeNumber,
        MaterialRevisionLevel,
        HandlingIndicator,
        WarehouseProductGroup,
        WarehouseStorageCondition,
        StandardHandlingUnitType,
        SerialNumberProfile,
        AdjustmentProfile,
        PreferredUnitOfMeasure,
       IsPilferable,
        IsRelevantForHzdsSubstances,
        QuarantinePeriod,
        TimeUnitForQuarantinePeriod,
        QualityInspectionGroup,
        AuthorizationGroup,
        HandlingUnitType,
        HasVariableTareWeight,
        MaximumPackagingLength,
        MaximumPackagingWidth,
        MaximumPackagingHeight,
      to_Description
      }
 entity A_ProductDescriptionType as Projection on API_PRODUCT_SRV.A_ProductDescriptionType
  {
              key  Product,
             key   Language,
                ProductDescription
}
}

请告诉我如何在其中添加关联吗?my-service.cds?

代码语言:javascript
复制
using API_BUSINESS_PARTNER as bp from './external/csn/API_BUSINESS_PARTNER';

service CrudService{

 @cds.persistence.skip
 Entity BusinessPartner as projection on bp.A_BusinessPartnerType{
   BusinessPartner,
   LastName,
   FirstName,
   BusinessPartnerCategory
  };
}

热烈的问候,

美娜克什

EN

回答 2

Stack Overflow用户

发布于 2019-03-19 04:03:30

如果可能的话,你能分享你的整个项目吗?请求映射可能不包含产品描述数据,因为我猜CDS文件中没有正确定义产品和描述之间的关联。

请查阅下列文件以确定您的实体和协会:

https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/855e00bd559742a3b8276fbed4af1008.html

我有兴趣知道您的服务当前的$metadata响应是什么。此外,我希望看到您的自定义处理程序代码,以及您如何尝试从请求对象检索深度插入有效负载。

谢谢你,克兰蒂

票数 1
EN

Stack Overflow用户

发布于 2019-05-27 08:50:54

问题是您的JSON 请求有效负载:

代码语言:javascript
复制
{
  "Product" : "BALL",
  ...
  "to_Description": {
    "results": [
     {
        "Product" : "BALL",
        "Language" : "EN",
        "ProductDescription" : "Pipes for machines"
      }
    ]
  }
}

to_Description不应该是对象。相反,它应该是一个数组

代码语言:javascript
复制
{
  "Product" : "BALL",
  ...
  "to_Description": [
     {
        "Product" : "BALL",
        "Language" : "EN",
        "ProductDescription" : "Pipes for machines"
     }
  ]
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55056740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档