Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Transaction Jobs with no access to SM36 in SAP system
In SAP systems, users may not always have access to transaction SM36 (Define Background Job) to schedule jobs through the standard interface. In such scenarios, you can leverage ABAP function modules to schedule jobs programmatically. There are specific function modules like JOB_OPEN and JOB_CLOSE that allow you to create and manage background jobs directly from your ABAP programs.
You can programmatically handle job scheduling irrespective of privilege issues, providing an alternative approach when standard transaction access is restricted.
Key Function Modules for Job Scheduling
The main function modules used for programmatic job scheduling are −
- JOB_OPEN − Opens a new background job and returns a job number
- JOB_SUBMIT − Submits a program or transaction to the opened job
- JOB_CLOSE − Closes the job and schedules it for execution
Example Implementation
Here's a complete example showing how to schedule a job programmatically −
DATA: lv_jobname TYPE tbtcjob-jobname VALUE 'MY_BACKGROUND_JOB',
lv_jobcount TYPE tbtcjob-jobcount,
lv_print_parameters TYPE pri_params.
* Open the job
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = lv_jobname
IMPORTING
jobcount = lv_jobcount
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc = 0.
* Submit program to job
SUBMIT zmy_report
VIA JOB lv_jobname NUMBER lv_jobcount
AND RETURN.
* Close and schedule the job
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = lv_jobcount
jobname = lv_jobname
strtimmed = 'X' "Start immediately
EXCEPTIONS
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
OTHERS = 6.
IF sy-subrc = 0.
WRITE: 'Job scheduled successfully with job number:', lv_jobcount.
ELSE.
WRITE: 'Error closing job:', sy-subrc.
ENDIF.
ELSE.
WRITE: 'Error opening job:', sy-subrc.
ENDIF.
Benefits of Programmatic Job Scheduling
This approach provides flexibility for users who lack SM36 access while maintaining the ability to automate background processes. The programmatic method also allows for dynamic job creation based on runtime conditions and can be integrated into larger automation workflows.
By using these function modules, you can effectively bypass transaction−level restrictions and maintain robust job scheduling capabilities within your SAP applications.
