Search code examples
javasap-cloud-platformsap-cloud-sdk

How to use SDK update Planned Independent Requirement in Java


I want to update PIRs (planned independent requirements) in SAP S/4Hana Cloud. I am using Java SDK. I am using the class DefaultExtendedPlannedIndependentRequirementService.

        PlannedIndepRqmtItem pirItem = null;

        try {

            pirItem.setPlannedQuantity(utilities.convertToBigDecimal(anaplanLine.getForecastQuantity()));

            new DefaultExtendedPlannedIndependentRequirementService()
                    .updatePlannedIndepRqmtItem(pirItem)
                    .execute();

I use PlannedIndepRqmtItem to populate fields to be updated, as shown above.

My question is how do I set conditional fields (where fields)?

The fields of the where clauses are: product, plant, MRP area, PIR type, PIR version, PIR period and period type.

BR, Pietro


Solution

  • OData does not allow the use of a "where clause" in an update request.

    To update an item you first have to request the particular item (GET request), modify it and then pass it to the dedicated update method of the service class.

    In case you want to update multiple items at the same time you can perform a batch request via DefaultExtendedPlannedIndependentRequirementServiceBatch. However, this also requires explicitly passing all objects that are to be updated, there is "where clause" available there.

    In case you want to perform an update similar to the SQL way, so update all items which match a certain condition, you would fetch only the items that meet the criteria to be updated, modify them and then update them through a batch request. So essentially the "where clause" of a SQL update will be represented through the filters of the getAll() method.