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,
                     "",
                     utilityStatement,
                     "",
                     "RUNSTATS TABLESPACE",
                     "",
                     "",
                     0,
                     "",
                     "",

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-->
        RUNSTATS
</div>
                           
   <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"
    onclick="loadFeeds(document.getElementById('database').value,
                       document.getElementById('tablespace').value)">
<div id="wrapper">
          <ul id="itemsList"></ul>
</div>

  • 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);
        busyIndicator.show();
       
        // 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]
        };
        WL.Client.invokeProcedure(invocationData,{
                onSuccess : loadFeedsSuccess,
                onFailure : loadFeedsFailure
        });
}
 
function loadFeedsSuccess(result){
        WL.Logger.debug("Feed retrieve success");
        busyIndicator.hide();
        if (result.invocationResult.resultSet.length>0)
                displayFeeds(result.invocationResult.resultSet);
        else
                loadFeedsFailure();
}
 
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'
                }).text(resultSet[i].TEXT);
 
                li.append(TEXT);
               
                ul.append(li);
        }
}

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.

Please sign in to comment.

Sign In


Jane
Hi glenn_gail, I recommend you to work with your IBM representative to determine which new workloads would qualify for MWP.
5/26/2016 4:00:16 PM
glenn_gail
By running runstats from your mobile device does the workload qualify for mobile workload pricing discounts?
3/11/2016 10:16:04 AM
Join Now!
Coupling Technology: What’s Right for Me?

Coupling Technology: What’s Right for Me?

Desired outcome and choices help determine setup for coupling technology.

Read more »

Addressing the IT Skills Shortage

Addressing the IT Skills Shortage

Despite predictions of doom and gloom, collaborative efforts among businesses, universities, vendors and independent industry organizations will forestall any IT skills shortfall.

Read more »