<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SAP Integration Experts - DataXstream &#187; batch job</title>
	<atom:link href="http://www.dataxstream.com/tag/batch-job/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dataxstream.com</link>
	<description>SAP Certified Consultants</description>
	<lastBuildDate>Tue, 31 Aug 2010 15:53:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>SAP Event Driven Batch Job</title>
		<link>http://www.dataxstream.com/2010/03/sap-event-driven-batch-job/</link>
		<comments>http://www.dataxstream.com/2010/03/sap-event-driven-batch-job/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 05:00:32 +0000</pubDate>
		<dc:creator>Steve Park</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[SAP ABAP Blog]]></category>
		<category><![CDATA[SAP ABAP Performance]]></category>
		<category><![CDATA[SAP Technical]]></category>
		<category><![CDATA[batch job]]></category>
		<category><![CDATA[SAP]]></category>
		<category><![CDATA[Steve Park]]></category>

		<guid isPermaLink="false">http://www.dataxstream.com/?p=3839</guid>
		<description><![CDATA[When creating SAP batch jobs to run a program, most of the scheduling can be accomplished by setting a periodic time for when the job is executed.  For example, execute the job every 10min, 30min, or 1 hour.  But what if you needed more control of when a batch job was executed? At one of [...]]]></description>
			<content:encoded><![CDATA[<p>When creating SAP batch jobs to run a program, most of the scheduling can be accomplished by setting a periodic time for when the job is executed.  For example, execute the job every 10min, 30min, or 1 hour.  But what if you needed more control of when a batch job was executed?</p>
<p><span id="more-3839"></span></p>
<p>At one of my clients they had a requirement to run a batch job every 5 minutes.  Sometimes the batch job would take longer than 5 minutes to complete.  Thus, the same program would start in a new batch job before the previous batch job had time to finish.  The same program would collide with itself and cause issues.</p>
<p>It seems that SAP&#8217;s built-in job scheduler does not have a standard way of preventing overlapping job executions.  I was hoping to find a checkbox that would deny an execution of a job if it finds the same active job running, but that would be too easy.  However, SAP does have some different options in its toolbelt to satisfy this requirement.  The approach that I will demonstrate will use an event-driven approach to execute a SAP batch job.</p>
<p>First I will detail the High level overview of what needs to happen.  Then, after you understand the big picture, then I will go into more detail about how to code and configure this scenario.</p>
<h2>High level Overview</h2>
<p>Basically 2 SAP batch jobs are needed:</p>
<p>1) SAP Job #1</p>
<ul>
<li>This job will execute every 5min or so depending on your requirment and execute a simple custom program that will check the status of Job #2.
<ul>
<li>If the status of job Job #2 is <strong>not </strong>running, then the custom program will raise an event</li>
<li>If the status of Job #2 is running, then the custom program will do nothing</li>
</ul>
</li>
</ul>
<p>2) SAP Job #2</p>
<ul>
<li>This job is setup to start only when an event is raised
<ul>
<li>If an event is Raised from Job #1 then Job #2 will start.  Job #2 will contain the actual programs that you need to execute.</li>
</ul>
</li>
</ul>
<p>Sound easy enough?</p>
<h2>Step-By-Step Instructions</h2>
<p>Now let’s get to business and see what configuration and coding we need to do.</p>
<p>1)      First let’s define an Event.</p>
<p>Transaction SM64 – I defined my event as Z_JOB_START_XXXXX</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-3850" title="pic1" src="http://www.dataxstream.com/wp-content/uploads/2010/01/pic1.png" alt="pic1" width="600" height="233" /></p>
<p style="text-align: center;">
<p style="text-align: center;"><img class="aligncenter size-full wp-image-3851" title="2" src="http://www.dataxstream.com/wp-content/uploads/2010/01/2.png" alt="2" width="599" height="122" /></p>
<p>2)     Next,  Create simple Custom program ZJOB_CREATE_EVENT to Raise the Event.   This program will basically check if the specified job is currently running.  If it is not running then Raise an event which was created in the previous step above.   In my case, I will  raise event ‘Z_JOB_START_XXXXX’.   Create a variant here with the Event Name(Z_JOB_START_XXXXX) and the Job #2 name (ZJOB_XXXXX).</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-3852" title="3" src="http://www.dataxstream.com/wp-content/uploads/2010/01/3.png" alt="3" width="554" height="636" /></p>
<p style="text-align: center;">3)      For Job #1.  Basically set this job as Periodic Time driven job to run every 5 minutes or so with the custom program ZJOB_CREATE_EVENT.  Also make sure you include the variant with the Job #2 name and Event.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-3853" title="4" src="http://www.dataxstream.com/wp-content/uploads/2010/01/4.png" alt="4" width="485" height="133" /></p>
<p>4)      For Job #2.  Define this job as an Event Driven batch job and define the actual program (I used test program ZSPTEST) that needs to be executed.  Specify the event Z_JOB_START_XXXXX that this job will be waiting for.  Also checkbox ‘Periodic job’ to schedule another event job.</p>
<p style="text-align: center;"><img class="aligncenter size-large wp-image-3854" title="5" src="http://www.dataxstream.com/wp-content/uploads/2010/01/5-856x1024.png" alt="5" width="599" height="717" /></p>
<p style="text-align: center;">
<p style="text-align: center;"><img class="aligncenter size-full wp-image-3855" title="6" src="http://www.dataxstream.com/wp-content/uploads/2010/01/6.png" alt="6" width="603" height="604" /></p>
<p>That’s it…Now the batch job will only execute if the same batch job is not running.</p>
<h2>Testing</h2>
<p>For testing purposes, I will demonstrate by manually execute program ZJOB_CREATE_EVENT to show that how this all works.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-3856" title="7" src="http://www.dataxstream.com/wp-content/uploads/2010/01/7.png" alt="7" width="606" height="357" /></p>
<p>The event ZJOB_START_XXXXX has been raised by program ZJOB_CREATE_EVENT.  Now you can see the ZJOB_XXXXX is Active/Running</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-3857" title="8" src="http://www.dataxstream.com/wp-content/uploads/2010/01/8.png" alt="8" width="391" height="145" /></p>
<p>During the time the job is active, I attempted to execute program ZJOB_CREATE_EVENT again.   This time, the program knows that the job is still active and, therefore, it does not raise the event.  The only time the event will be raised again is once the job is finished .</p>
<p>This is only one scenario in where an event driven batch job is needed.  Now you can see how you can utilize an event driven batch job to put some control around how some programs are executed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dataxstream.com/2010/03/sap-event-driven-batch-job/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Discovering Something Old in SAP &#8211; Using an External Program as a Batch Job Step</title>
		<link>http://www.dataxstream.com/2009/10/sapusing-an-external-program-as-a-batch-job-step/</link>
		<comments>http://www.dataxstream.com/2009/10/sapusing-an-external-program-as-a-batch-job-step/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 04:00:15 +0000</pubDate>
		<dc:creator>Mike Salvo</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[SAP Basis Blog]]></category>
		<category><![CDATA[SAP Interface Blog]]></category>
		<category><![CDATA[SAP Technical]]></category>
		<category><![CDATA[ABAP]]></category>
		<category><![CDATA[batch job]]></category>
		<category><![CDATA[batch script]]></category>
		<category><![CDATA[external program]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[Mike Salvo]]></category>
		<category><![CDATA[SAP]]></category>
		<category><![CDATA[SAP ABAP]]></category>
		<category><![CDATA[SM36]]></category>
		<category><![CDATA[SM37]]></category>
		<category><![CDATA[UNIX script]]></category>

		<guid isPermaLink="false">http://www.dataxstream.com/?p=2762</guid>
		<description><![CDATA[Occasionally, I have the opportunity to utilize a feature in SAP that I have never used before.  It is not necessarily a new feature, and it may have existed in SAP for several releases.  There are several reasons for ignoring new functionality, but the primary reason that comes to mind is “I’ve always done it [...]]]></description>
			<content:encoded><![CDATA[<p>Occasionally, I have the opportunity to utilize a feature in SAP that I have never used before.  It is not necessarily a new feature, and it may have existed in SAP for several releases.  There are several reasons for ignoring new functionality, but the primary reason that comes to mind is “I’ve always done it this way, I’ve installed hundreds of these, and I know it works”.</p>
<p>Sometimes, a special business or security requirement does not permit the “business as usual” scenario.  It is these situations which nudge me down the path which I have never explored.</p>
<p><span id="more-2762"></span></p>
<p>Take, for example, a simple flat file interface outbound from SAP to an external system.  In the typical scenario, at the 50,000 foot level, it works like this:</p>
<p>In a scheduled batch job step, an SAP ABAP program extracts data and creates a flat file in a folder somewhere on the network that is commonly visible to both SAP and the external system.</p>
<p>The external system acquires the flat file, processes the data and then archives the file, just in case we need to play “where is my data” or “I sent it, why didn’t you get it”.</p>
<p>Here is the process diagram:</p>
<p><img class="aligncenter size-full wp-image-2637" src="http://www.dataxstream.com/wp-content/uploads/2009/10/1-simple-flat-file-interface2.jpg" alt="Simple flat file interface" width="456" height="479" /></p>
<p>In this scenario, OS administrators on both sides of the interface have agreed to grant to the common folder all of the permissions needed so that each side of the interface can perform its tasks.</p>
<p>But what if that is not the case?  What if the external system administrator cannot permit a common SAP/external system mount; but will permit receiving the file via ftp?</p>
<p>Let’s redraw the process diagram:</p>
<p><img class="aligncenter size-full wp-image-2639" src="http://www.dataxstream.com/wp-content/uploads/2009/10/2-flat-file-interface-via-ftp.jpg" alt="2 flat file interface via ftp" width="441" height="693" /></p>
<p>In this scenario, SAP drops the output file into its own outbound network OS folder.
The file is then moved to an inbound network folder on the external system via an ftp script.</p>
<p><span style="background-color: #ffffff;">The question now becomes, how do we execute the ftp script after the first step of the batch job which creates the outbound data file? </span></p>
<p>It turns out that SAP provides a facility to do just that.  Effectively, SAP will allow the ftp script to be entered as a step in a batch job.</p>
<p><span style="background-color: #ffffff;">We begin to assemble our batch job with <strong>SM36</strong> as usual.</span></p>
<p>As shown here, the batch job is named <strong>Z_OUT_INTERFACE_2_EXTERNAL_SYST</strong>.</p>
<p><img class="aligncenter size-full wp-image-2645" src="http://www.dataxstream.com/wp-content/uploads/2009/10/3-define-background-job.jpg" alt="3 define background job" width="599" height="380" /><span style="background-color: #ffffff;">The first step of the batch job executes ABAP program <strong>Z_OUT_MATERIAL_EXTRACT</strong> with variant <strong>PRODUCTION_VAR. </strong></span></p>
<p>This is the step which creates the outbound data file.</p>
<p><img class="aligncenter size-full wp-image-2646" src="http://www.dataxstream.com/wp-content/uploads/2009/10/4-step-list-overview.jpg" alt="4 step list overview" width="558" height="145" /></p>
<p>Once the file is created by the ABAP program in step 1, we would like an ftp script to execute, and copy the file to a folder on the remote system.
SAP allows an <strong>external program</strong> (e.g. our ftp script) to be executed as a batch job step.  We are going to  make this step 2 in our job.
(This is the section of batch job land which I had never before explored.)
To set up an external program as an SAP batch job step, click the <strong>External Program</strong> button.
The External program block is now open for input.</p>
<p><img class="aligncenter size-full wp-image-2647" src="http://www.dataxstream.com/wp-content/uploads/2009/10/5-create-ext-prog-step.jpg" alt="5 create ext prog step" width="586" height="611" />
In the <strong>Name</strong> <strong>box</strong>, enter the complete path name of the location of the external program.
In this case, our external program is an ftp script which takes two input parameters:
1) The complete pathname of the data file.
In this example, the complete pathname is <span>/data/dx1/ftpscript.ksh</span>.
2) The path name and the name of the outbound data file.
In this example, the path name of the outbound data file is /data/dx1/interfaces/materials/outbound,
and the name of the outbound data file is materials.txt.
Both of these parameters are entered in the <strong>Parameter box</strong>.</p>
<p><img class="aligncenter size-full wp-image-2648" src="http://www.dataxstream.com/wp-content/uploads/2009/10/6-ext-prog-name-and-parameters.jpg" alt="6 ext prog name and parameters" width="560" height="106" /></p>
<p>SAP also allows for the external program standard output or error output to be displayed in the SAP job log.
These are turned on/off using control flags.</p>
<p><img class="aligncenter size-full wp-image-2649" src="http://www.dataxstream.com/wp-content/uploads/2009/10/7-control-flags-button.jpg" alt="7 control flags button" width="572" height="613" /></p>
<p>In this example, I have turned on the control flags which allow any standard output and error output from the external program to be displayed in the SAP job log.  I have also set the control flag which requires that the external program complete before the SAP job ends.  If this control flag is not set and there are no further job steps, the SAP job will complete without waiting for the external program.</p>
<p><img class="aligncenter size-full wp-image-2650" src="http://www.dataxstream.com/wp-content/uploads/2009/10/8-control-flag-settings.jpg" alt="8 control flag settings" width="330" height="217" /></p>
<p>Here is the entire SAP batch job with two job steps.
The first step is the ABAP program which creates the outbound data file.
The second step is the ftp script which will ftp the file to the external system.
This is the result that we want.</p>
<p><img class="aligncenter size-full wp-image-2651" src="http://www.dataxstream.com/wp-content/uploads/2009/10/9-job-with-two-steps.jpg" alt="9 job with two steps" width="620" height="117" /></p>
<p>And, for all of you SAP documentation fans, yes, this is documented in SAP.  This documentation describes the external command and external program facilities, as well as the authorizations needed to utilize them.</p>
<p>SAP Documentation about using External Commands and External Programs as batch job steps can be found at:<a href=" http://help.sap.com/saphelp_nw70/helpdata/EN/c4/3a7f2c505211d189550000e829fbbd/content.htm" target="_blank"> http://help.sap.com/saphelp_nw70/helpdata/EN/c4/3a7f2c505211d189550000e829fbbd/content.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dataxstream.com/2009/10/sapusing-an-external-program-as-a-batch-job-step/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
