When background jobs are scheduled, a variant is a must. Keeping track of when your program last ran can be a must as well - why not combine the two !
Thus: your program needs to run twice a day, and it should only process the entries that have not been processed in the previous run. Of course when a batchjob is scheduled, it will start anytime (soon) after the scheduled time. Here's something I found very useful in several occasions:
Scenario
- A background job performs a task on a given selection
- The time and date (e.g. creation time and date) of the objects to be processed are available on the selection screen
- Via a variant the actual time and date (usually the cutoff moment) can be entered.
- If the ABAP program registers the last time and date on the variant itself, the next time the batch job will run it will know exactly where (with which cutoff settings) to start.
To do this the program needs to know which variant is used to schedule the job. Hence the variant name must be specified on the selection screen (if no variant name is specified, nothing will be updated). The advantage here is that a variant name on the selection screen with a bit of comment lines to explain how it works can "explain" the solution.
Building blocks
For the variant name on the selection screen, a check routine can be put in place. Use function module RS_VARIANT_EXISTS
for this task.
For the really fancy selection screen: you could set up F4 response on the variant field. Function module RS_VARIANT_LIST
or F4_REPORT_VARIANT
could be handy.
Performing an actual update on some of the fields on a variant can be done using function module RS_VARIANT_CONTENTS
to read the (all) current settings and function module RS_CHANGE_CREATED_VARIANT
to do exactly what the function module name implies.
An object oriented example demonstrates how this works. The example contains a re-usable LCL_VARIANT_UTILITY
class that can be copied into your own sources.
Nice detail: if you want to see when the program last ran, just fetch the variant. Even better: if you want the program to run "in between", run it with the same variant. The "last runtime registration" mechanism can be used in concordance with the scheduled background job !