• Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,743
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
11
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Mainframe Express v2.5 - DB2 Stored procedures Mainframe Express (MFE) 2.5 SQL for DB2 Option supports the animation and execution of stored procedures running under the control of an XDB server accessing data on an XDB location. There is some very good documentation intended to provide a set of instructions for utilizing stored procedures in MFEMFSQLBINStoredp.htm. See MFEMFSQLBINreadme.sp for the stored procedure demo. Note ensure you have a user location (that is not system, tutorial or maintain). Existing Limitations to Stored Procedure Development with the an XDB Location 1. STOP RUN statements within a stored procedure will halt the SQL for DB2 Option server when they are animated. This only applies to animation. If the stored procedure is not being animated, the STOP RUN will have no effect on the server; it will be treated just like a GOBACK. This limitation will not be removed in the near future. However, it must be noted the IBM recommends that programmers writing stored procedures should avoid the use of STOP RUN. In the DB2 subsystem, a STOP RUN will terminate the Language Environment enclave. The next time a DB2 stored procedure is called, the Language Environment enclave will have to be rebuilt. This extra work being done by the DB2 region will severely impact the benefits of running the stored procedure as a DB2 subprogram. 2. Terminating the Animator that is animating a stored procedure will terminate the SQL for DB2 Option server. This restriction is due to the facilities available to the Animator. The Animator is allowed by the operating system to attach to the server process; it is unable to detach however. So by terminating the Animator the server is terminated as well. However, the user may debug the same stored procedure multiple times. If the Animator is left running attached to the server, a breakpoint may be set within the stored procedure. If the code that the breakpoint is set upon is executed when the stored procedure is executed again, the Animator will break the server process and allow debugging of the stored procedure again. 3. Currently, the VALIDATE preprocessor directive will provide minimal assistance with stored procedure SQL statements (CALL, ASSOCIATE, ALLOCATE). 4. No support is provided for performing a PREPARE statement using ALLOCATE CURSOR or ASSOCIATE LOCATORS syntax. ALLOCATE CURSOR and ASSOCIATE LOCATORS statements must be embedded within the SQL language EXEC SQL ... END-EXEC delimiters. ALLOCATE CURSOR and ASSOCIATE LOCATORS statements can not be dynamically prepared. Stored procedures with DB2 V6 Some background information about DB2 V6. IBM has changed the implementation of stored procedures. There are major differences between V5 and V6 implementations of a stored procedure. With V5, stored procedures are instantiated by inserting a record into the SYSIBM.SYSPROCEDURES table. With V6, stored procedures are instantiated with a CREATE PROCEDURE command that populates the SYSIBM.SYSROUTINES and SYSIBM.SYSPARMS tables with the stored procedure definition. In V6, the concept of schemas has been introduced with the inclusion of the SET CURRENT PATH statement to build a schema path. In V6, all stored procedures are defined with a schema (authid) and the schema path is used to identify which stored procedure is invoked. The schema path lists a set of schemas to be searched for the definition of the stored procedure when that stored procedure is invoked with a one part name. Additionally, the search relies on the number of arguments passed to the stored procedure so multiple stored procedures can be defined with the same name and differing numbers of arguments. In DB2 V5, stored procedures could only be called from a precompiled program. Page 1 of 4
  • 2. Mainframe Express v2.5 - DB2 Stored procedures In V6, with the advent of triggers, a stored procedure call can be performed outside of a program (as in a trigger). An XDB V6 server engine must have a V6 location so that it has the SYSIBM.SYSROUTINES and SYSIBM.SYSPARMS tables. A V6 server engine will look in SYSIBM.SYSROUTINES. A location created with a previous XDB engine will not contain the SYSIBM.SYSROUTINES and SYSIBM.SYSPARMS tables. An scenario relating to DB2 V6 stored procedure (programs not provided): CREATEP1.CBL performs the set up for the stored procedure. The client program that calls the stored procedure is CALLSTPR.CBL The actual stored procedure code is STPROC1.CBL. The stored procedure will return a result set that can be fetched by the client program. Triggers Also new in DB2 V6 IBM has introduced the concept of triggers. A trigger specifies an action to be taken when an event happens. The event can be INSERT, UPDATE, or DELETE. One trigger can be created for the entire table or multiple triggers can be created for one or more columns. The action can be one or more of the following statements: Full Select CALL SIGNAL SQLSTATE VALUES SET transition variable INSERT DELETE (searched) UPDATE (searched) These statements are defined within the CREATE TRIGGER statement between the BEGIN ATOMIC and END tokens. Triggers are defined to occur before and/or after the action. When the trigger occurs, the trigger can refer to the contents of the columns (before or after the action depending on the definition of the trigger). The column contents in the trigger are known as transition variables. There is also the concept of a transition table that is the full set of rows affected by the statement that invoked the trigger (transition tables are not support with XDB stored procedures today). An example of a trigger (programs not provided): To provide a World Cup information database. We want to keep track of player goals and team goals and we want separate tables for this task. This requires two tables - player and teams. When a player scores a goal will need to add a record for that player, with data and time. A trigger should be defined on the player table that will invoke a stored procedure after an insert into the player table. The stored procedure will then look up the team the player is on and update the team's record in the team table adding one to the total team goals scored. Page 2 of 4
  • 3. Mainframe Express v2.5 - DB2 Stored procedures The SETUP.CBL program will create the tables, trigger, and stored procedure definition and populate the tables with some data. The UPDTEAM.CBL program is the stored procedure that is invoked by the trigger. The DRIVER.CBL will insert a row invoking the trigger. The trigger can also be invoked by an INSERT statement from a tool like the SQLWizard [i.e., INSERT INTO PLAYER_GOAL VALUES ('David Beckham', CURRENT_TIMESTAMP)]. Additional Resources The full set of DB2 documentation for versions 4, 5, 6, and 7 can be found at the following link: http://www-3.ibm.com/software/data/db2/os390/library.html A discussion of how DB2 V6 uses the schema path to find the correct stored procedure to execute can be found at the following link: http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/dsnap0g3/7.2.7.1 A discussion of triggers within the DB2 V6 documentation can be found at the following link: http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/dsnap0g3/3.5 MFE customization for Stored Procedure support Action Comments 1 Define the Stored EXEC SQL Procedure. This can be CREATE PROCEDURE STPROC1 ( accomplished by issuing IN IN1 CHAR(4), the create procedure OUT OUT1 CHAR(4), command in SQL Wizard OUT RSLT SMALLINT ) EXTERNAL NAME STPROC1 or by embedding it a PARAMETER STYLE GENERAL COBOL application. NO COLLID LANGUAGE COBOL PROGRAM TYPE MAIN RESULT SET 1 NO WLM ENVIRONMENT COMMIT ON RETURN NO END-EXEC 2 Modify XDB.INI in Adding following lines mfuserconfig folderTo [SERVER] indicate to the SQL XDBSERVE=XDBLOCAL system that Stored XSRVCFG=d:mfuserconfig Procedure must be StProcLoadlib=D:Projectscargoloadlib;D:storedPLOADLIB animated and allow load StProcAnimate=Yes module localisation 3 Stored Procedure Remember animation.The Animation of a Stored Procedure 1. To animate each subsequent call to the Stored Procedure within will load a second this MFE session, you must set a breakpoint in the Stored session of MFE onto your Procedure during to the first execution or else subsequent call machine. will be RUN. 2. Do not modify the Stored Procedures source within this copy of MFE. This copy of MFE has no associated project and does not allow editing, compilation ... 5 Sample are shipped in Stproc.sql - add the stored procedure sysibm.sysprocedures the product Callstpr.cbl - program that calls a stored procedure Stproc1.cbl - sample stored procedure Page 3 of 4
  • 4. Mainframe Express v2.5 - DB2 Stored procedures Callstpr.tso - a tso clist to execute the calling program General background When you start XDB as a service, it runs in its own "environment" space, completely separate from MFE. Micro Focus has looked at ways to actually "invoke" the COBOL environment "inside" the service itself, but it does not work as expected, therefore you will need to do the following to run stored procedures If this is not done you will get SQLCODE=0 and will not be able to animate. You are running the XDB server as an NT service with MFE 2.5. Shut down the server with either the MFE menus or the Control Panel Icon. Then start an MFE command prompt from the Windows Start menu (Start -> Programs -> Mainframe Express 2.5 -> Mainframe Express Command Prompt) and then start the non-service server with the command XSRV40N. Alternately you can DISABLE the MFE XDB server in services, just start the server with MFE using start server This should allow you to get past the SQLCODE of zero and allow you to debug stored procedures. If you want second debugging: Either set a break point the first time into the stored procedure or close the second session of MFE and start XSRV40N.EXE again. Page 4 of 4