TechTip: Speed Up SQL Procedures with Service Program Support

SQL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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
Kent Milligan is a Senior Db2 for i Consultant in the IBM Lab Services Power Systems Delivery Practice.  Kent has over 25 years of experience as a Db2 for IBM i consultant and developer working out of the IBM Rochester lab. Prior to re-joining the DB2 for i Lab Services practice in 2020, Kent spent 5 years working on healthcare solutions powered by IBM Watson technologies. Kent is a sought-after speaker and author on Db2 for i & SQL topics.
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: