如何使用Java Cloud SDK将销售订单发送到S/4 HANA Cloud

2020-09-01 08:58发布

点击此处---> 群内免费提供SAP练习系统(在群公告中)加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)大家好,我正在尝试进行销售订单模...

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


大家好,我正在尝试进行销售订单模拟,以获取工序的价格。 当我直接使用REST调用(使用Postman)调用S/4系统时,它实际上显示了结果:
 {
 " SalesOrderType":" OR",
 " SalesOrganization":" 2410",
 " DistributionChannel":" 10",
 " OrganizationDivision":" 00",
 " SoldToParty":" 24100003",
 " PurchaseOrderByCustomer":" SalesOrder Simulation",
 " to_Pricing":{},
 " to_PricingElement":[],
 " to_Item":[
 {" SalesOrderItem":" 10",
 " Material":" SOMEMATERIAL",
 " RequestedQuantity":" 1"
 }]
 }
 
但是使用我的代码,实例化那些空的定价元素不会给我提供任何定价信息:
/*新销售订单*/

 SalesOrderSimulation oSimulationInput = new SalesOrderSimulation();
 oSimulationInput.setSalesOrganization(" 2410");
 oSimulationInput.setSalesOrderType(" O");
 oSimulationInput.setDistributionChannel(" 10");
 oSimulationInput.setOrganizationDivision(" 00");
 oSimulationInput.setSoldToParty(" 24100003");
 oSimulationInput.setPurchaseOrderByCustomer(" 2000000");
 oSimulationInput.setPricingElement(new ArrayList ());
 SalesOrderPricingSimulation orderPricing = new SalesOrderPricingSimulation();

 oSimulationInput.setPricing(orderPricing);

/* 新增项目 */
 SalesOrderItemSimulation oItem = new SalesOrderItemSimulation();
 oItem.setSalesOrderItem(" 10");
 oItem.setMaterial(" SOMEMATERIAL");
 BigDecimalRequestedQuantity = new BigDecimal(" 1");
 oItem.setRequestedQuantity(requestedQuantity);

 oSimulationInput.addItem(oItem);

 SalesOrderSimulation oSimulation = oService._mSimulate(oSimulationInput); 
我要监督什么? 是序列化的问题吗? 我正在为项目使用Springboot 1.41。

谢谢您的时间!

2条回答
一只江湖小虾
2020-09-01 09:54

嗨Germán,

我没有S/4HANA系统来测试以下代码。 因此,您可以对其进行测试,看看它是否对您有用:

 @WebServlet("/img/sosimulation")
 公共类SalesOrderSimulationServlet扩展了HttpServlet {

     私有静态最终长serialVersionUID = 1L;
     私有静态最终Logger logger = LoggerFactory.getLogger(SalesOrderSimulationServlet.class);

     私有最终ErpHttpDestination目标= DestinationAccessor.getDestination(" MyErpSystem")。asHttp()。decorate(DefaultErpHttpDestination :: new);
     私有静态最终字符串_SERVICE_PATH =" sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderSimulation";

     @Override
     受保护的void doGet(最终HttpServletRequest请求,最终HttpServletResponse响应)
             引发ServletException,IOException {
         尝试{
         SalesOrderItemSimulation soItemSimulation = SalesOrderItemSimulation.builder()
         .salesOrderItem(" 10")
         .material(" SOMEMATERIAL")
         .requestedQuantity(new BigDecimal(" 1"))
         。建立();

 SalesOrderSimulation sosimulation = SalesOrderSimulation.builder()
         .salesOrganization(" 2410")
         .salesOrderType(" O")
         .distributionChannel(" 10")
         .organizationDivision(" 00")
         .soldToParty(" 24100003")
         .purchaseOrderByCustomer(" 2000000")
         .pricingElement(新的SalesOrderPrcgElmntSimln())
         .pricing(new SalesOrderPricingSimulation())
         .item(soItemSimulation)
         。建立();

 SalesOrderSimulationCreateFluentHelper soSimulationHelper = new SalesOrderSimulationCreateFluentHelper(_SERVICE_PATH,sosimulation);
 final SalesOrderSimulation fetchedSoSimulation = soSimulationHelper.execute(destination);

             response.setContentType(" application/json");
             response.getWriter()。write(new Gson()。toJson(fetchedSoSimulation));
         } catch(final ODataException e){
             logger.error(e.getMessage(),e);
             response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
             response.getWriter()。write(e.getMessage());
         }
     }
 }
 

最好的问候,
伊万

一周热门 更多>