|
Purpose With a simple test in a development or sandbox system you can find out whether a particular SAP OData service returns before or after the SAP update task has written the data. The test needs no knowledge of the service's ABAP code and works for any service. BackgroundMost SAP applications do not write their changes to the database directly. They register update function modules and trigger them with COMMIT WORK. An update work process then executes these modules asynchronously. There are three variants that matter for the caller:
Low-priority (V2) update modules, for example statistics updates, always run later, even with COMMIT WORK AND WAIT. For an application that calls OData.Update, this decides whether a read immediately afterwards returns the changed data. SAP generally does not document which variant a service uses, and different parts of one business process can behave differently. See the OData.Update documentation for the general recommendations. Why SM14 is not suitable for the testAn obvious idea is to deactivate updating in transaction SM14 and see whether the OData request returns. This does not work. While updating is deactivated, the SAP system suspends every program that tries to create an update request, so the request waits in any case. You can see this with transaction VA02: saving a sales order also hangs until updating is reactivated. The test therefore cannot distinguish COMMIT WORK from COMMIT WORK AND WAIT. It can even suggest that a service waits for the update when the data has in fact already been written (see the example below). Test setup: blocking the update work processesInstead of stopping updates, you keep all update work processes busy for a defined time. New update requests can still be created, but they wait for a free update process. A service that uses COMMIT WORK returns immediately, while a service that uses COMMIT WORK AND WAIT hangs until the blockade ends. You need two small objects. First, an update function module that keeps its work process busy for a given number of seconds. A WAIT UP TO statement is not suitable here: in our test the work process was not blocked during the wait. The module therefore uses a loop that checks the elapsed time. The loop uses CPU, which is acceptable in a test system for a short time. Create it in SE37 with processing type "Update module" and "Start immediately" (V1). Import parameters of update modules must be passed by value.
Second, a report that calls this module once per update work process, each time in its own LUW:
Set p_procs to the number of UPD work processes shown in SM50. A higher value does no harm: the additional requests are queued and simply extend the blockade. In a system with several application servers, update requests can be dispatched to other servers. In this case you have to block the update work processes of all servers. Control checksBefore you test an OData service, make sure that the blockade works as intended. Otherwise a result such as "the service returns immediately" has no meaning.
Running the test and evaluating the resultsStart the blocker report, call the OData service from your application during the blocking time, and note whether the call returns immediately. Then read the changed object again. While the blockade is still active, check the following:
Example: changing a sales orderIn our S/4HANA test system, the same sales order change behaves differently in VA02 and in the OData sales order API. The update work processes were blocked for 60 seconds in both tests.
VA02 writes the sales order through the asynchronous update task. The OData service writes the order within the request itself. The only update request it creates belongs to Predictive Accounting, which creates predictive journal entries for sales orders. This V1 update runs asynchronously, and the OData service does not wait for it. This also explains the misleading SM14 result: the OData request hangs because it cannot create the Predictive Accounting update request. The sales order data is already saved at this point. In a system without active Predictive Accounting, this update request would not exist at all. ConclusionsThe result of the test applies only to the tested service, release and system configuration. The example shows two reasons for this: the same business object is written differently depending on the access path, and additional processes such as Predictive Accounting depend on customizing. For applications that use OData.Update, this means:
|