Updation of Database Table On first day of every year using factory calendar as a Background job
Consider a batch job that needs to be run on 1st day of every year.
If you set it up using transaction SM36 as a repetitive batch job you see that the options provided do not match this requirement.
We can achieve this by creating a factory calendar then using the factory calendar option in SM36.
Let us see below how we configure these settings.
Create a new factory calendar that has one working day which is always the 1st day of year.
You use transaction SCAL to create factory calendars. Select the Factory calendar radio button and then click on the change icon.
Then ‘Change Factory Calender: Overview’ screen appear.
Press the left upper corner ‘Create’ button to create new factory calender
Then ‘Change Factory Calender Datails’ screen appears.
Insert Factory Calender Id as ‘ZL’ and description as “First day of every year’.
As we are going to use Special rules only, we don’t need to enter a holiday calendar.
Press Save and then click on “Special rules”.
In the next screen that appears enter the specific dates for which you want the calendar to be active.
Tick the Workday check box for these dates.
Press save and go back to Overview screen. Click on the Calendar button to see what these dates look like in a calendar format.
Double-click on a year to see the work dates in a calendar format. Workdays are highlighted in yellow on your screen and non-working days are in green.
Job scheduling in SM36:
Create a new job ZLMS_BACKGROUND_JOB and click on “Start condition
Press “Date/Time” .Insert proper starting date and time on which job sceduled.
Tick the Periodic job check box.
Click on the other period button one dialog box will appear .specify 12 months and press Save
Then click on “Restrictions” button. In the pop-up of Start date restrictions enter calendar id as ZL and
select Move job to next working day option which restricts the job.
Then press transfer to save the settings and go back to pop-up.
We can see the job planned start date is set to 01.01.2013(1st day of year) and frequency is set to yearly. Define the steps and complete the job set up by pressing save.
Then go to step button .It prompts us for program to be executed while executing a job.
First create a abap program in SE38 using following code.
DATA ITAB TYPE STANDARD TABLE OF ZLMS_EMP_MASTER.
DATA STRU LIKE LINE OF ITAB.
DATA TEMP TYPE ZLMS_EMP_MASTER-CASUAL_LEAVE.
SELECT * FROM ZLMS_EMP_MASTER INTO STRU.
TEMP = STRU-CASUAL_LEAVE – STRU-CASL_LEAVE_TAKEN.
IF TEMP >= 5.
STRU-CASL_ADJUSTMENT = 5.
STRU-CASL_LEAVE_TAKEN = 0.
TEMP = STRU-EARNED_LEAVES – STRU-ERND_LEAVE_TAKEN.
IF TEMP >= 5.
STRU-ERND_ADJUSTMENT = 5.
STRU-ERND_LEAVE_TAKEN = 0.
STRU-COMPENSATRY_LEAV = STRU-COMPENSATRY_LEAV – STRU-COMPNSTRY_LV_TKN.
STRU-COMPNSTRY_LV_TKN = 0.
STRU-LEAVE_WO_PAY = 0.
STRU-PATERNITY_LEAVE = 0.
STRU-MATERNITY_LEAVE = 0.
APPEND STRU TO ITAB.
MODIFY ZLMS_EMP_MASTER FROM TABLE ITAB.
After specifying Program name click ’save’ button. It redirect to step list overview page
Showing specified program as one entry in table.
Thus we have created Background Job to update table on 1st of every year.
On scheduled date and time each year Job runs means that ABAP program is execuuted without developers or the users intervention.