SAP HANA XS JOBS – Part 3
Welcome to the Part-3 tutorial on SAP HANA XS Jobs. In the Part-1 tutorial, we have already learn what an XS Job is and why it is used. In Part-2, we learnt the pre-requisite configuration files needed for SAP HANA XS development artifacts to exist. Be sure to check them out before reading this one. In tutorial, we show you how to create a job file.
Firstly, let’s take a moment to revisit the stored procedure we created in our previous tutorial Stored Procedure.
Double click on it to open the code
The functionality has already been explained in detail. The important thing to note here is that there is an input parameter here by the name of P_MATERIAL and the procedure would need this value as input from the XS JOB whenever it is called.
The result of a call to this procedure should be that the SALES_LOG table would become filled with the sales details of the material number provided by the input parameter P_MATERIAL.
Let’s check the data currently in sales log table before we build our XS JOB by using a simple SELECT statement SELECT tutorial
Press F8 or the execute button.
The result below shows that currently, the sales log table has no data.
Now, we create the SAP HANA XSJOB. Right click on your package and navigate to New Other
Search for XS Job Scheduler or find it in the “Application Development” folder as shown below.
Click “Next” to continue.
Provide a file name to the job and make sure to keep the Template setting to Basic (which is the default setting). Using “Basic” templates help us save time in writing codes as the skeleton of the code gets auto-created by SAP HANA.
As seen below, I named the job as Procedure_Job ( It seems I lack creativity in naming things but… it will do for now).
Press finish.
The default code for the “Basic” template is provided by HANA as shown below.
The parts of code enclosed in the red outlines need to be modified as per our requirement.
Let’s understand this line by line.
Line 2: description : This is the description you give for this Job.
Line 3: action : Here you provide the Stored Procedure or XSJS function name which you wish to run. The name must be complete with the package path prefixed to it.
Line 4: schedules : This block contains the properties of the schedule frequency.
Line 6: description : This is the description of the job frequency.
Line 7: xscron : This provides the frequency of the job. Refer the below table for details.
Xscron Field (* from left to right) | Meaning and Permitted Value |
Year | 4-digit, for example, 2013 |
Month | 1 to 12 |
Day | -31 to 31 |
DayofWeek | mon,tue,wed,thu,fri,sat,sun |
Hour | 0 to 23 |
Minute | 0 to 59 |
Second | 0 to 59 |
Credits: The above table is provided by SAP at this link.
Line 8:parameter : This section should assign input parameters to the values that we wish to pass to the logic
Remember that the below code is not SQL and hence even the string values are enclosed in double quotes “ “ instead of single quotes.
The code was modified as per our scenario as shown below.
Line 2: Description of the job is now Sales log load Job
Line 3: Action is to run the sales_procedure stored procedure under the 0TEACHMEHANA package.
Line 6: Description of the frequency is “Run every 1 hour”
Line 9: The input parameter P_MATERIAL is being assigned the value “CM_WHEAT”. This value would be passed down to the stored procedure for execution.
Activate once done by pressing the activate button shown below.
Now, your xsjob would be available in active version as shown below.
It’s quite a simple procedure and HANA does most of the codes for you. All you need to do is change the sample values given and punch in the values you need as per your scheduling requirement.
I hope that I made it simple enough for a beginner to understand SAP HANA XS jobs.
Join us for our next tutorial where we learn how to schedule this xsjob.
Leave your comments below on how you fared in creating your own SAP HANA XS Jobs and make sure to share this tutorial across social media. Subscribe to our newsletter when it pops up for updates on our newest additions.
If you feel the website helped you, please also contribute any small amount by using the “Donate button” on the right side of this page to help with the operational costs of this website and other systems involved.
Stay hungry.. stay motivated. Adios!