To run a report in the background in SAP, you typically first save the report's selection criteria as a variant, and then use that variant to schedule a background job. This is essential for long-running or resource-intensive reports that would impact system performance if run in the foreground during peak hours.
Step 1: Create a report variant
A report variant is a saved set of selection criteria for a program, which is necessary for running it consistently in the background.
- Navigate to the selection screen of your desired report (e.g., via its transaction code or
SE38for ABAP programs). - Enter all the selection criteria you need for the background run, such as company code, date ranges, and material numbers.
- Click the "Save" icon (often a floppy disk) or navigate to the menu option
Go To > Variants > Save as Variant. - Provide a Variant Name and a Description.
- In the variant attributes screen, you can set additional options:
- Protect Variant: Prevents other users from changing the variant.
- Only for background processing: Restricts the variant so it can only be used for background jobs.
- Selection variables: Use dynamic date and time variables (e.g., "Current Date" or "First Day of Current Month") for recurring jobs.
- Save the variant.
Step 2: Schedule the background job
With your variant created, use the standard SAP transaction SM36 to define and schedule the background job.
- Enter the transaction code
SM36in the command field and press Enter. - Provide a descriptive Job Name (e.g.,
Z_MONTHLY_GL_REPORT) and select a Job Class based on priority (A for high, B for medium, C for low). - Click the Step button.
- In the step definition screen, enter the ABAP Program name for your report and the Variant name you just created. The program name can be found via
System > Statusfrom your report's selection screen. - Save the step and return to the main job definition screen.
- Click the Start condition button to define when the job should run. You have several options:
- Immediate: Runs the job as soon as possible.
- Date/Time: Schedules the job for a specific date and time.
- After Job: Runs the job after another specified background job has finished successfully.
- Recurrence (Periodic Job): For recurring jobs (e.g., daily, weekly, monthly), choose
Date/Time, click thePeriodic Valuesbutton, and define the recurrence.
- After setting the start condition, click Save to schedule the job. The job status will show as "Released".
Step 3: Monitor and retrieve the report output
Once the job has run, you will use two different transactions to monitor its status and retrieve the report's output.
Transaction SM37 (Job Overview)
This transaction allows you to check the status of your background job.
- Go to transaction
SM37. - Enter the Job Name you defined and your User Name (or
*to see all jobs). - Select the relevant Job Statuses (e.g., "Finished" or "Cancelled") and a Date Range.
- Execute the search.
- From the results list, you can select your job and:
- Check the status: See if the job completed successfully, failed, or was cancelled.
- View the Job Log: Examine any errors that may have caused a failure.
Transaction SP01 (Output Controller)
The report output is stored as a "spool request," which you can view with SP01.
- Go to transaction
SP01. - Enter your User Name in the
Created byfield and the Date the job was run. - Execute the search.
- A list of spool requests will be displayed. Find the request associated with your job and double-click it to view the report contents.
- You can then export the output to a local file, such as an Excel spreadsheet.
Best practices and troubleshooting
- Variants are essential: Always use a variant for background jobs to ensure consistency and prevent manual entry errors.
- Use dedicated job users: For critical, long-running jobs, consider having an SAP Basis team create a dedicated background user. This prevents a job from failing if the user who scheduled it is locked or leaves the company.
- Monitor job logs: If a job fails, the job log (
SM37) is the first place to look for details on authorization errors or other technical issues. - Set up output recipients: When scheduling a job in
SM36, you can specify recipients who will receive the spool output via email or their SAP Business Workplace (SBWP) inbox. - Manage spool output: Spool requests consume database space over time. Schedule periodic housekeeping jobs (using
RSPO0041) to delete old spools and prevent performance issues. - Consider system load: For resource-intensive reports, schedule the job during off-peak hours (e.g., overnight) to avoid impacting interactive users.