Event-Driven Background Jobs in SAP BASIS
I. What are Event-Driven Jobs?
Event-driven background jobs are SAP background jobs whose execution is triggered not by a specific time or date, but by the occurrence of a predefined "event" within the SAP system or from an external source.
- SAP Event: A named flag or signal that can be raised (triggered) within the SAP system or by an external program. When an event is raised, any background job configured to "wait for" that event will be set to
Ready
status and subsequently executed by an available background work process. - Purpose:
- Automation & Dependencies: Automate complex process chains where one job's successful completion (or specific output) triggers another job.
- Real-time Processing: React to real-time occurrences (e.g., file arrival, interface completion, critical data change).
- Flexibility: Decouple job scheduling from fixed time windows, making processes more adaptable to varying data volumes or external system availability.
- Integration: Allow external systems to initiate SAP processes without direct RFC calls to specific function modules, providing a robust and less tightly coupled integration point.
II. Defining and Managing Events (SM64
)
SM64
(Business Event) is the central transaction for defining and managing SAP events.
-
Defining an Event:
- Go to
SM64
. - Click
Create
. Event Name
: Choose a meaningful name (e.g.,Z_FILE_ARRIVED_AP
,SAP_HR_DATA_LOAD_COMPLETE
). Follow a consistent naming convention (e.g.,Z_CLIENT_FUNCTION_EVENT
).Description
: Provide a clear description of what the event signifies.Parameter
(Optional): Define an event parameter (e.g.,&EVTPARM
). This allows you to pass a short string value (up to 32 characters) along with the event. The triggered job's ABAP program can read this parameter.- Use Cases: Pass a file name, a unique ID, a status code, or a processing variant name.
- Save the event.
- Go to
-
Monitoring Events in
SM64
:SM64
displays a list of all defined events.- It shows the
Last Creation Date
andLast Creation Time
for when the event was last triggered. - You can select an event and click
Event History
to see a log of its past triggers.
III. Scheduling Event-Driven Jobs (SM36
)
- Create a New Background Job:
- Go to
SM36
. - Enter
Job Name
andJob Class
. - Define
Job Steps
(ABAP program, external command, etc.) as usual.
- Go to
- Define Start Condition as
After Event
:- Click
Start Condition
. - Select the
After Event
radio button. Event
: Enter the name of the event you defined inSM64
(e.g.,Z_FILE_ARRIVED_AP
). Use F4 help to search.Parameter
(Optional): If the event is configured to pass a parameter, and your job's ABAP program needs to consume it, you can specify&EVTPARM
here inSM36
to pass it to the job's variant.Period Job
(Optional): If you want the job to be re-released and wait for the event again after it finishes, checkPeriod Job
and specify a period (e.g., Daily). If not checked, the job will run once and then remain inFinished
orCanceled
status until manually re-released.- Save the start condition and the job. The job will now be in
Released
status, waiting for the event.
- Click
IV. Triggering Events (Raising an Event)
An event can be triggered in several ways:
-
Manually (
SM64
):- Go to
SM64
. - Select the event.
- Click
Raise
(orTrigger
). - If the event has a parameter, you'll be prompted to enter the
Event Parameter
. - Use Case: Testing, one-off triggering.
- Go to
-
From an ABAP Program:
- This is the most common method for intra-SAP process chaining.
- Use the function module
BP_EVENT_RAISE
. - Syntax Example:
ABAP
CALL FUNCTION 'BP_EVENT_RAISE' EXPORTING eventid = 'Z_FILE_ARRIVED_AP' eventpar = 'MY_FILE.CSV' " Optional parameter EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. " Error handling ENDIF.
- Use Case: After a preceding background job finishes successfully, its last step calls
BP_EVENT_RAISE
to trigger the next job.
-
From the Operating System (OS Command):
- Allows external systems or OS scripts to trigger SAP events.
- Uses the SAP executable
btctrns1
. - Syntax Example (UNIX/Linux):
Bash
/usr/sap/<SID>/SYS/exe/run/btctrns1 -t EVENT -E Z_FILE_ARRIVED_AP -P FILENAME_001.TXT
-t EVENT
: Specifies event type.-E <Event_Name>
: The name of the event.-P <Parameter_Value>
: (Optional) The event parameter value.
- Important: The OS user executing
btctrns1
must have necessary permissions.btctrns1
connects to the SAP Gateway. - Use Case: An external script detects a new file, processes it, and then triggers an SAP job to import the data, passing the filename as a parameter.
-
As a Background Job Step (using
SM69
External Command):- You can define an external OS command in
SM69
that callsbtctrns1
. - Then, use this
SM69
command as a step in an ABAP background job. - Use Case: A preceding ABAP job prepares data, then triggers another ABAP job by raising an event via an OS command step. This is less common than directly using
BP_EVENT_RAISE
from ABAP, but possible.
- You can define an external OS command in
V. Monitoring Event-Driven Jobs (SM37
)
- Status Changes: When an event is raised, a
Released
job waiting for that event will change its status toReady
, then toRunning
(if a background work process is available). - Checking Event Parameters: The event parameter passed can be seen in the
Job Log
of the triggered job (if the ABAP program logs it). You can also typically see it inSM37
under Job Details forAfter Event
jobs. - Dependencies: When troubleshooting, ensure the event was actually raised (check
SM64
history) and that the job's start condition correctly specified the event.
VI. Important Configuration and Best Practices
- Event Naming Convention:
- Establish a clear, consistent, and unique naming convention for events (e.g.,
Z_<Module>_<Process>_<Status>
,Z_FI_POSTING_COMPLETED
,Z_HR_FILE_RECEIVED
). - Avoid generic names like
Z_EVENT1
.
- Establish a clear, consistent, and unique naming convention for events (e.g.,
- Event Parameter Usage:
- Design your ABAP programs to read and utilize the
&EVTPARM
value when necessary. Use function modules likeBP_EVENT_READ
or ensure the job variant uses&EVTPARM
. - Ensure the external system or triggering program passes a meaningful value.
- Design your ABAP programs to read and utilize the
- Security for Event Triggering:
S_BTCH_EVT
Authorization Object: The user triggering an event (viaBP_EVENT_RAISE
in ABAP orbtctrns1
from OS) needs authorization forS_BTCH_EVT
withACTVT=01
(Create/Raise) and the specificEVENTID
.- OS User Permissions: The OS user executing
btctrns1
must have permissions to run the executable and connect to the SAP Gateway.
- Error Handling in Triggering Programs:
- Programs that raise events should have robust error handling. If the event fails to raise (
BP_EVENT_RAISE
returnssy-subrc <> 0
), it should be logged or alerted to prevent the dependent job from never starting.
- Programs that raise events should have robust error handling. If the event fails to raise (
- Monitoring and Alerting:
SM64
Event History: Regularly checkSM64
event history to verify events are being triggered as expected.- Solution Manager / CCMS (
RZ20
): Configure alerts for dependent jobs that are stuck inReleased
status for too long, as this might indicate the event was not raised. Also, alert on canceled event-driven jobs. - Job Chaining/Dependency Monitoring: Tools like Solution Manager or custom developments can visualize and monitor complex event-driven job chains.
- Periodic Jobs for Event-Driven Chains:
- If an event-driven job needs to run every time an event occurs, ensure it is configured as a
Periodic Job
inSM36
afterAfter Event
is selected. This makes it automatically re-release itself and wait for the next event trigger after it finishes. If not periodic, it will only run once.
- If an event-driven job needs to run every time an event occurs, ensure it is configured as a
- Resource Management:
- Ensure sufficient background work processes are available for event-driven jobs, especially if a single event can trigger many jobs concurrently.
10 Interview Questions and Answers (One-Liner) for Event-Driven Background Jobs
- Q: What is the main transaction for defining and managing SAP events?
- A:
SM64
.
- A:
- Q: How do you set a background job to wait for an event?
- A: In
SM36
, set the Start Condition toAfter Event
.
- A: In
- Q: Which SAP function module is used to raise an event from an ABAP program?
- A:
BP_EVENT_RAISE
.
- A:
- Q: What is the OS command line tool used to trigger an SAP event from the operating system?
- A:
btctrns1
.
- A:
- Q: Can you pass a parameter with an event trigger?
- A: Yes, using the
Event Parameter
field inSM64
orbtctrns1 -P
.
- A: Yes, using the
- Q: What authorization object is required to raise an event?
- A:
S_BTCH_EVT
.
- A:
- Q: If an event-driven job needs to run multiple times, what setting in
SM36
is crucial?- A: Mark it as a
Period Job
.
- A: Mark it as a
- Q: What status will an event-driven job be in while waiting for its event?
- A:
Released
.
- A:
- Q: Where can you check when an event was last triggered?
- A: In
SM64
, underLast Creation Date/Time
orEvent History
.
- A: In
- Q: Why use an event-driven job instead of an
After Job
job?- A: Events offer more flexibility, can be triggered from external systems, and decouple dependencies.
5 Scenario-Based Hard Questions and Answers for Event-Driven Background Jobs
-
Scenario: You've implemented a critical daily process where an external ETL tool places a
daily_sales.csv
file on the SAP application server at//sap_app_server/interface/sales_in/
. Once the file is placed, an SAP background jobZ_SALES_IMPORTER
(ABAP programZ_PROCESS_SALES_FILE
) needs to be triggered immediately to process it. TheZ_SALES_IMPORTER
job needs the exact filename (which includes a timestamp, e.g.,daily_sales_202506211030.csv
) to be passed to it for processing.- Q: Detail the complete configuration and process, from defining the event to the external tool's action, to achieve this, ensuring the filename is passed correctly.
- A:
- I. Define the SAP Event (
SM64
):- Event Name:
Z_SALES_FILE_ARRIVED
- Description: "Triggered when new daily sales file arrives on SFTP server."
- Parameter:
&EVTPARM
(this will carry the filename). - Save.
- Event Name:
- II. Configure the Background Job (
SM36
):- Job Name:
Z_SALES_IMPORTER
- Job Class:
B
(e.g., as it's critical daily processing) - Steps:
ABAP Program
:Z_PROCESS_SALES_FILE
Variant
: Create a variant (e.g.,Z_VARIANT_DYNAMIC
). Crucially, the ABAP programZ_PROCESS_SALES_FILE
must be designed to read its input filename from a parameter passed to the variant, or fromBP_EVENT_READ
. For&EVTPARM
, you define a selection screen parameter (e.g.,P_FILENAME TYPE STRING
) in the program's variant, and then inSM36
->Step
->Variant
, use&EVTPARM
as the value forP_FILENAME
.
- Start Condition:
- Select
After Event
. - Event:
Z_SALES_FILE_ARRIVED
- Parameter:
&EVTPARM
(This tells SAP to pass the parameter from the event to the job's variant/program). - Period Job: Check
Period Job
and set toDaily
(orImmediate
if the external tool is truly once per day, butDaily
ensures it re-releases for the next day's file).
- Select
- Save the job. It will be in
Released
status.
- Job Name:
- III. External ETL Tool Action (OS Level Command):
- After the ETL tool successfully places the
daily_sales_202506211030.csv
file on//sap_app_server/interface/sales_in/
, its final step should execute an OS command on thesap_app_server
(or any server that can reach the SAP Gateway). - OS Command:
Bash
/usr/sap/<SID>/SYS/exe/run/btctrns1 -t EVENT -E Z_SALES_FILE_ARRIVED -P /interface/sales_in/daily_sales_202506211030.csv
- Replace
<SID>
with your SAP System ID. - The value passed with
-P
(e.g.,/interface/sales_in/daily_sales_202506211030.csv
) becomes theEvent Parameter
.
- Replace
- OS User: The OS user executing this command must have permissions to run
btctrns1
and connect to the SAP Gateway.
- After the ETL tool successfully places the
- IV. ABAP Program
Z_PROCESS_SALES_FILE
Adaptation:- The ABAP program must be capable of reading the
Event Parameter
. - Option A (Recommended for
&EVTPARM
in variant):ABAPPARAMETERS: p_file TYPE string. " This parameter is in the job variant and takes &EVTPARM START-OF-SELECTION. " p_file now contains '/interface/sales_in/daily_sales_202506211030.csv' " Proceed with file processing using p_file
- Option B (If not using variant parameter):
ABAP
DATA: lv_event_param TYPE btceparam. CALL FUNCTION 'BP_EVENT_READ' EXPORTING eventid = 'Z_SALES_FILE_ARRIVED' IMPORTING eventpar = lv_event_param EXCEPTIONS OTHERS = 1. IF sy-subrc = 0. " lv_event_param contains the filename " Proceed with file processing using lv_event_param ENDIF.
- The ABAP program must be capable of reading the
- Process Flow: ETL places file -> ETL executes
btctrns1
with filename ->btctrns1
triggersZ_SALES_FILE_ARRIVED
event ->Z_SALES_IMPORTER
(waiting for this event) is set toReady
and runs, receiving the filename as a parameter ->Z_PROCESS_SALES_FILE
processes the specific file.
- I. Define the SAP Event (
-
Scenario: You have a complex financial closing process involving 10 jobs.
Job_A
runs, and upon successful completion, triggersJob_B
andJob_C
simultaneously. Once bothJob_B
andJob_C
complete successfully,Job_D
should start.- Q: Design an event-driven job chain in SAP to manage these dependencies, explaining the events and job configurations needed for each step, and how to ensure
Job_D
only starts after BOTHJob_B
andJob_C
are finished. - A:
-
Event Definitions (
SM64
):Z_JOB_A_FINISHED
(No parameter) - Triggered byJob_A
.Z_JOB_B_FINISHED
(No parameter) - Triggered byJob_B
.Z_JOB_C_FINISHED
(No parameter) - Triggered byJob_C
.Z_ALL_DEPENDENCIES_MET
(No parameter) - This will be a virtual event triggered by a custom logic.
-
Job Configurations (
SM36
):-
Job_A
:- Start Condition:
Immediate
(or scheduled time/date). - Steps: Contains its relevant programs.
- Last Step: An ABAP program (or a custom method) that, upon
Job_A
's successful completion, calls:ABAPCALL FUNCTION 'BP_EVENT_RAISE' EXPORTING eventid = 'Z_JOB_A_FINISHED'.
- Period Job: No (unless
Job_A
is meant to run periodically and trigger the chain each time).
- Start Condition:
-
Job_B
:- Start Condition:
After Event
->Event
:Z_JOB_A_FINISHED
. - Steps: Contains its relevant programs.
- Last Step: An ABAP program that, upon
Job_B
's successful completion, calls:ABAPCALL FUNCTION 'BP_EVENT_RAISE' EXPORTING eventid = 'Z_JOB_B_FINISHED'.
- Period Job: Yes (to re-release after execution, ready for the next
Z_JOB_A_FINISHED
).
- Start Condition:
-
Job_C
:- Start Condition:
After Event
->Event
:Z_JOB_A_FINISHED
. - Steps: Contains its relevant programs.
- Last Step: An ABAP program that, upon
Job_C
's successful completion, calls:ABAPCALL FUNCTION 'BP_EVENT_RAISE' EXPORTING eventid = 'Z_JOB_C_FINISHED'.
- Period Job: Yes (to re-release after execution, ready for the next
Z_JOB_A_FINISHED
).
- Start Condition:
-
Job_D
:- Start Condition:
After Event
->Event
:Z_ALL_DEPENDENCIES_MET
. - Steps: Contains its relevant programs.
- Period Job: Yes.
- Start Condition:
-
-
Ensuring
Job_D
Starts After BOTHJob_B
andJob_C
(The "AND" Condition):- SAP's standard event-driven jobs support an "OR" condition (if
Job_X
waits forEvent_Y
OREvent_Z
, it triggers when either occurs). For an "AND" condition, you need a monitoring job or a custom ABAP program. - Recommended Solution: A Dedicated "Event Monitor" ABAP Job:
- Create a New Job:
Z_EVENT_MONITOR_B_C
- Start Condition:
After Event
-> Event:Z_JOB_B_FINISHED
. - Period Job: Yes.
- Steps: This job will run an ABAP program (e.g.,
Z_CHECK_B_C_EVENTS
) that performs the "AND" logic. Z_CHECK_B_C_EVENTS
Program Logic:- When
Z_EVENT_MONITOR_B_C
is triggered byZ_JOB_B_FINISHED
, the programZ_CHECK_B_C_EVENTS
will then check ifZ_JOB_C_FINISHED
has also occurred recently. - This can be done by checking the
SM64
event history forZ_JOB_C_FINISHED
(e.g., within the last few minutes/hours). - If both conditions are met (i.e.,
Z_JOB_B_FINISHED
andZ_JOB_C_FINISHED
have recently occurred):ABAPCALL FUNCTION 'BP_EVENT_RAISE' EXPORTING eventid = 'Z_ALL_DEPENDENCIES_MET'.
- Else (if
Z_JOB_C_FINISHED
has not occurred yet): The program logs that it's waiting and exits. ThisZ_EVENT_MONITOR_B_C
job will then be re-released (because it's periodic) and wait for the next trigger ofZ_JOB_B_FINISHED
(which may happen again, or not, untilJob_A
runs again).
- When
- Create a New Job:
- Alternative for
Z_EVENT_MONITOR_B_C
(more robust, but complex): MakeZ_EVENT_MONITOR_B_C
wait forZ_JOB_C_FINISHED
instead, and its program checks forZ_JOB_B_FINISHED
. The key is that one of them needs to be the direct trigger, and the program performs the check for the other. This scenario is why tools like SAP Solution Manager's Business Process Monitoring are preferred for complex chains.
- SAP's standard event-driven jobs support an "OR" condition (if
-
- Q: Design an event-driven job chain in SAP to manage these dependencies, explaining the events and job configurations needed for each step, and how to ensure
-
Scenario: A background job
Z_EXT_REPORT
needs to be triggered by an external monitoring system viabtctrns1
. TheJob Log
ofZ_EXT_REPORT
consistently shows "Job started... Job canceled" with no other messages orST22
dump.SM21
showsCPIC-CALL: 'ThSAPRcvEx' : cmRc=20 thRc=456#Error in program call
.- Q: What does the
thRc=456
error specifically indicate in this context, and what detailed steps would you take, involving OS-level checks and SAP Gateway monitoring, to troubleshoot and resolve this issue? - A:
thRc=456
Indication:thRc=456
(oftenTP_NOT_FOUND
orPROGRAM_NOT_REGISTERED
) in theCPIC-CALL
error when usingbtctrns1
to trigger an event, specifically means that the SAP Gateway could not find or execute thebtctrns1
program itself, or the connection frombtctrns1
to the Gateway failed due to a fundamental environment issue on the OS level. This is not an issue with the event itself or the job, but with thebtctrns1
executable.- Detailed Troubleshooting & Resolution Steps:
- Verify
btctrns1
Path and Permissions on OS:- Action: Log into the OS of the external monitoring system (or wherever
btctrns1
is being executed from). - Action: Check the exact path to
btctrns1
in the external system's script (e.g.,/usr/sap/<SID>/SYS/exe/run/btctrns1
). Is this path correct and accessible? - Action: Verify the OS user that runs the external monitoring system's script has
execute
permissions onbtctrns1
. (chmod +x btctrns1
if needed, but it should have correct permissions after SAP installation). - Rationale: The most common cause of
thRc=456
in this scenario.
- Action: Log into the OS of the external monitoring system (or wherever
- Manual Execution of
btctrns1
on OS:- Action: As the exact OS user that the external system uses, manually execute the
btctrns1
command from the command line:Bash/usr/sap/<SID>/SYS/exe/run/btctrns1 -t EVENT -E Z_EXT_TRIGGER -P TEST_PARAM
- Observe: Does it return any specific errors on the command line? (e.g., "command not found", "permission denied", "connect failed"). This output is often more informative than the
SM21
log. - Rationale: Direct reproduction helps isolate the problem to the OS level.
- Action: As the exact OS user that the external system uses, manually execute the
- SAP Gateway Connectivity Check (
ping
,telnet
):- Action: From the external system's OS, try to ping the SAP application server's IP address (where the Gateway is running).
- Action: Try to
telnet
to the SAP Gateway port (e.g.,telnet <SAP_APP_SERVER_IP> 3300
for instance 00, or3301
for 01, etc.). A successful connection means the port is open. - Rationale: Rule out network connectivity issues or firewall blocks.
- SAP Gateway Monitoring (
SMGW
):- Action: On the SAP system, go to
SMGW
(Gateway Monitor). - Check: See if there are any errors in the Gateway log (
GoTo
->Log
->Display
). - Check: Look for any blocked connections or security errors.
- Rationale: While the error points to
btctrns1
itself, the Gateway might log connection attempts and failures.
- Action: On the SAP system, go to
dev_w*
Traces on SAP Application Server:- Action: On the SAP application server, check the
dev_w*
developer traces (work
directory) for the work processes (dpmon
also gives clues) around the time of the event trigger attempt. These logs might contain more detailed information from the SAP kernel regarding the failedbtctrns1
connection. - Rationale: Kernel-level debugging logs.
- Action: On the SAP application server, check the
- Solution:
- Most likely, the fix will involve correcting the path to
btctrns1
, ensuring the OS user has sufficient permissions to execute it, or resolving network/firewall issues preventing connection to the SAP Gateway. - Once
btctrns1
can successfully trigger an event from the OS command line, the SAP job should begin to run.
- Most likely, the fix will involve correcting the path to
- Verify
- Q: What does the
-
Scenario: A weekly financial reconciliation job (
Z_WEEKLY_RECON
) is triggered by an eventZ_RECON_DATA_READY
. This job is set as aPeriod Job
inSM36
. However, after running successfully once, it never gets triggered again the following week, remaining inFinished
status, even though theZ_RECON_DATA_READY
event is confirmed to be raised weekly by a preceding process.- Q: What is the most common reason for a periodic event-driven job failing to re-release, and how would you verify and rectify this?
- A:
- Most Common Reason: The most common reason for a periodic event-driven job not re-releasing is that the "Period Job" flag in
SM36
was not actually checked or was somehow unset during a change to the job. If it's not a periodic job, it runs once, sets toFinished
, and is done. It won't wait for the event again. - Verification and Rectification Steps:
- Verify
Period Job
Flag inSM37
/SM36
:- Action: Go to
SM37
. FindZ_WEEKLY_RECON
and view its details. - Check: In the
Job Details
->Start Condition
tab, confirm if thePeriod Job
checkbox is actually ticked. - Action: If it's not ticked, go to
SM36
. SelectZ_WEEKLY_RECON
. ClickChange
. Go toStart Condition
. TickPeriod Job
. Set the appropriate periodic value (e.g.,Weekly
). Save. - Rationale: This is the primary culprit. Even if you thought you set it, a mistake or an overwrite could have occurred.
- Action: Go to
- Review Job Change History:
- Action: In
SM37
, selectZ_WEEKLY_RECON
. Go toJob
->Job History
(orUtilities
->Log
->Changes
). - Check: Look for any recent changes to the job definition, especially modifications to the
Start Condition
. Identify who made the change and when. - Rationale: This can confirm if someone inadvertently unset the
Period Job
flag.
- Action: In
- Confirm Event Raising (
SM64
):- Action: While the scenario states the event is confirmed to be raised, it's always good practice to double-check
SM64
forZ_RECON_DATA_READY
. ViewEvent History
and confirm it was indeed raised at the expected time each week, with the correct parameters (if any). - Rationale: Rule out any miscommunication or intermittent failure of the event-raising mechanism.
- Action: While the scenario states the event is confirmed to be raised, it's always good practice to double-check
- Work Process Availability (Less Likely, but for completeness):
- Action: If the
Period Job
flag was correctly set, then the job should re-release. If it still doesn't, it's very rare but could indicate a system-level issue preventing the scheduler from re-releasing the job. CheckSM21
andSM50
/SM66
for any scheduler or work process issues around the time the job should have re-released. - Rationale: To cover all bases.
- Action: If the
- Rectification: Once the
Period Job
flag is correctly set and saved, the job will typically re-release itself immediately (if the event was just raised) or wait for the next occurrence ofZ_RECON_DATA_READY
.
- Verify
- Most Common Reason: The most common reason for a periodic event-driven job not re-releasing is that the "Period Job" flag in
-
Scenario: You need to implement a data load process where a master data extract job (
Z_MASTER_EXTRACT
) runs onAPPSERV_01
and, upon its successful completion, triggers a dependent job (Z_DELTA_LOAD
) onAPPSERV_02
. Both jobs should be triggered by an event, and theZ_DELTA_LOAD
job should receive the extraction date as a parameter.- Q: Design this event-driven process. Explain the specific event type, job scheduling (including target server considerations), and how the extraction date is passed, considering the cross-server dependency.
- A:
-
I. Event Definition (
SM64
):- Event Name:
Z_MASTER_DATA_EXTRACTED
- Description: "Master data extraction complete, triggers delta load."
- Parameter:
&EVTPARM
(this will carry the extraction date). - Save.
- Event Name:
-
II.
Z_MASTER_EXTRACT
Job Configuration (SM36
- onAPPSERV_01
):- Job Name:
Z_MASTER_EXTRACT
- Job Class:
B
- Target Server:
APPSERV_01
(explicitly set to ensure it runs here). - Start Condition: Scheduled (
Immediate
or specific date/time). - Steps:
- Step 1: Program for master data extraction.
- Step 2 (ABAP Program): A simple ABAP program (e.g.,
Z_TRIGGER_DELTA_EVENT
) that runs after Step 1.- Logic in
Z_TRIGGER_DELTA_EVENT
:ABAPDATA: lv_extraction_date TYPE sy-datum. lv_extraction_date = sy-datum. " Or get from a previous step's output/variable CALL FUNCTION 'BP_EVENT_RAISE' EXPORTING eventid = 'Z_MASTER_DATA_EXTRACTED' eventpar = lv_extraction_date " Pass current date as parameter EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. " Log error: Failed to raise event MESSAGE 'Failed to raise event Z_MASTER_DATA_EXTRACTED' TYPE 'E'. ENDIF.
- Logic in
- Period Job: No (unless the master extract itself runs periodically and initiates the chain).
- Save.
- Job Name:
-
III.
Z_DELTA_LOAD
Job Configuration (SM36
- can be defined on any server, will run onAPPSERV_02
):- Job Name:
Z_DELTA_LOAD
- Job Class:
B
- Target Server:
APPSERV_02
(Crucial for cross-server execution). This ensures that even though the event is global, this specific job instance is scheduled to run only onAPPSERV_02
. - Start Condition:
- Select
After Event
. - Event:
Z_MASTER_DATA_EXTRACTED
- Parameter:
&EVTPARM
(This tells SAP to take the parameter passed with the event and make it available to the job's program/variant). - Period Job: Check
Period Job
and set toDaily
(if the process runs daily and needs to re-release).
- Select
- Steps:
- Step 1: ABAP program (
Z_PROCESS_DELTA_DATA
). - Variant: The
Z_PROCESS_DELTA_DATA
program's variant should have a selection parameter (e.g.,P_EXTR_DATE TYPE SY-DATUM
) configured to accept&EVTPARM
. - Logic in
Z_PROCESS_DELTA_DATA
:ABAPPARAMETERS: p_extr_date TYPE sy-datum. " This parameter is in the job variant and takes &EVTPARM START-OF-SELECTION. " p_extr_date now contains the date from Z_MASTER_EXTRACT " Use p_extr_date for delta logic (e.g., selecting data from this date onwards) MESSAGE i000(00) WITH 'Processing delta for extraction date:' p_extr_date. " ... rest of the delta load logic ...
- Step 1: ABAP program (
- Save.
- Job Name:
-
Process Flow & Cross-Server Aspect:
Z_MASTER_EXTRACT
starts onAPPSERV_01
.- Upon completion, its last step on
APPSERV_01
callsBP_EVENT_RAISE
to trigger theZ_MASTER_DATA_EXTRACTED
event, passing the extraction date. - The SAP scheduler (which runs globally) detects that
Z_MASTER_DATA_EXTRACTED
has been raised. Z_DELTA_LOAD
, which is waiting for this event and hasAPPSERV_02
as its target server, is activated.- The scheduler assigns
Z_DELTA_LOAD
to an available background work process onAPPSERV_02
. Z_DELTA_LOAD
executes onAPPSERV_02
, and its programZ_PROCESS_DELTA_DATA
receives the extraction date via&EVTPARM
and processes the delta.
-
This setup effectively manages the cross-server dependency and passes critical information using the event mechanism.
Comments
Post a Comment