## 4.2.15.15.1  Development in Classic ABAP
The starting point is the class CL\_SWF\_CPWF\_API\_FACTORY\_A4C . Once you have the API object of interface IF\_SWF\_CPWF\_API , see the ABAP documentation on supported actions.
## Starting SAP Build Process Automation process instances
Instances can be created with the following snippet:
```
 Sample Code Start a SAP Cloud Platform Workflow TYPES: BEGIN OF ty_context, some_property TYPE string, END OF ty_context. DATA(lo_cpwf_api) = cl_swf_cpwf_api_factory_a4c...=>get_api_instance( ... ). DATA(ls_context) = VALUE ty_context( some_property = 'someValue' ). DATA(lv_context_json) = lo_cpwf_api->get_start_context_from_data( iv_data = ls_context ). DATA(lv_cpwf_handle) = lo_cpwf_api->start_workflow( iv_cp_workflow_def_id = '<SAP Workflow Service Process Definition Identifier>' iv_context            = lv_context_json iv_retention_time     = 30 iv_callback_class     = '<Callback class for final state handling>' ).
```
## Registering SAP Build Process Automation process instances
If there is a running process instance in SAP Build Process automation which you would like to handle from within your S/4 Hana Application, you can register the instance in the following way:
```
 Sample Code Register a SAP Cloud Platform Workflow " Get a Instance for the CPWF Integration API DATA(lo_cpwf_api) = cl_swf_cpwf_api_factory_a4c...=>get_api_instance( ... ). DATA(lv_cpwf_handle) = lo_cpwf_api->register_workflow( iv_cp_workflow_inst_id = '<SAP Workflow Service Instance Identifier>' iv_retention_time     = 30 iv_callback_class     = '<Callback class for final state handling>' ). COMMIT WORK.
```
## Handling the result of SAP Build Process Automation process instances
As shown in the above snippets, a callback class can be provided that allows processing the result of the process. For example, it is possible to read the context of the completed instance.
```
 Sample Code Completion callback with reading context METHOD if_swf_cpwf_callback~workflow_instance_completed. TYPES: BEGIN OF ty_context, some_result TYPE string, END OF ty_context. TRY. DATA(lo_cpwf_api) = cl_swf_cpwf_api_factory_a4c...=>get_api_instance( ... ). data(lv_context_json) = lo_cpwf_api->get_workflow_context( iv_cpwf_handle = iv_cpwf_handle ). DATA ls_context TYPE ty_context. lo_cpwf_api->get_context_data_from_json( EXPORTING iv_context = lv_context_json IMPORTING ev_data = ls_context ). CATCH cx_swf_cpwf_api INTO DATA(lx_exc). " Exception handling ENDTRY. " your business coding ENDMETHOD.
```
## Raising an intermediate message event for a SAP Build Process Automation process instance
If the process expects a intermediate message event (IME), this can be raised via the following code.
```
 Sample Code Raise an intermediate message event (deprecated) TYPES: BEGIN OF ty_example_context, value TYPE int4, END OF ty_example_context. " Get a Instance for the CPWF Integration API DATA(lo_cpwf_api) = cl_swf_cpwf_api_factory_a4c...=>get_api_instance( ... ). " provide relevant event context data => in this case a meaningful integer DATA(lv_event_context_data) = VALUE ty_example_context( value = 4711 ). DATA(lv_event_context) = lo_cpwf_api->get_context_from_data( iv_data = lv_event_context_data ). " actually raise the event lo_cpwf_api->raise_event( EXPORTING iv_cpwf_handle   = lv_cpwf_handle iv_event_def_id  = '<Event Definition Identifier>' iv_event_context = lv_event_context ). COMMIT WORK.
```
This approach works only for old workflow management process definitions being deployed from SAP Business Application Studio.
For SAP Build Process Automation processes, you nee to trigger a intermediate message event by executing the corresponding API trigger, which can be done through the API as follows (from SAP\_CLOUD 2511 / OP 2027 onwards).
##  Sample Code
Raise an intermediate message event
```
CONSTANTS: lc_cp_workflow_def_id TYPE if_swf_cpwf_api=>cpwf_def_id      VALUE '<Your Workflow Definition ID>', lc_api_trigger_uid    TYPE if_swf_cpwf_api=>cpwf_trigger_uid VALUE '<Your API Trigger UID>'. " Get a Instance for the CPWF Integration API DATA(lo_cpwf_api) = cl_swf_cpwf_api_factory...=>get_api_instance( ... ). " actually raise the event lo_cpwf_api->api_trigger( EXPORTING iv_cpwf_handle   = lv_cpwf_handle  " the BTP process instance handle iv_event_def_id  = lc_api_trigger_uid ). COMMIT WORK.
```
Open your process in the SAP Build Process Automation Control Tower and check the list of triggers. View the trigger details to find the API trigger UID.
## Retrieving the current state of SAP Build Process Automation process instances
It is also possible to synchronously retrieve data about the processes. It can be accessed via the interface IF\_SWF\_CPWF\_API , which extends the core API IF\_SWF\_CPWF\_CAPI.
For example, you can query the current lifecycle status of processes.
```
 Sample Code Read Workflow Instances " Get a Instance for the CPWF Integration API DATA(lo_cpwf_api) = cl_swf_cpwf_api_factory...=>get_api_instance( ... ). DATA(lo_wf_inst) = lo_cpwf_api->if_swf_cpwf_capi~get_workflow_instances_api( ). DATA(lt_workflow_instance) = lo_wf_inst->query_instances( iv_definition_id = '<SAP Workflow Service Process Definition Identifier>' iv_status = if_swf_cpwf_capi_wf_insts=>cs_status-running ).
```
Or retrieve the current context:
##  Sample Code Read Workflow Instance Context TYPES: BEGIN OF ty\_context, attr1 TYPE string, attr2 TYPE int4, attr3 TYPE string, END OF ty\_context. " Get a Instance for the CPWF Integration API DATA(lo\_cpwf\_api) = cl\_swf\_cpwf\_api\_factory...=&gt;get\_api\_instance( ... ). DATA(lo\_cp\_json) = lo\_cpwf\_api-&gt;get\_json\_converter( ). DATA(lo\_wf\_inst\_ctxt) = lo\_cpwf\_api-&gt;if\_swf\_cpwf\_capi~get\_wf\_instance\_context\_api( ). DATA ls\_context TYPE ty\_context. lo\_wf\_inst\_ctxt-&gt;get\_instance\_context( EXPORTING iv\_cpwf\_handle = &lt;cpwf\_handle&gt; io\_cp\_json = lo\_cp\_json IMPORTING data = ls\_context ).
As shown in the code there is also a JSON converter available to simplify the processing of the context.
## Restricting the retrieved process context
To allow retrieving only relevant parts of the process context the APIs IF\_SWF\_CPWF\_API
→ get\_workflow\_context and IF\_SWF\_CPWF\_CAPI\_WF\_INST\_CTXT -&gt;get\_instance\_context allow to provide an additional parameter IV\_CONTEXT\_PATH , that accepts any JSON path expression (see SBPA API description). This expression is forwarded to the Workflow API of SAP Build Process Automation. The JSON path expression is evaluated by the SAP Build Process Automation Workflow Service API, which returns then only the corresponding substructure of the context.
The following examples show how the IV\_CONTEXT\_PATH parameter can be used.
##  Sample Code Sample Context { "decision\_travelRequestApproved\_2": { "outcome": "APPROVED" }, "startEvent": { "travelid": "1", "createdby": "UserX", "createdbymail": "userx@sap.com", "enddate": "2025-02-28", "startdate": "2025-02-01", "destination": "Far Far Away" }, "action\_post\_ProcessCompleted\_2": { "result": { "notificationProcessed": true } }, "custom": { "approver": "userx@sap.com", "outcome": "APPROVED", "destinations": [ { "date": "2025-02-01", "location": "here" }, { "date": "2025-02-12", "location": "there" } ] }, "decision\_determineRecipient\_1": { "Approver": "userx@sap.com" }, "form\_approveTravelRequest\_1": { "travelID": 1, "requestor": "UserX", "description\_1": "Far Far Away", "startDate": "2025-02-01", "endDate": "2025-02-28" } }
```
 Sample Code Get Context with JSONPath "custom" { "approver": "userx@sap.com", "outcome": "APPROVED" "destinations": [ { "date": "2025-02-01", "location": "here" }, { "date": "2025-02-12", "location": "there" } ]
```
}
##  Sample Code Get Context with JSONPath "custom.outcome" "APPROVED"
```
 Sample Code Get Context with JSONPath "custom.outcome.destinations[1]" { "date": "2025-02-12", "location": "there" }
```
##  Sample Code
Get Context with JSONPath "custom.outcome.destinations[1].location"
"here"