PackagePackagetypeA library you install and call yourself.See every one →What this type is →independently maintainedindependently maintainedoriginPublished by one person or a small company outside SAP. Says nothing about quality; the readings say that.See every one →

COROUTINES4ABAP

A coroutine framework for ABAP that launches a piece of work, such as a database query or a background task, as a task the caller awaits later while carrying on with other work.

A caller implements the zif_coroutine_scope interface with the work to run, hands it to zcl_coroutine_manager, which launches it and returns a task, and the caller keeps doing other work until it calls await on that task to get the result back. The two examples in the README cover an asynchronous MARA query and a background email send, both without the caller waiting on them synchronously. It provides the launch-and-await mechanism only: error handling around a launched coroutine, or a fixed limit on how many run at once, is not part of what the README shows.

Facts

Last pushLicenceMIT

Where it sits

Lives in
Provides
Parallel processingABAPParallel processingcapabilitySplitting one run's work across several work processes so that it finishes sooner, and collecting what each part returned before the run goes on. [Async processing](capability:async-processing) is the neighbouring concern: work deferred past the request with a guarantee that it eventually happens, where parallel processing is throughput inside a run that waits for its results.

Who is behind it

Furkan COSGUNFurkan COSGUNPersonMaintains this
In the atlas: maintains 6, contributes to 8
@furkancosgun
maintainer

Before choosing this

Signals

ActivityQuietNo published releases; repository quiet for 26 months

It publishes no releases, and its repository has been quiet for at least 24 full months. This may be normal for stable software; check whether its current state still fits your use.

What it declares

Every artifact

Type
Package
Origin
Independently maintained

As a package

Where it runs
does not say
Distributed through
does not say

Connections1

README

quoted from furkancosgun/COROUTINES4ABAP under MIT, read
furkancosgun/COROUTINES4ABAP/README.mdOn GitHub

COROUTINES FOR ABAP

This project showcases the use of coroutines in ABAP for handling asynchronous operations. Coroutines enable the concurrent execution of tasks, allowing you to perform operations such as database queries and background processing more efficiently. By using coroutines, you can execute tasks asynchronously and manage their completion within your ABAP programs.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contents

Overview

This project provides a framework for implementing coroutines in ABAP. Coroutines are designed to handle multiple concurrent operations, making them useful for optimizing performance and enhancing the responsiveness of your applications. The framework includes methods for starting, managing, and awaiting coroutines, enabling more efficient processing of asynchronous tasks.

Examples
Awaiting Results from a Coroutine

This example demonstrates how to use a coroutine to perform an asynchronous database query and then retrieve the results. The coroutine queries material data from the MARA table based on a specified material number range and returns the results when the operation is completed.

Coroutine Class Definition:

CLASS zcl_example_coroutine DEFINITION.
  PUBLIC SECTION.
    INTERFACES: zif_coroutine_scope.
    TYPES: t_mara TYPE TABLE OF mara WITH DEFAULT KEY.
    TYPES: r_matnr TYPE RANGE OF mara-matnr.

    METHODS:
      constructor IMPORTING iv_matnr TYPE r_matnr,
      get_materials RETURNING VALUE(rt_materials) TYPE t_mara.
  PRIVATE SECTION.
    DATA: mt_materials TYPE t_mara,
          mr_matnr TYPE r_matnr.
ENDCLASS.

Coroutine Implementation:

CLASS zcl_example_coroutine IMPLEMENTATION.
  METHOD constructor.
    me->mr_matnr = iv_matnr.
  ENDMETHOD.

  METHOD zif_coroutine_scope~launch.
    SELECT * FROM mara INTO TABLE me->mt_materials WHERE matnr IN me->mr_matnr.
  ENDMETHOD.

  METHOD get_materials.
    rt_materials = me->mt_materials.
  ENDMETHOD.
ENDCLASS.

Main Program:

START-OF-SELECTION.
  DATA: lo_task TYPE REF TO zif_coroutine_task,
        lo_example_work TYPE REF TO zcl_example_coroutine,
        lt_materials TYPE zcl_example_coroutine=>t_mara.

  " Create an instance of the coroutine class
  lo_example_work = NEW zcl_example_coroutine( iv_matnr = VALUE #( ) ).

  " Start the coroutine
  lo_task = zcl_coroutine_manager=>run( lo_example_work ).

  " Perform other operations
  " ...

  " Retrieve results from the coroutine
  lo_example_work ?= lo_task->await( ).
  lt_materials = lo_example_work->get_materials( ).

  " Display results
  LOOP AT lt_materials INTO DATA(ls_material).
    WRITE: / ls_material-matnr, ls_material-meins.
  ENDLOOP.
Background Processing with Coroutines

This example illustrates how to use a coroutine for background processing tasks, such as sending an email. The coroutine performs the email sending operation asynchronously, allowing the main program to continue executing without waiting for the email process to complete.

Coroutine Class Definition:

CLASS zcl_example_coroutine DEFINITION.
  PUBLIC SECTION.
    INTERFACES: zif_coroutine_scope.
    METHODS: 
      constructor IMPORTING iv_recipient TYPE bcs_address,
      send_email.
  PRIVATE SECTION.
    DATA: recipient TYPE bcs_address.
ENDCLASS.

Coroutine Implementation:

CLASS zcl_example_coroutine IMPLEMENTATION.
  METHOD constructor.
    me->recipient = iv_recipient.
  ENDMETHOD.

  METHOD zif_coroutine_scope~launch.
    send_email( ).
  ENDMETHOD.

  METHOD send_email.
    DATA: lo_msg TYPE REF TO cl_bcs_message,
          lt_tstc TYPE TABLE OF tstc.

    SELECT * FROM tstc INTO TABLE lt_tstc.

    TRY.
        cl_salv_table=>factory(
            IMPORTING
                r_salv_table = DATA(lo_salv)
            CHANGING
                t_table = lt_tstc
        ).
      CATCH cx_root.
    ENDTRY.

    lo_msg = NEW #( ).
    lo_msg->add_recipient( me->recipient ).
    lo_msg->set_subject( 'Example Mail Subj.' ).
    lo_msg->set_main_doc( 'Example Mail Content' ).
    lo_msg->add_attachment(
        EXPORTING
        iv_doctype = 'XLS'
        iv_filename = 'DOC.xlsx'
        iv_contents_bin = lo_salv->to_xml( if_salv_bs_xml=>c_type_xlsx )
     ).

    TRY.
        lo_msg->send( ).
    CATCH cx_root.
    ENDTRY.
  ENDMETHOD.
ENDCLASS.

Main Program:

START-OF-SELECTION.
  DATA: lo_task TYPE REF TO zif_coroutine_task,
        lo_example_work TYPE REF TO zcl_example_coroutine.

  " Create an instance of the coroutine class
  lo_example_work = NEW zcl_example_coroutine( iv_recipient = 'furkan51cosgun@gmail.com' ).

  " Start the coroutine
  lo_task = zcl_coroutine_manager=>run( lo_example_work ).

Feel free to customize the code and examples to fit your specific needs.

MIT, read
Parallel processing
  1. abapify/promisePromise and async/await implementation for ABAPfrom ABAP
  2. ABAPParallelizationServiceFramework for running ABAP work units in parallel tasksfrom ABAP
  3. zconcurrency_apiParallel task library for ABAP over the SPTA frameworkfrom ABAP
  4. RFC_TOOLSA wrapper class for calling asynchronous RFC function modules in parallel from ABAP, one instance per parallel task.from ABAP
  5. zthreadThreading library for ABAP modelled on Java's Thread and Runnablefrom ABAP

Details

Sources3
dotabapdiscovered herechecked
github.com/furkancosgun/COROUTINES4ABAPtree, pushes, contributors, CIchecked
README.mdquoted, and what the entry declareschecked

Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.

Compatibility and provenance
discovered viadotabap
first seen in the atlas
ecosystem and domainabap, operations-and-runtime
abaplint
issues under its own abaplint configuration236
lines539
statements310
objects14
files30
analysed, main
abaplint version2.120.84
History in the atlas1
  1. First seen.
For your agent
Ref
artifact:furkancosgun-coroutines4abap
JSON
/artifacts/furkancosgun-coroutines4abap.json
MCP
Connecting an agent