Some BAPI remote functions commit database changes, but some don’t have a commit implemented in their code. By default, OutSystems Platform creates a new transaction for each SAP remote function call, and commits changes before closing it.

However, there are situations where you need to make several calls to SAP remote functions in the same transaction.

To achieve this, you need an extension module to manage stateful calls in SAP:

  1. Create an extension module using SAP Extensibility API to handle stateful calls in SAP;
  2. In your application, add dependencies to actions of the extension;
  3. Implement logic to execute SAP stateful calls in your application.


You want to lock the record of a patient before updating it, to avoid that others modify it at the same time. After the record is updated, you want to remove the lock from the record.

Create the Extension Module for SAP

In the Forge, you can find component 'SAP Utilities'. It's a sample with an extension module for SAP, with actions for handling stateful calls. Get it here.

Because this extension makes use of the SAP Extensibility API, make sure you fill the requirements described in here.

Publish the extension.

Add Dependencies to Actions of the Extension

To implement stateful calls in your application, add dependencies to the following actions in the extension:

Learn more about how to add dependencies.

Implement Logic to Execute Stateful Calls

Use SAP remote functions together with actions from the extension to implement a stateful call.

First, consume the following remote functions from SAP:

  • BAPI_PATIENT_ENQUEUE: locks a Patient record;
  • BAPI_PATIENT_CHANGE: updates a Patient record;
  • BAPI_PATIENT_DEQUEUE: removes the lock from a Patient record.

See how to consume SAP remote functions.

Implement stateful call in an action with the following flow (see picture):

  1. BeginContext: starts a stateful connection in SAP;
  2. Bapi_Patient_Enqueue: locks the patient record in SAP;
  3. Bapi_Patient_Change: updates the patient in SAP;
  4. Bapi_Patient_Dequeue: unlocks the patient record in SAP;
  5. Commit: commits changes inside a stateful connection in SAP;
  6. EndContext: ends the stateful connection in SAP.

In the flow to handle exceptions (see picture):

  1. Rollback: rolls back changes inside a stateful connection in SAP;
  2. EndContext: ends the stateful connection in SAP.



See Also

SAP Remote Function | SAP Extensibility API