This is a test message to test the length of the message box.
Login
ABAP Quick Processing in a new task
Created by Software-Heroes

ABAP Quick - Processing in a new task

5034

This tip is about asynchronous processing in a new process and what to look out for.



In some cases you want to execute a computationally heavy process asynchronously, an additional process should be started and the whole thing should not have any performance impact on the current process. To do this, you use an asynchronous task that runs in its own LUW and, in contrast to the main process, can take its time. In this article, we'll go into the prerequisites and show you how to start the process.

 

Requirements

So that we can execute a process asynchronously, we need a function module in the first step. In addition, it must also be RFC-enabled. The function module should run in a separate process, similar to an update module. There are therefore the following additional requirements for the function block:

  • RFC-enabled function module
  • Only parameters with VALUE data transfer
  • No parameters with exporting or changing

 

Example

Such a function module could now look like this, using three importing parameters that we will work with later.

FUNCTION Z_TEST_FOR_BACKGROUND_PROCESS
  IMPORTING
    VALUE(ID_USER) TYPE SYUNAME
    VALUE(ID_NUMBER) TYPE I
    VALUE(ID_TEXT) TYPE STRING.

  " Implement some code
ENDFUNCTION.

 

If you work with Eclipse, you should not forget to mark the function module as RFC-enabled. To do this, you will find the "Specific" tab on the "Properties" view. Here you can set the Processing Type to RFC.

 

Start

To call the function module in your processing, a simple CALL FUNCTION is sufficient, as you do with normal function modules. You must also specify the addition IN BACKGROUND TASK so that the RFC function module is started in the background and assigned to its own LUW with AS SEPERATE UNIT. The use of the addition DESTINATION is optional; if no value is specified, the destination NONE is used.

CALL FUNCTION 'Z_TEST_FOR_BACKGROUND_PROCESS'
  IN BACKGROUND TASK AS SEPARATE UNIT
  EXPORTING
    id_user   = sy-uname
    id_number = 23
    id_text   = `Some example text`.

 

Commit

Depending on where you are in your process, you may need to issue a COMMIT to start the process. If you call the function module as above, it will first be registered for processing, but no processing will take place yet. The next COMMIT WORK then starts processing and the process.

Here are a few examples of how it could be solved:

  • BADI implementation - A commit is set here after successful processing and a rollback is processed in the event of an error. No additional commit has to be implemented or a commit can lead to an error in the processing of the standard.
  • OData Service - During the execution of a function, an asynchronous process should also be started; a commit must be set for this after the call.

 

Hint: If you test the OData via the SAP Gateway Client without a commit, the processing will work, if it is called via a Fiori application it will no longer work. So it's best to always implement a COMMIT WORK here.

 

Rules

Since the function module starts in its own LUW, you can no longer access the data of the original session, but you can use all importing parameters and read your own data. Your commit or rollback only affects your data, so that you can work normally from standard processes. However, you should note that if the original process should then roll back, your process will not notice it.

 

Conclusion

With our little tip, you should now be able to implement asynchronous processing from your own programs and from the standard. So that processing starts properly, always think of a commit work and whether it makes sense at this point.


Included topics:
QuickNEW TASKAsynchronous processing
Comments (0)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ABAP in Practice - String Processing

Category - ABAP

In this practical example we look at the string processing to determine the CDS names in CamelCase and how you can implement this with ABAP.

10/15/2024

ABAP in Practice - Test Driven Development

Category - ABAP

How does TDD actually work in practice and are there simple examples for learning in ABAP? In this exercise we will look at the practical part.

09/24/2024

ABAP in Practice - Merge data sets

Category - ABAP

How do we merge two different data sets in ABAP, especially with regard to Modern ABAP? A practical task for this topic.

09/17/2024

ABAP in Practice - Modern ABAP

Category - ABAP

In this small task we look at existing classic ABAP source code and try to optimize it according to Modern ABAP.

08/27/2024

ABAP Quick - Performance Data Filtering

Category - ABAP

Which statement do you use in ABAP to filter internal tables and is it performant? Read more in this article.

08/13/2024