IBM Destination Z - Group home

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

By Destination Z posted Mon December 23, 2019 03:30 PM

  

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
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.
        RUNSTATS
                           
   
   
   
   
   
    onclick="loadFeeds(document.getElementById('database').value,
                       document.getElementById('tablespace').value)">
         

    • 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 = $('
  • ').text(resultSet[i].SEQNO);
  •                 var TEXT = $('
    ', {
                            '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.