Home
Blog
About
Database administration
Operating systems
Development
Links


Following require login:
ScratchPad



Locations of visitors to this page


Table of Contents

April 2012

2012-04-11

Scheduling background jobs in SAP

The scheduler supplied by SAP is capable of time and event based scheduling.
Time based scheduling can be described as basic, it can not, for example, schedule a job that runs every 15 minutes on every work day between 10a.m. and 4:45p.m.
We are in the middle of a SAP implementation and had a need for a scheduler that could schedule such a job.
Our implementation consultants suggested we add ABAP code to each job to handle this requirement.
Going forward that was obviously not going to be a workable solution for us - although it would have worked for them as no doubt additional invoices to us would have been involved.

Anyway, as a (probably) short term measure we have created an event and associated that event with our job.
We then use sapevt to trigger the event with sapevt being scheduled via the SAP instance owner cron on the central instance server.

sapevt requires two parameters:

  1. The event name you want to trigger
  2. The full path to the default profile

Our reading of the documentation suggests that sapevt can be run from any user.
In our environment LD_LIBRARY_PATH is rarely configured correctly; if it isn't then sapevt will return an error similar to:

Could not open the ICU common library.
   The following files must be in the path described by
   the environment variable "LD_LIBRARY_PATH":
   libicuuc.so.30, libicudata.so.30, libicui18n.so.30 [nlsui0.c 1610] pid = 32715

Our first attempt at a crontab entry looked similar to this:

# Local SAP system ID
SYSTEMID=R31
# NB: Required to run sapevt (your path may vary)
LD_LIBRARY_PATH=/sapmnt/${SYSTEMID}/exe
#
00,15,30,45 10-16 * * 1-5 /usr/sap/${SYSTEMID}/SYS/exe/run/sapevt <event name> pf=/sapmnt/${SYSTEMID}/profile/DEFAULT.PFL

Sadly, sapevt doesn't generate any output so there was no way (at least none I could find) of checking to make sure the event was being triggered.
Our solution was a simple shell script that logged it's start and finish and it looked something like this:

#!/bin/bash
#
# Trigger SAP event
# Scheduled via cron
#
# 2012-03-13    Initial version
#

# MAIN

{
# Setup the environment parameters
[ $# -ne 2 ] && { echo "ERROR: Usage trigger_sap_event SID Event"; exit 1; }
DbSid=$1
SapEvent=$2

[ ! -x /usr/sap/${DbSid}/SYS/exe/run/sapevt ] && { echo "ERROR: Cant find sapevt"; exit 1; }

LD_LIBRARY_PATH=/sapmnt/${DbSid}/exe

ret=0
echo "Trigger event, starting at `date`"

/usr/sap/${DbSid}/SYS/exe/run/sapevt $SapEvent pf=/sapmnt/${DbSid}/profile/DEFAULT.PFL

echo "Triger event, complete at `date`"

} > /tmp/trigger-sap-job-cron.log 2>&1

exit $ret

Our crontab now looks like this:

# Local SAP system ID
SYSTEMID=R31
# NB: Required to run sapevt (your path may vary)
LD_LIBRARY_PATH=/sapmnt/${SYSTEMID}/exe
#
00,15,30,45 10-16 * * 1-5 /home/r31adm/trigger_sap_event ${SYSTEMID} <event name>

This has been working reliably for a while now although there are some minor disadvantages.

  • The SAP scheduler only wakes up once per minute so the actual job start time may differ from the start time in crontab.
  • A separate event and crontab entry is required for every job scheduled this way.
    This could rapidly become a maintenance problem so this form of scheduling should be reserved for jobs that cannot be scheduled via SAP.

2012-04-19

Did you know #8

We have a lot of Windows servers which we, as a team, need to log on to fairly regularly.
It often happens that you try to connect to a server only to find that the default two RDP connections are both in use.
As we are a global team it can sometimes be time consuming to find who is logged on.

There is a simple way, e.g.(on Windows XP Pro SP 3)

[39]: QWINSTA /server:[servername]
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 services                                    0  Disc
 console                                     2  Conn
                   user1                     3  Disc
 rdp-tcp#2         user2                     4  Active  rdpwd
 rdp-tcp                                 65536  Listen

Given that you now know the session ID of the logged in user you can log their session off:

RWINSTA /server:[servername] [sessionid]

Check with them before you do that though!


Copyright HandyDBA 2012