cancel
Showing results for 
Search instead for 
Did you mean: 

How to send to S/4 HANA Cloud a sales order simulate with the Java Cloud SDK

former_member570896
Participant
0 Kudos
Hi guys, I'm trying to make a sales order simulation to get the pricing of the operation. When I call the S/4 system directly with the REST call (with Postman) it actually show results:
{
"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"
}]
}
But with my code, instantiating those empty pricing elements gives me no pricing information:
/* New Sales Orders */

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<SalesOrderPrcgElmntSimln>());
SalesOrderPricingSimulation orderPricing = new SalesOrderPricingSimulation();

oSimulationInput.setPricing(orderPricing);

/* Add Item */
SalesOrderItemSimulation oItem = new SalesOrderItemSimulation();
oItem.setSalesOrderItem("10");
oItem.setMaterial("SOMEMATERIAL");
BigDecimal requestedQuantity = new BigDecimal("1");
oItem.setRequestedQuantity(requestedQuantity);

oSimulationInput.addItem(oItem);

SalesOrderSimulation oSimulation = oService._mSimulate(oSimulationInput);
Is there something I am overseeing? Is the serialization the problem? I'm using Springboot 1.41 for the project.

Thank you for your time!

cschubert
Participant
0 Kudos

Where is the service your are using coming from? Wher would you expect which response? Using the SAP Cloud SDK you would usually have some kind of execute method which will actually send the request out.

You can set the logging output of the Apache Http libraries to debug by following the following guide: https://hc.apache.org/httpcomponents-client-4.5.x/logging.html With this output you can then better understand what the SDK actually sends. Please add the actual request send by your service.

Accepted Solutions (0)

Answers (1)

Answers (1)

Ivan-Mirisola
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Germán,

I don't have an S/4HANA system to test the following code. So, could you test it and see if it works for you:

@WebServlet("/sosimulation")
public class SalesOrderSimulationServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;
    private static final Logger logger = LoggerFactory.getLogger(SalesOrderSimulationServlet.class);

    private final ErpHttpDestination destination = DestinationAccessor.getDestination("MyErpSystem").asHttp().decorate(DefaultErpHttpDestination::new);
    private static final String _SERVICE_PATH = "sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderSimulation";

    @Override
    protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
            throws ServletException, IOException {
        try {
        	SalesOrderItemSimulation soItemSimulation = SalesOrderItemSimulation.builder()
        			.salesOrderItem("10")
        			.material("SOMEMATERIAL")
        			.requestedQuantity(new BigDecimal("1"))
        			.build();

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

			 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());
        }
    }
}

Best regards,
Ivan