TechTip: Speed Up SQL Procedures with Service Program Support PDF Print E-mail
Tips & Techniques - SQL
Written by Kent Milligan   
Thursday, 07 August 2008 20:00

Support MC Press - Visit Our Sponsors

 

Forums Sponsor

 

 Popular Forums

POPULAR FORUMS

Forums

 

Search Sponsor
  
 

 Popular Searches

POPULAR SEARCHES

Search

With a recent V6R1 PTF, SQL stored procedures can now benefit from the improved performance offered by IBM i service program objects.

 

The usage of SQL stored procedures by IBM i applications and programs continues to rise. For quite awhile, applications have had the ability to leverage the performance benefits offered by IBM i service program objects.

 

With a recent V6R1 PTF, SQL stored procedures can now benefit from the improved performance offered by IBM i service program objects. When an SQL stored procedure is created, DB2 for i generates and creates an ILE C program object to implement the business logic specified by the programmer. For example, when the following procedure is created, it will result in DB2 generating an ILE C program object (*PGM) named ADD_PGM in the QGPL library.  Whenever an application invokes the ADD_PGM, DB2 will transparently call the generated C program object. 

 

CREATE PROCEDURE QGPL/ADD_PGM (IN p1 INT, IN n INT, OUT o1 INT)

LANGUAGE SQL

BEGIN

  DECLARE v1 INT;

  SET v1=ABSVAL(n);

  SET o1= p1+v1;

END;


With the V6R1 Database Group PTF #5 released in July 2008, programmers can now have DB2 generate ILE C service program objects instead. This capability is controlled with the new PROGRAM TYPE clause as shown in the following example. The PROGRAM TYPE SUB clause causes DB2 to generate an ILE C service program object (*SRVPGM) named ADD_SRVPGM in the QGPL library. If this clause is not specified, the default value is PROGRAM TYPE MAIN, which results in DB2 generating an ILE C program object. 

 

CREATE PROCEDURE QGPL/ADD_SRVPGM (IN p1 INT, IN n INT, OUT o1 INT)

LANGUAGE SQL

PROGRAM TYPE SUB

BEGIN

  DECLARE v1 INT;

  SET v1=ABSVAL(n);

  SET o1= p1+v1;

END;


The usage of a service program object will provide a small performance boost when the SQL stored procedure is called. No changes are needed to the applications that invoke the SQL stored procedure. The SQL stored procedure just needs to be re-created after the PROGRAM TYPE SUB clause is added.

 

You can find more information on the CREATE PROCEDURE statement syntax in the DB2 for i SQL Reference.


Kent Milligan
About the Author:

Kent Milligan is a Senior Technical Team Lead on the Emerging Technology Delivery team for the IBM Watson for Clinical Trial Matching solution. Prior to joining the Watson team in 2015, Kent spent the first 25 years of his career working as a DB2 for IBM i consultant and developer working out of the IBM Rochester lab.

 

 

Read Kent's "DB2 farewell" blog:

http://db2fori.blogspot.com/2015/06/time-for-new-challenge.html

 

Read More >>
Last Updated on Tuesday, 19 May 2009 11:35
 
User Rating: / 0
PoorBest 
   MC-STORE.COM