Parallel Processing in ABAP Cloud Using CL_ABAP_PARALLEL and RAP EML

Parallel Processing in ABAP Cloud Using CL_ABAP_PARALLEL and RAP EML

SAP RAP

Modern SAP applications often need to execute time-consuming operations such as external service calls, heavy calculations, or mass data creation. Running such logic sequentially can slow down user interaction and block dialog processes. ABAP Cloud offers a clean and powerful way to distribute workload using parallel processing via the class CL_ABAP_PARALLEL.

In this blog, we will see:

  • What a parallel class is in ABAP Cloud

  • How to implement IF_ABAP_PARALLEL

  • How to execute RAP EML inside a parallel task

  • How to commit inside the task and return results

  • How this pattern can be reused in RAP actions, saver classes, or even BAPI scenarios


What is a Parallel Class?

A parallel class is a normal ABAP class that implements the interface IF_ABAP_PARALLEL.
This interface provides the method:

IF_ABAP_PARALLEL~DO

which represents the logic that will run in a separate work process. Each instance of this class becomes an independent task executed by the framework.

The advantages are:

  • Multiple tasks run concurrently

  • Main session is not blocked

  • Each task has its own transactional context

  • You can perform COMMIT inside the task


Business Scenario

We have a managed RAP application:

  • Billing Document Header

  • Billing Document Item

  • Task BO (separate RAP Business Object with managed implementation)

Requirement:

  1. Read a billing document item

  2. Get its Material ID

  3. Create a Task using RAP EML based on that Material

  4. Commit inside the parallel task

  5. Return the created Task UUID generated from managed Task app

  6. Update the billing item description with this UUID

All this should happen using parallel execution.


Step 1 – Create the Parallel Task Class

This class:

  • Receives Material ID in constructor

  • Implements IF_ABAP_PARALLEL

  • Creates Task using EML

  • Performs COMMIT ENTITIES inside the task

  • Returns the created UUID

Parallel Class Implementation

CLASS zsac_cl_parallel_task DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

    INTERFACES if_serializable_object .
    INTERFACES if_abap_parallel .

    METHODS: constructor IMPORTING iv_material TYPE string.

    METHODS get_result
      RETURNING VALUE(rt_result) TYPE string.

  PRIVATE SECTION.
    DATA: mv_material TYPE string.
    DATA mv_result  TYPE string.
ENDCLASS.
CLASS zsac_cl_parallel_task IMPLEMENTATION.

  METHOD constructor.
    mv_material = iv_material.
  ENDMETHOD.

  METHOD get_result.
    RETURN mv_result.
  ENDMETHOD.

  METHOD if_abap_parallel~do.

    DATA: lt_task_create TYPE TABLE FOR CREATE zsac_r_task_head\\ZsacRTaskHead,
          ls_task_create LIKE LINE OF lt_task_create,
          lt_reported    TYPE RESPONSE FOR REPORTED EARLY zsac_r_task_head,
          lt_mapped      TYPE RESPONSE FOR MAPPED EARLY zsac_r_task_head,
          lt_failed      TYPE RESPONSE FOR FAILED EARLY zsac_r_task_head.

    lt_task_create = VALUE #( (
        %cid           = 'MY_CID_1'
        TaskID         = | TASK- | && mv_material
        Title          = | New task for | && mv_material
        Description    = 'Test Description'
        OverallStatus  = 'O'
        %control       = VALUE #(
                           TaskID        = if_abap_behv=>mk-on
                           Title         = if_abap_behv=>mk-on
                           Description   = if_abap_behv=>mk-on
                           OverallStatus = if_abap_behv=>mk-on
                         )
    ) ).

    MODIFY ENTITIES OF zsac_r_task_head
      ENTITY ZsacRTaskHead
        CREATE FROM lt_task_create
      MAPPED   lt_mapped
      FAILED   lt_failed
      REPORTED lt_reported.

    IF lt_failed IS INITIAL.
      COMMIT ENTITIES.
      mv_result = lt_mapped-zsacrtaskhead[ 1 ]-taskuuid.
    ENDIF.

  ENDMETHOD.
ENDCLASS.

Key Points

  • EML is executed inside the parallel session

  • COMMIT ENTITIES is allowed here

  • Result is stored in instance attribute

  • get_result method exposes the value


Step 2 – Calling the Parallel Class

To keep the example simple, we call it from a local class implementing IF_OO_ADT_CLASSRUN.

Execution Flow

  1. Read billing item using EML

  2. Extract Material ID

  3. Create instance of parallel task

  4. Run using CL_ABAP_PARALLEL

  5. Collect result

  6. Update billing item description

CLASS zsac_cl_process IMPLEMENTATION.

  METHOD if_oo_adt_classrun~main.

    DATA: lt_processes TYPE cl_abap_parallel=>t_in_inst_tab.

    READ ENTITIES OF zsac_r_bill_headtp
        ENTITY zsac_r_bill_itemtp FIELDS ( MaterialId )
          WITH VALUE #( ( BillID = '1000000005' ItemNo = '000001' ) )
           RESULT DATA(lt_bill_items).

    DATA(lv_material) = lt_bill_items[ 1 ]-MaterialId.

    INSERT NEW zsac_cl_parallel_task( CONV #( lv_material ) )
      INTO TABLE lt_processes.

    NEW cl_abap_parallel( p_num_tasks = 3 )->run_inst(
        EXPORTING p_in_tab  = lt_processes
        IMPORTING p_out_tab = DATA(lt_finished)
    ).

    DATA(ls_finished) = lt_finished[ 1 ].
    DATA(lv_desc) = CAST zsac_cl_parallel_task(
                       ls_finished-inst )->get_result( ).

    MODIFY ENTITIES OF zsac_r_bill_headtp
      ENTITY zsac_r_bill_itemtp
      UPDATE FROM VALUE #(
        ( BillId               = '1000000005'
          ItemNo               = '000001'
          description          = lv_desc
          %control-description = if_abap_behv=>mk-on ) ).

    COMMIT ENTITIES.

  ENDMETHOD.
ENDCLASS.

Created Task

Description updated


Why This Pattern is Powerful

1. RAP Framework Restrictions

Inside RAP:

  • COMMIT WORK and COMMIT ENTITIES statements are forbidden

  • Long running logic blocks UI

With parallel class:

  • You get a separate LUW

  • You can commit safely

  • RAP transactional buffer remains clean

2. Where Can We Use This?

This concept is extremely useful in:

  • RAP action implementations

  • Saver class methods

  • Determinations with heavy logic

  • Mass creation scenarios

  • External API or BAPI calls

For example:

  • Call legacy BAPI in parallel class

  • Perform COMMIT WORK there

  • Return updated keys

  • Continue RAP flow without dumps

3. Clean Architecture

  • Business logic isolated

  • No RAP lifecycle conflict

  • Scalable execution

  • Better performance


Conclusion

Parallel processing in ABAP Cloud is not only for classic reports.
It fits perfectly into RAP architecture when:

  • You need independent transactions

  • External commits are required

  • Heavy processing must be offloaded

You can refer to this link for SAP's documentation on parallel processing.