Skip to main content

Use IBM Database Add-Ins for Visual Studio 2005 to create, drop and add multiple versions of a native procedure on z/OS, Version 9.1

Working with native stored procedures using z/OS, Version 9.1

Vasantha Jayakumar (vasantha@us.ibm.com), Software Developer, IBM
Vasantha Jayakumar photo
Vasantha Jayakumar is an advisory software engineer at the IBM Silicon Valley Lab in San Jose. She has worked on several data management tools and currently works on developing tools for the various IBM servers on Visual Studio .NET.

Summary:  DB2® for z/OS Version 9.1 introduces support for creating native SQL procedures. With this support, it's no longer necessary to have a C program associated with each procedure. This article illustrates how stored procedure capabilities have been enhanced by this new support, and how you can support multiple versions concurrently. Learn how to use IBM® Database Add-Ins for Visual Studio 2005 to create a native procedure, add versions, activate different versions, and more!

Date:  01 Feb 2007
Level:  Intermediate
Activity:  683 views

Introduction

Prior to DB2 for z/OS V9.1, SQL procedures were all external. The body was written in SQL, and DB2 supported these procedures by generating and associating a C program for each procedure. Now, DB2 for z/OS V9.1 introduces support for creating native SQL procedures. The body of a native SQL procedure is written in SQL, but DB2 does not generate an associated C program for native procedures.

Native SQL statements usually provide better performance and support more functions than external SQL statements. Additionally, DB2 permits you to manage several versions of a native procedure. Hence several versions of native procedure can exist while only one version can be made the active version at any given time. This article describes in detail how to create a native procedure, add versions, and activate different version, using the IBM Database Add-Ins for Visual Studio 2005.

Prerequisites

This article assumes that you are accessing DB2 for z/OS V9.1.

You'll need the IBM Database Add-Ins for Visual Studio 2005. Get the Add-Ins in one of the following ways:

For an introduction to the IBM Database Add-Ins for Visual Studio 2005, please see the Resources section of this article.

Create native procedures in z/OS V9.1

To create a connection to a z/OS server, use the Add Connection option in the Server Explorer. When creating the connection, you can choose to specify a schema filter to refine the objects that will be visible in your connection. After creating a connection to the z/OS V9.1 server in the Server Explorer, choose the Procedures node in the tree and invoke the IBM Procedure Designer using the Add New Procedure with Designer Context menu option as shown in Figure 1:



Figure 1. Add new procedure with designer
Add New Procedure with Designer

While the designer allows creation of both external as well as native procedures, the default procedure type is native. To create external procedures, change the selection in the procedure type combo box to External. The z/OS options section applies only for external procedures, and therefore is enabled for external procedures only. It's disabled and automatically collapsed for native procedures. Figure 2 shows the various z/OS options. When a procedure is created for the first time, the default version ID used is V1, but the user can edit and change this ID in the version ID field. Various procedure attributes such as the debug mode for the procedure, the number of result sets, ASU time limit, and the Workload Manager (WLM) environment can be specified using the fields in the procedure definition section of the designer:



Figure 2. Procedure definition section
Procedure Definition section

You can add parameters for the procedure using the Procedure Parameters section. You can also choose to import parameters using the Import Parameters button, available in this section. You can edit the SQL body of the procedure using the SQL body section. To insert template code to create additional cursors with return, use the Context menu Insert SQL > Cursor with return options. This inserts the template code at the current cursor location.



Figure 3. Procedure parameters and SQL body sections
Procedure parameters and SQL body sections

Before saving the procedure, you can view the CREATE PROCEDURE Data Definition Language (DDL) that will be executed on the server once the procedure is saved. To see the CREATE PROCEDURE DDL, switch to the Show Script view of the designer. The Show Script allows a script header and a script trailer to be added. The SQL in the script header is executed prior to the script execution, and the SQL in the script trailer is executed after the script has been executed. Figure 4 shows the Show Script view and contains an example of a script that is generated for a native procedure.



Figure 4. Show Script view
Show Script View

To create the procedure on the database, choose the Save button or use the Visual Studio IDE menu. A status message on the execution operation is added to the Output View of the integrated development environment (IDE). On successful completion of the script execution, a node for the newly created procedure is added under the Procedures node in the Server Explorer.

Create external procedures in z/OS

To create external procedures using the IBM Procedure designer, change the selection in the procedure type combo box to External. The z/OS options section applies only for external procedures, and therefore is only enabled for external procedures. It is disabled and automatically collapsed for native procedures. Figure 4.1 shows the various z/OS options, which include the collection ID, external name, build options and runtime options:



Figure 4.1 z/OS Options for external procedures
z/OS Options for External Procedures

Create multiple versions of a native procedure

You can create and manage multiple versions of a native procedure, but only one procedure is considered the active version at any point. When a procedure is first created, the initial version is considered the active version. You can create and maintain several versions of a procedure concurrently, so that you can create a new version of a procedure while the original one still exists. You can create and test new versions of a native procedure, and it's easy to make a newer versions the active version. One advantage of this setup is that if you encounter problems with a newer version, you can always fall back to a previous version of a procedure by activating it. You can also delete any unwanted versions of a procedure.

To create a new version of an existing native procedure, select the native procedure in the Server Explorer tree and choose the Add New Version menu option as shown in Figure 5:



Figure 5. Add New Version option
Add New Version

When creating a new version of a native SQL procedure, you can modify the procedure body, procedure options and parameter names while all the other values of the procedure remain identical to the original procedure. The number of parameters, parameter data types and parameter type (IN, OUT, INOUT) have to be the same as that of the original native procedure in order to add a new version for a native procedure. If a change to any of these is required, you can create a new native procedure instead of creating a new version.

When adding a new version of a native procedure, certain fields and sections in the IBM Procedure designer are disabled since newer versions cannot differ in the values for these fields. An example of this is shown in Figure 6:



Figure 6. Add New Version for a native procedure
Add New Version for a native procedure

Initially when a native procedure is created, the DDL that is stored in the catalog for the procedure is the CREATE PROCEDURE script. All additional versions of a native procedure are created using the ALTER PROCEDURE DDL, and thus the catalog stores an alter script for all additional versions. Figure 7 shows an example of the ALTER PROCEDURE script generated and displayed in the designer's Show Script view in order to add a new version of a native procedure.



Figure 7. Alter procedure to add new version
Alter procedure to add new version

The version of the procedure that is currently active is displayed as the Main Procedure node. Any additional versions of a native procedure that are created are displayed under the Versions node of the respective procedure in the Server Explorer tree. In Figure 8, the active version of the UPDATE_BALANCE procedure is version V1, which is represented by the UPDATE_BALANCE node. An additional version (V2) was created for this procedure and is represented by the V2 node under the Versions node.



Figure 8. Versions of native procedures as shown in Server Explorer
Versions of native procedures shown in Server Explorer

Activate different versions of a native procedure

When multiple versions of a native procedure exist, any of the versions of the procedure can be made the active version by simply right-clicking on the specific version node and choosing the Activate Version menu option. In the example shown in Figure 9, version V2 of the procedure is chosen to be the active version. This is an example of the DDL executed in this case, when choosing this menu option:

ALTER PROCEDURE UPDATE_BALANCE
ACTIVATE VERSION V2;



Figure 9. Activating a version of a native procedure
Activating a version of a native procedure

Upon successful activation of the selected version of the native procedure, the nodes in the Server Explorer tree are automatically refreshed to reflect the changes in the active version. Now, the newly activated version (V2) is represented by the UPDATE_BALANCE node in the tree, and the previously active version (V1) is be represented by the node VI under the Versions node of the procedure, as shown in Figure 10:



Figure 10. Server Explorer refreshed to display the newly activated version of the native procedure
Server Explorer refreshed to display the newly activated version of the native procedure

Delete native procedures

Deleting a non-active version of a native procedure

To delete a specific version of a native procedure that is not the active version, right -click on the specific procedure version node in the tree and choose the Drop menu option. This causes the specific version of the procedure to be deleted from the database. Figure 11 shows a screenshot of the menu option used to delete a specific version of a native procedure:



Figure 11. Deleting a non-active version of a native procedure
Deleting a non-active version of a native procedure

When you want to delete a specific version of a native procedure, the following confirmation dialog is displayed, and the user can choose to either continue of cancel the deletion:


Figure 11.1 Confirmation dialog -- deleting a specific non-active version of a native procedure
Message on deleting a specific non-active version of a native procedure

Deleting an active version of a native procedure

If only a single version of a native procedure exists, by default that version of the procedure is the active version. Deleting an active version of a procedure will cause the active version as well as all additional versions of the procedure to be deleted. Figure 12 shows a screenshot of the menu option used to delete the active version of a native procedure:



Figure 12. Deleting an active version of a native procedure and all its versions
Deleting an active version of a native procedure and all its versions

When deleting the active version, the following confirmation dialog is displayed, stating that deleting the active version will cause all the other versions to be dropped, and the user is given the opportunity to either continue or cancel the operation:



Figure 12.1. Confirmation dialog -- deleting an active version of a native procedure
Message on deleting an active version of a native procedure

View DDL for native procedures

The CREATE DDL or the ALTER DDL (as applicable) can be viewed for the native procedures using the Show Script menu option available on the active procedure node, as well as additional procedure version nodes. The script displays the CREATE DDL for the first procedure that was created. For all additional versions created, the script displays the ALTER DDL that was used to create that specific version of the procedure.

Enable debugging for procedures

To enable debugging of a procedure, the procedure should be built on the server for debug. Debugging can be turned on and off easily using the Enable Debugging and the Disable Debugging menu options available on the procedure node as well as on the specific procedure node in the tree.

Run native procedures

You can run an active version of the native procedure by right-clicking on the active procedure node and choosing the Run menu option. By default, the active version of the procedure is used when running the procedure. To run a non-active version of the procedure, the active version would have to be temporarily overriden with the specific non-active version. In this case, you would run the procedure and then revert back the active version to point to the originally active procedure. The IBM Add-Ins handles all of this and simplifies this process. To run a non-active version of a procedure, the user simply right-clicks the specific version of the procedure and chooses the Run menu option.


Figure 13. Run procedures
Run procedures

Summary

The ability to create native procedures as well as create and manage multiple versions of a procedure is a very powerful feature introduced with z/OS Version 9.1. Native SQL statements usually provide better performance and support more functions than external SQL statements. Using IBM Database Add-Ins for Visual Studio 2005, you can use and exploit these newly introduced features with just a few simple steps, as detailed in this article. You can easily create native procedures, add and delete multiple versions of procedures, as well as activate and view DDL for the various versions. Debugging can also be easily turned on and off for procedures. Working with native procedures for z/OS Version 9.1 has become very easy with the IBM Database Add-Ins for Visual Studio 2005.


Resources

Learn

Get products and technologies

Discuss

About the author

Vasantha Jayakumar photo

Vasantha Jayakumar is an advisory software engineer at the IBM Silicon Valley Lab in San Jose. She has worked on several data management tools and currently works on developing tools for the various IBM servers on Visual Studio .NET.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Information Management
ArticleID=202327
ArticleTitle=Use IBM Database Add-Ins for Visual Studio 2005 to create, drop and add multiple versions of a native procedure on z/OS, Version 9.1
publish-date=02012007
author1-email=vasantha@us.ibm.com
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers