Background Jobs and Parallel Processing
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Some work takes too long for a person to wait for it: reminding every clerk about claims that are still open, recalculating
thousands of totals, printing a month-end list. ABAP offers three families of tools for such work. In classic Standard ABAP
you schedule a background job, a program that the system runs by itself in a special work process, without a screen. In
ABAP Cloud you cannot use that classic job system; you describe the job as an application job that people or programs
schedule, or you hand a short piece of work to the background processing framework (bgPF). And when a single long run is
still too slow, a program can cut its data into packages and let several work processes handle them at the same time, which
is parallel processing with asynchronous remote function calls. This page is written against Standard ABAP release 8.16
and ABAP for Cloud Development release 9.20 (2608). The job system, SUBMIT and asynchronous RFC are classic Standard ABAP
(on premise and private edition); application jobs and the bgPF are the ABAP Cloud tools. After reading, you can choose the
right tool, read a classic scheduling program, check a job in the job overview, and explain why a parallel run needs
independent packages.
Before you read
-
Classic Reports and Events: what an executable program (report) is, because only reports can run as job steps.
-
Selection Screens: parameters, select-options and variants, the values a background run must get from somewhere because nobody can type them.
-
Function Modules and Function Groups: the job system and asynchronous RFC are called through function modules.
-
SAP LUW, Update Tasks and Commit: commits end work units, and every tool on this page interacts with them.
-
Database Tables and Structures: the claim table
ZEXP_CLAIMused in the examples.
Key terms
-
Background job: a unit of work, made of one or more job steps, that the system runs without a user dialog.
-
Job step: one program (or external command) inside a background job.
-
Background work process: a work process reserved for background jobs, with no dialog time limit.
-
Spool request: the stored list output of a job step, waiting to be printed or displayed.
-
Application job: the ABAP Cloud form of a scheduled job, created from a template in the Application Jobs app or through an API.
-
Background processing framework: the ABAP Cloud framework that runs methods of your classes asynchronously and reliably.
-
Asynchronous RFC (aRFC): a call of a remote-enabled function module that does not wait for the function to finish.
-
RFC server group: a named set of application server instances that parallel processing may use.
-
Work package: one independent slice of the data that one parallel task processes.
Which tool for which system
Classic Standard ABAP (on premise, private edition) |
ABAP Cloud |
|
Schedule recurring or one-off work |
Transaction SM36, or a program that calls |
Application job template, scheduled in the Application Jobs app or with the class |
Run a piece of work asynchronously and reliably |
Background RFC, or a job |
Background processing framework (bgPF) |
Watch it |
Transaction SM37 (job overview), job log, spool requests |
The Application Jobs app, application logs; the bgRFC monitor for bgPF |
Split one long run over several work processes |
|
Not offered as a language statement (see below) |
The ABAP Keyword Documentation for ABAP for Cloud Development has no topic for SUBMIT or for the asynchronous form of
CALL FUNCTION; its topic for CALL FUNCTION, RFC lists only the synchronous forms. That is why the sections below treat
the classic tools and the cloud tools separately.
Classic background jobs
What a job is
The work unit of the classic background processing system is the background job, which consists of one or more job steps. Putting several programs into one job lets you schedule and review them as one thing. A job step is either an executable ABAP program (type 1; module pools and function groups are not allowed) or an external command or program. For an ABAP step the specification is the program, a variant, print and archiving parameters and a language. A report with a selection screen needs a variant, or it must supply its own parameters, because nobody is there to type values. Steps run one after the other. If one step fails the whole job is cancelled and later steps do not run, but a step that already committed is not rolled back.
Jobs run in background work processes. A dialog work process ends a dialog step that runs too long; the limit is the profile
parameter rdisp/max_wprun_time, whose documented default is 600 seconds and which an administrator can change. No such limit applies to background work processes, which also assign memory differently so
they can handle large amounts of data.
Source: Jobs and Job Steps Explained, icm/wp_roll_timeout (names the default of rdisp/max_wprun_time; an AS ABAP 7.51 page) and Background Work Processes
Life of a job
A job passes through a small set of statuses, drawn below from the platform documentation.
Only an administrator or a user with the right authorization can release a job, so users cannot start jobs without approval. A job can also be Intercepted, excluded from running by criteria an administrator defined. Active jobs can no longer be changed or deleted. A job is Canceled when an administrator cancels it in SM37, or when a step ends abnormally, for example with an E or A message in an ABAP program.
Scheduling by hand and monitoring
A job is scheduled from transaction SM36 (Define Background Job), with the "start in the background" option of SA38 or SE38,
through the programming interface that many SAP applications use, or through an external interface. The central tool for
watching jobs is the job overview, transaction SM37: after you select jobs by name, user, status or start condition you can
copy, change, repeat, release, cancel or delete them, show job details (status, periodicity, steps, spool requests) and
display the job log. The job log holds every message that the program issued with MESSAGE; a short dump shows through its
Abend message. Never delete log files at operating-system level: delete the jobs, which deletes their logs.
Authorizations
All users can schedule, cancel, delete and check their own jobs. Extra authorization is needed to work on another user’s job,
to display a job log or a spool request that a job produced, to release a job, or to use an external command. By default a job
runs with the authorizations of the user who scheduled it. Administrator authorization (unrestricted access to all jobs in all
clients, job classes A and B, external programs) should go to few trusted people. The keyword documentation names the
authorization objects S_BTCH_JOB (release right) and S_BTCH_NAM (checks the user named with USER).
Scheduling from a program
A program can create a job itself with the full-control method, three steps in this order: JOB_OPEN creates the job and
returns the job count, the unique number that together with the job name identifies it; then each step is added with the
function module JOB_SUBMIT or with the statement SUBMIT; finally JOB_CLOSE passes the job to the background system. A
job cannot start before it is closed. JOB_CLOSE also tells you whether the job was only scheduled or also released: it
stays only scheduled when the scheduling user lacks release authorization or the job has no start time. The one difference
between the two ways of adding a step is that SUBMIT can pass selection values directly, while JOB_SUBMIT can only name an
existing variant. Job attributes live in different places: the name and number in JOB_OPEN, the immediate start in
JOB_CLOSE (parameter STRTIMMED), the user whose authorizations a step uses in JOB_SUBMIT (AUTHCKNAM). The job priority
set through this interface is always class C.
The scenario: a program lets a clerk start the reminder report Z_EXP_REMINDERS, which lists all claims that are still in
status S (submitted), as a background job. The listing follows the example of the Keyword Documentation for SUBMIT ... VIA JOB,
with the claim report in place of its demo program. It requires an SAP system; not run here.
DATA: number TYPE tbtcjob-jobcount,
name TYPE tbtcjob-jobname VALUE 'EXP_REMINDERS',
print_parameters TYPE pri_params.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = name
IMPORTING
jobcount = number
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc = 0.
SUBMIT z_exp_reminders TO SAP-SPOOL
SPOOL PARAMETERS print_parameters
WITHOUT SPOOL DYNPRO
VIA JOB name NUMBER number
AND RETURN.
IF sy-subrc = 0.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = number
jobname = name
strtimmed = 'X'
EXCEPTIONS
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
OTHERS = 8.
IF sy-subrc = 0.
MESSAGE |Job { name } submitted with number { number }.| TYPE 'S'.
ENDIF.
ENDIF.
ENDIF.
Source: Keyword Documentation for Standard ABAP: SUBMIT, job_options, Task Overview: Full-Control Job Scheduling and Where to Specify Job Attributes
Reading it: SUBMIT ... VIA JOB does not run the report now. It loads the report briefly in a separate internal session, runs
everything before START-OF-SELECTION, stores the selections in an internal variant, and schedules the report as a step. The
actual run happens later in a background session, with the same user and client unless USER is given. VIA JOB works only
together with AND RETURN. After SUBMIT, sy-subrc is 0 when scheduling worked, 4 when the user left the selection
screen, 8 on a scheduling error and 12 on an error in number assignment. strtimmed = 'X' asks for an immediate start, which
works only if the user may release jobs. The print_parameters structure above is left empty, as in the documentation
example. In a real program fill it with the function module GET_PRINT_PARAMETERS (run in batch mode, with the report name),
because otherwise the spool system uses defaults from the user master record, such as 80 characters per line, that may not
fit the list. A list produced by the step is stored as a spool request, a numbered output job for the spool system; if you
use VIA JOB without TO SAP-SPOOL, a spool request is created implicitly with default parameters.
To check the job afterwards, the same documentation page shows the function modules SHOW_JOBSTATE (returns flags such as
finished, running or aborted) and BP_JOBLOG_READ (returns the job log). It requires an SAP system; not run here.
DATA: number TYPE tbtcjob-jobcount,
name TYPE tbtcjob-jobname VALUE 'EXP_REMINDERS',
aborted TYPE c LENGTH 1,
finished TYPE c LENGTH 1.
CALL FUNCTION 'SHOW_JOBSTATE'
EXPORTING
jobcount = number
jobname = name
IMPORTING
aborted = aborted
finished = finished
EXCEPTIONS
jobcount_missing = 1
jobname_missing = 2
job_notex = 3
OTHERS = 4.
SAP warns that the function modules for background processing other than the documented ones (JOB_OPEN, JOB_SUBMIT,
JOB_CLOSE, BP_JOBVARIANT_SCHEDULE, BP_JOBVARIANT_OVERVIEW, BP_CALCULATE_NEXT_JOB_STARTS) are reserved for internal use.
BP_JOBVARIANT_SCHEDULE is the quick "express" method: it shows the user screens to pick a variant and a start time.
Application jobs in ABAP Cloud
An application job is the ABAP Cloud answer to "run this report every first Monday of the month". Three objects work together. The business logic is an ABAP class. The application job catalog entry names that class and says how its selection fields appear in the scheduling dialog. The application job template is a variant of a catalog entry with values for some or all fields; the template is what a business user schedules in the Application Jobs app, choosing a start date and a recurrence such as every first Monday at 1:00. Scheduling a template creates the application job. The framework is meant for long-running, repeated jobs, not for short jobs with a high frequency.
The class implements the interface IF_APJ_RT_RUN, whose single method EXECUTE runs when the job starts. Its public
attributes are the selection parameters, and the framework fills them with the entered values before EXECUTE is called.
Default values for a new template come from the attribute defaults, the constructor or the optional interface
IF_APJ_DT_DEFAULTS with its method FILL_ATTRIBUTE_DEFAULTS. SAP lists the older pair IF_APJ_DT_EXEC_OBJECT and
IF_APJ_RT_EXEC_OBJECT as legacy and says not to use it for new work. The class must be in a customer-defined software
component, not ZLOCAL, so that it can be transported. The listing keeps the documentation’s pattern: a class that writes an
application log and assigns it to the current job. It requires an SAP system; not run here.
CLASS zcl_exp_reminder_job DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_apj_rt_run.
INTERFACES if_apj_dt_defaults.
"! <p class="shorttext synchronized" lang="en">Claim status to count</p>
DATA status_filter TYPE c LENGTH 1 VALUE 'S'.
ENDCLASS.
CLASS zcl_exp_reminder_job IMPLEMENTATION.
METHOD if_apj_dt_defaults~fill_attribute_defaults.
status_filter = 'S'.
ENDMETHOD.
METHOD if_apj_rt_run~execute.
SELECT COUNT(*) FROM zexp_claim WHERE status = @status_filter INTO @DATA(open_claims).
TRY.
DATA(log) = cl_bali_log=>create_with_header(
header = cl_bali_header_setter=>create( object = 'ZEXP_LOG'
subobject = 'REMINDER' ) ).
log->add_item( item = cl_bali_free_text_setter=>create(
severity = if_bali_constants=>c_severity_status
text = |Claims in status { status_filter }: { open_claims }| ) ).
cl_bali_log_db=>get_instance( )->save_log_2nd_db_connection( log = log
assign_to_current_appl_job = abap_true ).
CATCH cx_bali_runtime INTO DATA(runtime_exception).
" error handling
ENDTRY.
ENDMETHOD.
ENDCLASS.
The names ZEXP_LOG and REMINDER stand for an application log object and subobject that you define for your own application;
the documentation uses ZOBJECT and ZSUBOBJECT as placeholders. After the class is activated, you create the catalog entry
and then the template in the ABAP Development Tools (Other ABAP Repository Object, Application Jobs). Creating them also
creates an IAM app named after the entry with the ending _SAJC, which holds the start authorization. To let a business user
schedule the job you add that app to an IAM business catalog and the catalog to a business role. If the business logic does its
own authorization checks, those authorizations go into a separate IAM app of type EXT.
Scheduling by API and automatic restart
Programs can schedule and manage application jobs with the class CL_APJ_RT_API: schedule, read the status, cancel and delete.
The documentation’s example uses a start time stamp rather than the immediate start, because the immediate start cannot be used
from inside a RAP business object: the underlying API performs an implicit COMMIT WORK. The sketch below follows that example.
It requires an SAP system; not run here.
DATA(template_name) = CONV cl_apj_rt_api=>ty_template_name( 'ZEXP_REMINDER_TMPL' ).
DATA job_text TYPE cl_apj_rt_api=>ty_job_text VALUE 'Claim reminders'.
DATA start_info TYPE cl_apj_rt_api=>ty_start_info.
DATA jobname TYPE cl_apj_rt_api=>ty_jobname.
DATA jobcount TYPE cl_apj_rt_api=>ty_jobcount.
GET TIME STAMP FIELD DATA(now).
start_info-timestamp = cl_abap_tstmp=>add( tstmp = now
secs = 3600 ).
TRY.
cl_apj_rt_api=>schedule_job(
EXPORTING
iv_job_template_name = template_name
iv_job_text = job_text
is_start_info = start_info
IMPORTING
ev_jobname = jobname
ev_jobcount = jobcount ).
CATCH cx_apj_rt INTO DATA(apj_exception).
" apj_exception->get_longtext( ) explains the error
ENDTRY.
A long job can be interrupted by a planned or unplanned failover, which rolls back what was not committed. SAP’s documentation
says that such an interrupted application job is not set to canceled any more: it stays active and another server resumes it
with the step that was interrupted (a one-step job starts from the beginning), without creating a copy. The method
CL_APJ_RT_API=>GET_OWN_AUTO_RESTART_NUMBER returns 0 for the original run and 1 or more for a restart, so write the logic so
that it is consistent and can be restarted at any time.
The background processing framework
Application jobs run on a clock. The background processing framework (bgPF) runs a method of your class asynchronously and
reliably when something happens: the user’s screen is not blocked, the work happens in a new session, and the system
guarantees that it runs once. It is based on the background remote function call (bgRFC), the successor of the transactional
(tRFC) and queued (qRFC) remote function calls, and supports only the inbound scenario: sender and receiver are the same system
and the call runs in a new session. You do not write your own RFC. The documentation names two kinds of background process:
a transactional one runs its operations exactly once, in no particular order; a queued one runs them exactly once and in
order. The page says the bgPF is available since the ABAP environment release 2308; for on-premise systems the page tells you
only to create a default inbound destination BGPF in transaction SBGRFCCONF (the cloud needs no action) and names no
release, so check your system.
Two scenarios exist. In the transactional controlled scenario the operation class implements IF_BGMC_OP_SINGLE and follows
the two phases of the controlled SAP LUW from the earlier page: changes in the modify phase, then cl_abap_tx=>save( ), then
the database change. In the uncontrolled scenario the class implements IF_BGMC_OP_SINGLE_TX_UNCONTR and everything happens
in one step. The sketch shows the controlled scenario for the claim table, adapted from the documentation’s sample. It
requires an SAP system; not run here.
CLASS zcl_exp_claim_post_op DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_bgmc_op_single.
METHODS constructor IMPORTING claim_id TYPE zexp_claim-claim_id.
PRIVATE SECTION.
DATA claim_id TYPE zexp_claim-claim_id.
METHODS save.
ENDCLASS.
CLASS zcl_exp_claim_post_op IMPLEMENTATION.
METHOD constructor.
me->claim_id = claim_id.
ENDMETHOD.
METHOD if_bgmc_op_single~execute.
" modify phase: prepare, no database change here
cl_abap_tx=>save( ).
save( ).
ENDMETHOD.
METHOD save.
UPDATE zexp_claim SET status = 'A' WHERE claim_id = @claim_id.
ENDMETHOD.
ENDCLASS.
The starter creates the operation, hands it to a process created by the default factory, saves it for execution and commits.
Without COMMIT WORK the process never starts; when the RAP runtime is in charge it executes COMMIT WORK or
ROLLBACK WORK itself, and your own code must not. It requires an SAP system; not run here.
CLASS zcl_exp_claim_post_starter DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
ENDCLASS.
CLASS zcl_exp_claim_post_starter IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA lx_bgmc TYPE REF TO cx_bgmc.
TRY.
DATA(operation) = NEW zcl_exp_claim_post_op( 'C-0001' ).
cl_bgmc_process_factory=>get_default( )->create( )->set_name( 'Post claim C-0001'
)->set_operation( operation
)->save_for_execution( ).
COMMIT WORK.
CATCH cx_bgmc INTO lx_bgmc.
out->write( lx_bgmc->get_longtext( ) ).
ROLLBACK WORK.
ENDTRY.
ENDMETHOD.
ENDCLASS.
The sequence below shows who does what.
Source: Background Processing Framework
Four more points from the documentation. A referenced object that does not implement IF_SERIALIZABLE_OBJECT is not passed
to the new session, and the constructor is not called again there, so keep the operation’s state small and serializable.
SAVE_FOR_EXECUTION returns a monitor instance for applications that keep their own accounting; the monitor can be written
to a string and rebuilt in a later session to ask for the process state. On premise the bgRFC monitor is transaction
SBGRFCMON, where failed units can be deleted or restarted. For unit tests, CL_BGMC_TEST_ENVIRONMENT=>CREATE_FOR_SPYING
makes SAVE_FOR_EXECUTION do nothing, so you can assert that the expected processes and operations were created while the
operations themselves are tested separately.
Parallel processing with asynchronous RFC
A background job uses one work process. For the "short nights" problem, where a report cannot finish in the time available,
a classic program can cut its data into independent work packages and start one function module call per package with
CALL FUNCTION ... STARTING NEW TASK. The job step itself runs in a background work process, while the tasks it starts run in
dialog work processes, possibly on other servers. The asynchronous call returns as soon as the function has been started
on the target; it does not wait for the result.
Prerequisites
-
The packages must be logically independent: no package may need the result of another, and no order is guaranteed.
-
The function module must be remote-enabled and must not call the destination
BACK. -
The program must not change to a new internal session after the call (no
SUBMITorCALL TRANSACTION). -
Use the form with
DESTINATION IN GROUP, the parallel RFC (pRFC). Other asynchronous forms bypass the built-in resource checks, and SAP says they can bring the system to its knees. -
An asynchronous RFC triggers a database commit in the calling program, except during update processing.
Resource control
With DESTINATION IN GROUP DEFAULT every available server instance is used; with a group name it is an RFC server group
that an administrator defines in transaction RZ12. If no instance has resources, the predefined exception RESOURCE_FAILURE
is raised and the program must handle it, usually by waiting and trying again. The Keyword Documentation says an instance in
a group must have at least three dialog work processes of which one is free, and that queue length and other measures must
stay below thresholds set by profile parameters such as rdisp/rfc_max_queue. Older guide pages quote other numbers (for
example a queue under 10 percent), so treat the numbers as defaults that your administrator may have changed.
Callbacks and waiting
CALLING meth ON END OF TASK (or PERFORMING subr ON END OF TASK) names a callback routine that runs after the function ends.
The method must be public with one non-optional input parameter p_task of type clike, which receives the task ID. Inside
it the statement RECEIVE RESULTS FROM FUNCTION must receive the output parameters; a callback without it is a programming
error. The callbacks only run when the work process changes. WAIT FOR ASYNCHRONOUS TASKS UNTIL makes that happen and waits
until a condition holds (sy-subrc is 0 on success and 8 on timeout with UP TO). If the program ends or leaves the
internal session first, the callbacks never run.
Cutting data into packages, run in the lab
The cutting of the data into packages is plain ABAP and the part that decides whether parallelism is safe. The lab (the open-abap
playground with the reduced version of ZEXP_CLAIM, which has only claim_id, status and amount; the other columns of the
full table are left out) cannot start tasks on other work processes, so this listing only shows the cutting: it inserts seven
submitted claims and groups them into packages of three, summing each package. This listing was run in the lab.
REPORT zp_packages.
CONSTANTS package_size TYPE i VALUE 3.
TYPES: BEGIN OF package_line,
package_no TYPE i,
claims TYPE i,
total TYPE i,
END OF package_line.
DATA packages TYPE STANDARD TABLE OF package_line WITH EMPTY KEY.
DATA claims TYPE STANDARD TABLE OF zexp_claim WITH EMPTY KEY.
DO 7 TIMES.
INSERT zexp_claim FROM @( VALUE #( claim_id = |C-{ sy-index WIDTH = 4 ALIGN = RIGHT PAD = '0' }|
status = 'S'
amount = sy-index * 10 ) ).
ENDDO.
SELECT * FROM zexp_claim WHERE status = 'S' ORDER BY claim_id INTO TABLE @claims.
LOOP AT claims INTO DATA(claim).
DATA(package_no) = ( sy-tabix - 1 ) DIV package_size + 1.
IF package_no > lines( packages ).
APPEND VALUE #( package_no = package_no ) TO packages.
ENDIF.
ASSIGN packages[ package_no ] TO FIELD-SYMBOL(<package>).
<package>-claims += 1.
<package>-total += claim-amount.
ENDLOOP.
LOOP AT packages INTO DATA(package).
WRITE / |Package { package-package_no }: { package-claims } claims, total { package-total }|.
ENDLOOP.
Output:
Package 1: 3 claims, total 60
Package 2: 3 claims, total 150
Package 3: 1 claims, total 70
Reading it: each package holds at most three claims and no package needs another package’s result, which is the property that makes it safe to hand the packages to different work processes.
Starting the packages in parallel
The sketch below hands each package to a remote-enabled function module, here called Z_EXP_CHECK_PACKAGE (you create it; it
has the import parameters claim_from and claim_to and the export parameter checked, and it reads the claims in that
range of the full ZEXP_CLAIM). The structure is that of the Keyword Documentation’s parallel aRFC example: start, handle
RESOURCE_FAILURE by waiting, and finally wait for all callbacks. It requires an SAP system; not run here.
CLASS zcl_exp_parallel_check DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
METHODS callback_meth IMPORTING p_task TYPE clike.
PRIVATE SECTION.
DATA received TYPE i.
DATA checked_total TYPE i.
DATA mess TYPE c LENGTH 80.
ENDCLASS.
CLASS zcl_exp_parallel_check IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA sent TYPE i.
DATA name TYPE c LENGTH 8.
DO 10 TIMES.
name = |Task{ sy-index }|.
CALL FUNCTION 'Z_EXP_CHECK_PACKAGE'
STARTING NEW TASK name
DESTINATION IN GROUP DEFAULT
CALLING callback_meth ON END OF TASK
EXPORTING
claim_from = |C-{ ( sy-index - 1 ) * 1000 + 1 WIDTH = 4 ALIGN = RIGHT PAD = '0' }|
claim_to = |C-{ sy-index * 1000 WIDTH = 4 ALIGN = RIGHT PAD = '0' }|
EXCEPTIONS
system_failure = 1 MESSAGE mess
communication_failure = 2 MESSAGE mess
resource_failure = 3.
CASE sy-subrc.
WHEN 0.
sent += 1.
WHEN 3.
WAIT UNTIL received >= sent UP TO 5 SECONDS.
WHEN OTHERS.
out->write( mess ).
ENDCASE.
ENDDO.
WAIT FOR ASYNCHRONOUS TASKS UNTIL received >= sent.
out->write( |Claims checked: { checked_total }| ).
ENDMETHOD.
METHOD callback_meth.
DATA checked TYPE i.
received += 1.
RECEIVE RESULTS FROM FUNCTION 'Z_EXP_CHECK_PACKAGE'
IMPORTING
checked = checked
EXCEPTIONS
system_failure = 1 MESSAGE mess
communication_failure = 2 MESSAGE mess.
IF sy-subrc = 0.
checked_total += checked.
ENDIF.
ENDMETHOD.
ENDCLASS.
Source: Keyword Documentation for Standard ABAP: RFC, Parallel aRFC, CALL FUNCTION, STARTING NEW TASK and WAIT FOR ASYNCHRONOUS TASKS
Reading it: a task that hit RESOURCE_FAILURE is not counted as sent and is simply skipped after the wait in this sketch; a
production program would retry that package, which the documentation’s example does not show. The order in which the tasks
finish is not fixed. Parallel jobs cannot be marked specially in the job monitor: the parent job shows as one ordinary job.
Source: Parallel Processing Jobs with Asynchronous RFC and Defining RFC Groups for Parallel Processing Jobs
Parallel processing also meets the SAP LUW. Each task runs in its own session and commits on its own, so a rollback in the caller cannot undo packages that already finished. The controlled SAP LUW from SAP LUW, Update Tasks and Commit allows synchronous and asynchronous RFC only in the modify phase.
Scheduling beyond ABAP
Work that runs on a clock is not only an SAP topic. The Backend Development section compares standard scheduling with Quartz for Spring Boot services in Scheduling; misfires, calendars and persistent job stores there answer the same questions that start conditions, factory calendars and restarts answer in the SAP job systems.
Common mistakes
-
Scheduling a report without a variant or selection values: nobody can answer the selection screen in the background.
-
Leaving the print parameters empty for a job that writes lists, and getting default line lengths and printers.
-
Forgetting
COMMIT WORKaftersave_for_execution( ): the background process never starts. -
Calling
STARTING NEW TASKwithoutDESTINATION IN GROUP, or with packages that depend on each other. -
A callback routine without
RECEIVE RESULTS, which leaves the connection open.
What older books show, and what has changed
A book written for AS ABAP 7.5 or older, such as the first edition (2016) of Complete ABAP, whose release range is stated on
Interfaces and Inheritance, or the 2002 ABAP Objects book, covers
the classic job system, and that part is still correct for Standard ABAP: SM36, SM37, JOB_OPEN, SUBMIT with VIA JOB,
JOB_CLOSE, spool requests and variants have not changed in meaning. What those books cannot tell you is the ABAP Cloud side.
There SUBMIT and the asynchronous CALL FUNCTION are not part of the documented language, jobs are application jobs built
from a class with IF_APJ_RT_RUN, a catalog entry and a template, and deferred work is done with the background processing
framework, which is documented as available since the ABAP environment release 2308. Within the application job interfaces, an
older pair, IF_APJ_DT_EXEC_OBJECT and IF_APJ_RT_EXEC_OBJECT, appears in older examples, but SAP now marks it as legacy and
recommends IF_APJ_RT_RUN.
Source: SAP PRESS: Complete ABAP (the publisher page lists the current edition; the 1st edition is out of print), InformIT: ABAP Objects (Keller and Krueger, 2002) and Implementing the Business Logic
Summary
-
A classic background job is made of job steps that run in background work processes without a screen; it is scheduled in SM36 or by a program with
JOB_OPEN,SUBMIT ... VIA JOB(orJOB_SUBMIT) andJOB_CLOSE, and watched in SM37 and its job log. -
A job moves through Planned, Released, Ready, Active and Finished or Canceled; list output goes to a spool request, so fill the print parameters in production programs.
-
In ABAP Cloud the scheduled form is the application job: a class with
IF_APJ_RT_RUN, a catalog entry and a template, scheduled in the Application Jobs app or withCL_APJ_RT_API. -
The background processing framework runs an operation class asynchronously and exactly once; the starter must call
COMMIT WORK(unless RAP does) aftersave_for_execution( ). -
Parallel processing cuts data into independent work packages and starts them with
CALL FUNCTION ... STARTING NEW TASK ... DESTINATION IN GROUP, handlesRESOURCE_FAILURE, and collects results in callbacks withWAIT FOR ASYNCHRONOUS TASKS.
References
-
ABAP Concepts: Writing Unit Tests for Transactional Background Processes
-
ABAP Environment: Example Implementation Using Interface IF_APJ_RT_RUN
-
Keyword Documentation for Standard ABAP: SUBMIT, job_options
-
Keyword Documentation for Standard ABAP: CALL FUNCTION, STARTING NEW TASK
-
Keyword Documentation for Standard ABAP: WAIT FOR ASYNCHRONOUS TASKS
-
Complete ABAP (SAP PRESS), Kiran Bandari; the copy consulted is the 1st edition
-
ABAP Objects (Addison-Wesley), Horst Keller and Sascha Krueger, 1st edition 2002