Print Email

Build an IBM DB2 for z/OS Mobile Application With a Stored Procedure

Part three: Using a stored procedure to execute RUNSTATS

2/17/2016 12:55:14 AM | This is part three of a three-part series on building an IBM DB2 for z/OS mobile application by using IBM MobileFirst. Read part one and part two.

In this post, we'll show how to use a stored procedure to call a standard DB2 for z/OS utility, RUNSTATS, from within a mobile app. You can apply the steps in this post to call other DB2 for z/OS utilities as well.

Before you begin, complete parts one and two of this tutorial.

1. Follow the instructions in step one of part two of this tutorial to create a new IBM MobileFirst project and to create a new hybrid application called Runstats.
2. Create an SQL adapter for the Runstats project called RunstatsSQLAdapter.
3. Edit RunstatsSQLAdapter.xml add add these definitions:

  • Add zserveros as dataSource JNDIName or whatever Java Naming and Directory Interface (JNDI) name you defined in server.xml
  • Add <procedure name="runstatSP1"/>
4. Edit RunstatsSQLAdapter-impl.js to implement runstatSP1. Call a procedure called SYSPROC.DSNUTILS using WL.Server.invokeSQLStoredProcedure()and pass in the parameters. Part of its implementation is:

function runstatSP1(database, tablespace) {
   var utilityStatement = "RUNSTATS TABLESPACE " + database + "." + tablespace
                           + " UPDATE(ALL)";
   utilityStatement = utilityStatement.toString();
   return WL.Server.invokeSQLStoredProcedure({
       procedure : "SYSPROC.DSNUTILS",
       parameters : [123456789,
                     "RUNSTATS TABLESPACE",

5. Implement the front end (client side) like part two of this tutorial. See steps one to three of part two for details.

  • In index.html, add two inputs: one for the database and one for the table space.
<div data-role="content" style="padding: 15px">
<!--application UI goes here-->
   <label for="text">Database:</label>
   <input type="text" name="text" id="database">
   <label for="text">Tablespace:</label>
   <input type="text" name="text" id="tablespace">
   <input type="button" value="Submit" src="js/main.js"
<div id="wrapper">
          <ul id="itemsList"></ul>

  • Modify main.js to use the result after invoking runstatSP1
function loadFeeds(db, ts){
        WL.Logger.debug("Inside loadFeeds");
        WL.Logger.debug("Inside loadFeeds: db= " + db);
        WL.Logger.debug("Inside loadFeeds: ts= " + ts);;
        // case database and tablespace to uppercase because DB2 objects are case insensitive
        // otherwise RUNSTATS will not find it
        db = db.toUpperCase();
        ts = ts.toUpperCase();
        var invocationData = {
                        adapter : 'RunstatSQLAdapter',
                        procedure : 'runstatSP1',
                        parameters : [db, ts]
                onSuccess : loadFeedsSuccess,
                onFailure : loadFeedsFailure
function loadFeedsSuccess(result){
        WL.Logger.debug("Feed retrieve success");
        if (result.invocationResult.resultSet.length>0)
function displayFeeds(resultSet){
        WL.Logger.debug("displayFeeds now.....");
        var ul = $('#itemsList');
        for (var i = 0; i < resultSet.length; i++) {
                var li = $('<li/>').text(resultSet[i].SEQNO);
                var TEXT = $('<div/>', {
                        'class': 'TEXT'

Figure 1 shows what your application will look like in an Android emulator.

Figure 1: View in Android Emulator

Now that you've learned how to use a stored procedure to call RUNSTATS, you can apply this knowledge to incorporate other DB2 for z/OS utilities into your mobile apps.

More Resources

This series of tutorials gives a glimpse at the capabilities of using IBM MobileFirst Platform to leverage the value of your DB2 for z/OS transactional data.

Learn more about working with DB2 for z/OS data in mobile environments by checking out the following resources:

IBM MobileFirst 7 Developer Edition
• Learn more about Native Android Development
• Check out the JavaScript SQL Adapter
• Visit the Knowledge Center to learn more about SYSPROC.DSNUTILS
• The Information Management area on developerWorks provides resources for architects, developers and engineers
• Stay current with developer technical events and webcasts focused on a variety of IBM products and IT industry topics
• Follow developerWorks on Twitter
• Watch developerWorks demos ranging from product installation and setup demos for beginners, to advanced functionality for experienced developers.
• Get involved in the developerWorks Community. Connect with other developerWorks users while you explore developer-driven blogs, forums, groups and wikis.

Jane Man is a Senior Software Engineer in DB2 for z/OS development.
Eric G. Radzinski is a content developer in DB2 for QMF, IBM Analytics.
Join Now!
Buy One SQL, Get One Free

Buy One SQL, Get One Free

Simplify SQL statements by writing them to perform more than one operation.

Read more »

Blockchain for IBM Z

Blockchain for IBM Z

When blockchain first emerged as the next big thing, it arrived as the technology behind bitcoin. At that time, blockchain was an x86 phenomenon. Today it has moved to Linux and runs on multiple platforms, including IBM Z and LinuxONE. From the start, blockchain naturally benefitted from the legendary scalability, reliability, security and flexibility of Z.

Read more »