MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DB2 Stored Procedure and DB2 Catalog

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
manojagrawal
Beginner


Joined: 25 Feb 2003
Posts: 124
Topics: 29

PostPosted: Thu Apr 15, 2004 2:20 pm    Post subject: DB2 Stored Procedure and DB2 Catalog Reply with quote

When calling Stored Procedures running in a SPAS environment from a remote location, what is the necessity and the use of a DB2 Node, DB2 Catalog and Schema Name?

How can these be determined?

Is DB2 Node the same as the Location? That which is displayed on the QMF Screen as "Connected to ...."

Edited to add:
Also, to call the Stored Procedure, do we have to insert a row into SYSIBM.SYSPROCEDURES? I have used the CREATE PROCEDURE and GRANT EXECUTE and thus was thinking that inserting into SYSPROCEDURES would be wrong. Any advice? Also does the userid have to have SELECT access to the SYSPROCEDURES table??? Thanks!
_________________
Thanks & Regards,
Manoj.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Thu Apr 15, 2004 3:31 pm    Post subject: Reply with quote

Manoj,

You can Invoke a stored procedure basically Using the SQL statement CALL. Let us say your stored procedure name is SP1

The simplest form of a CALL statement looks like this:
Code:

     EXEC SQL CALL SP1 (INPUT-PARM, OUT-RESULT);



Now let us take a case where SP1 is in schema SCHEMAA at remote location LOCA. To access Sp1, you could use either of these methods:

1.Execute a CONNECT statement to LOCA and then execute the CALL statement:
Code:

CONNECT TO LOCA;
EXEC SQL CALL SCHEMAA.SP1 (INPUT-PARM, OUT-RESULT);


2.Specify the 3-part name for SP1 in the CALL statement:
Code:

EXEC SQL CALL LOCA.SCHEMAA.SP1  (INPUT-PARM, OUT-RESULT);


The advantage of using the second form is that you do not need to execute a CONNECT statement. The disadvantage is that this form of the CALL statement is not portable to other platforms.

Quote:

Is DB2 Node the same as the Location? That which is displayed on the QMF Screen as "Connected to ...."


No DB2 Node is different from location name. Location is the unique name of a database server. An application uses the location name to access a DB2 database server.

LU (logical unit name) is what vtam refers to a NODE in a network.

You can find the information regarding schema in the catalog table SYSIBM.SYSROUTINES table

check this link for DB2 catalog tables from where you can find more info.

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQH10/D.0?DT=20010215120247

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
manojagrawal
Beginner


Joined: 25 Feb 2003
Posts: 124
Topics: 29

PostPosted: Thu Apr 15, 2004 3:42 pm    Post subject: Reply with quote

Hello Kolusu,

Thanks for the quick reply. However, I am unable to get how to determine the DB2 Node and the DB2 Catalog. Is there a way to do this? I guess the catalog tables is different from the DB2 Catalog, as I am being asked for the DB2 Catalog Name by the team trying to connect to the Stored Procedure. The catalog tables would be the same through all installations of DB2.

What is the use of the Node when calling a stored procedure. As you mentioned above, they would use the location.

Also, as I added in the Edited version, do you have an idea on this. To call the Stored Procedure, do we have to insert a row into SYSIBM.SYSPROCEDURES? I have used the CREATE PROCEDURE and GRANT EXECUTE and thus was thinking that inserting into SYSPROCEDURES would be wrong. Any advice? Also does the userid have to have SELECT access to the SYSPROCEDURES table???

Thanks once again for your help.
_________________
Thanks & Regards,
Manoj.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Fri Apr 16, 2004 5:12 am    Post subject: Reply with quote

Manoj,

Quote:

I guess the catalog tables is different from the DB2 Catalog, as I am being asked for the DB2 Catalog Name by the team trying to connect to the Stored Procedure. The catalog tables would be the same through all installations of DB2.


I am not really sure as to what you meant by DB2 catalog. But I don't think you need any of catalog tables when trying to connect to stored procedure. The DB2 system catalog tables(prefixed sysibm) are the same through all installations of DB2.

Quote:

Also, as I added in the Edited version, do you have an idea on this. To call the Stored Procedure, do we have to insert a row into SYSIBM.SYSPROCEDURES? I have used the CREATE PROCEDURE and GRANT EXECUTE and thus was thinking that inserting into SYSPROCEDURES would be wrong. Any advice? Also does the userid have to have SELECT access to the SYSPROCEDURES table???


You must define your stored procedure to DB2. DB2 Versions 4,5,6 use the SYSIBM.SYSPROCEDURES table to keep information about stored procedures.If you are using DB2 Version 7 then it is sysibm.sysroutines. DBA at your shop usually does the addition of the row into these tables. Every stored procedure must have at least one row in the SYSIBM.SYSPROCEDURES table. When DB2 receives an SQL CALL statement, it searches for information about the stored procedure in the SYSIBM.SYSPROCEDURES catalog table.

DB2 uses the information in the SYSIBM.SYSPROCEDURES table to:

  • Obtain the load module name associated with the stored procedure name, authorization ID, and LU name
  • Verify the parameters required by the stored procedure
  • Validate the parameters supplied by the calling application
  • Perform data conversion for the parameters when required DB2 for MVS/ESA
  • Specify run-time options for LE/370


Here are the basic steps in creating a stored procedure.

  • Write a stored procedure program in language of choice (C, Cobol, PL/I, Assembler)
  • Write the calling application program in language of choice.
  • Bind a package for the stored procedure.
  • Bind a package or plan for the calling application.
  • Define the stored procedure in the catalog table SYSIBM.SYSPROCEDURES.


Regarding the authorization to access the sysprocedure table, it varies from shop to shop. At my shop we use DB2V7 , I can browse sysprocedures tables but not the sysroutines table. So give it a try and see if you get a -551 which means that you are not authorized.

I would recommend you to go thru this excellent redbook which explains in detail about Getting Started with DB2 Stored Procedures

http://www.redbooks.ibm.com/redbooks/pdfs/sg244693.pdf

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
manojagrawal
Beginner


Joined: 25 Feb 2003
Posts: 124
Topics: 29

PostPosted: Thu Apr 22, 2004 10:02 am    Post subject: Reply with quote

Hi Kolusu,

Thanks for your extensive explanation. A few of the issues have now been resolved.

When the people trying to connect to our database asked for the DB2 Catalog, we were confused like above, and we could not understand what they wanted. It turned out that we did not need to give them any information and it was the catalog they would create to connect to our database.

Quote:

db2 "catalog tcpip node XXXX remote XXX.YYY.COM server 5000 remote_instance db2 ostype mvs with 'ABCD T'";
db2 "catalog dcs db YYYY as Location parms ',,INTERRUPT ENABLED' with 'ABCD T'";
db2 "catalog db YYYY as ZZZZ at node XXXX authentication dcs with 'ABCD T'";
db2 "connect to ZZZZ user username using ????;


I am yet to get feedback if they could call the SP or not.

What I could not gather is this... When i do a "CREATE PROCEDURE" it creates a row in sysroutines, but does it also create a row in sysprocedures??? I do not have access to both these tables. We are using DB2 V7 and thus what I was thinking is, does the user id executing the stored procedure need access to the sysprocedures table. The reason im asking this is because you had mentioned above that
Quote:
When DB2 receives an SQL CALL statement, it searches for information about the stored procedure in the SYSIBM.SYSPROCEDURES catalog table.
and as the executing user id does not have access to this table, would it succeed.

I am towards the inclination that if we use the CREATE PROCEDURE statement, then we would NOT have to manually/separately insert rows into any table. However I am un-sure whether the executing user id should have read access to the sysprocedures table or not.

Comments are welcome. Thanks!
_________________
Thanks & Regards,
Manoj.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Thu Apr 22, 2004 10:49 am    Post subject: Reply with quote

Manoj,

Quote:

What I could not gather is this... When i do a "CREATE PROCEDURE" it creates a row in sysroutines, but does it also create a row in sysprocedures??? I do not have access to both these tables. We are using DB2 V7 and thus what I was thinking is, does the user id executing the stored procedure need access to the sysprocedures table. The reason im asking this is because you had mentioned above that Quote:
When DB2 receives an SQL CALL statement, it searches for information about the stored procedure in the SYSIBM.SYSPROCEDURES catalog table.
and as the executing user id does not have access to this table, would it succeed


Prior to version 7 DB2 used the information in sysibm.sysprocedures to validate the stored procedure. In versions 4 & 5 of DB2 you have to manually insert a row into the sysibm.sysprocedures whenever you create a stored procedure. But with DB2 version 6 IBM automated the task of inserting a row into the catalog table when the CREATE PROCEDURE statement is execueted.

A row will only be inserted in sysibm.sysroutines when you execuete the "CREATE PROCEDURE " in DB2 V7. You don't need a row in the sysibm.sysprocedures table.

It is true that when DB2 receives an SQL CALL statement, it searches for information about the stored procedure in the SYSIBM.SYSPROCEDURES or SYSIBM.SYSROUTINES catalog table. It makes sure that the stored procedure is defined to DB2. It has got nothing to do with the userid.

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
manojagrawal
Beginner


Joined: 25 Feb 2003
Posts: 124
Topics: 29

PostPosted: Thu Apr 22, 2004 10:56 am    Post subject: Reply with quote

Thanks for the explanation Kolusu. Sure has cleared up my thoughts on how it goes about doing it. Good to know that the calling userid does not need access. Thanks once again.
_________________
Thanks & Regards,
Manoj.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group