A new PTF makes it all so easy.
The use of DB2 for i stored procedures by IBM i developers is on the rise. With stored procedures entrenched in application environments, developers are quickly learning that an upgraded version of a stored procedure featuring new input parameters requires a number of coding changes to be made. All of the programs that invoke the stored procedure need to be modified to pass values for the new parameters.
With the delivery of Technology Refresh #5 for the IBM i 7.1 release, IBM i developers now have flexibility to minimize coding changes when deploying new versions of stored procedures. New default value support for parameters enables this flexibility. Default parameter values are supported for both SQL and external stored procedures. IBM plans to enable default parameter values for user-defined functions (UDFs) in a future release of the IBM i operating system.
This new ability to declare default parameter values enables developers to selectively choose which programs have to be modified to accommodate the new input parameters for a stored procedure. Deploying your upgraded stored procedures will go much faster when you can reduce the number of invoking programs that have to be changed.
Let's assume that the Generate_Claim stored procedure in Figure 1 was upgraded with two new parameters that allow the invoker to specify the department to process a claim and override the claim date.
CREATE OR REPLACE PROCEDURE Generate_Claim
(IN policyID CHAR(10),
IN claimDept CHAR(3) DEFAULT('45H'),
IN claimDate DATE DEFAULT CURRENT DATE)
LANGUAGE SQL
BEGIN
/* Logic goes here */
END;
Figure 1: Generate_Claim stored procedure
Once the upgraded version of the Generate_Claim procedure is deployed, existing programs will continue to work with the following SQL Call statement:
CALL Generate_Claim('AB12345678')
For this type of invocation, the stored procedure will use the default values of 45H and the current date during execution of the stored procedure.
If an invoker wanted to override the claim department, but not the claim date, the developer could use one of the following SQL Call statements to override the claims department while still using the default claim date value.
CALL Generate_Claim('AB12345678', '50A')
CALL Generate_Claim('AB12345678', '50A', DEFAULT)
This new support also makes it possible to override the claim date and still have the default value used for the claim department. This is done using the named parameter syntax shown in the following CALL statement. With named parameters, default values are used for any parameter that's not specified in the stored procedure invocation—in this example, that means the default value is used for the claim department input parameter.
CALL Generate_Claim('AB12345678', claimDate=>'10/12/2012')
The named parameter syntax can also be used to pass parameter values in any order. The freedom provided by this syntax means you should spend time thinking about coding conventions before employing this new support.
The default parameter support also provides dynamic default value capabilities by enabling a Select statement to provide the default value. This capability is really a carryover from the default support provided for the SQL Global Variable feature that was new with the IBM i 7.1 release. The following code demonstrates this dynamic default capability with a new version of the claimDept parameter. This new declaration generates a default value for the parameter by retrieving the department number for the department that is named 'US CLAIMS'.
IN claimDept CHAR(3) DEFAULT
(SELECT deptNum FROM departments WHERE deptName='US CLAIMS')
It should be easy to see that the new support for default parameter values provides developers with tremendous flexibility as they roll out new versions of their stored procedures. All you need to do now is simply load the IBM i 7.1 Database Group PTF level 19 onto your system to get started. All of the details on the new default parameter values support can be found in the IBM i 7.1 Information Center.
LATEST COMMENTS
MC Press Online