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 - declare global temp table

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


Joined: 15 Dec 2005
Posts: 20
Topics: 9

PostPosted: Thu Dec 29, 2005 4:49 am    Post subject: DB2 - declare global temp table Reply with quote

Hi,

I have learned that DB2 uses a declared temporary table to hold and maintain the data returned by a scrollable cursor.

Below is SENSITIVE STATIC SCROLL cursor, how should I use declared temporary table here ?? How to relate DGTT with the below cursor ?Please advise. I read IBM help, but could not get the complete picture.
Code:

EXEC SQL DECLARE SPJSC CURSOR
  SENSITIVE STATIC SCROLL FOR
  SELECT SN, PN, JN, QTY
  FROM   SPJ
  WHERE  JN = :JN
  ORDER BY SN, PN, JN
END-EXEC.

EXEC SQL OPEN SPJSC END-EXEC.

EXEC SQL FETCH SPJSC INTO :SN, :PN, :JN, :QTY END-EXEC.

Thanks
Hema
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Dec 29, 2005 5:43 am    Post subject: Reply with quote

Hema_Manyam,

Check this

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNAPH11/1.2.1.2.2?SHELF=&DT=20010710165542&CASE=

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
Hema_Manyam
Beginner


Joined: 15 Dec 2005
Posts: 20
Topics: 9

PostPosted: Thu Dec 29, 2005 6:35 am    Post subject: Reply with quote

Hi Kolusu,

Thanks for your quick reply.
I have already referred this link. But I could not understand the relation between scrollable cursor and GTT , on how they should be operated together ?? Please help me.

In my case should I declare GTT as below ??

EXEC SQL DECLARE GLOBAL TEMPORARY TABLE TEMPPROD
AS (SELECT SN, PN, JN, QTY FROM SPJ)
DEFINITION ONLY
INCLUDING COLUMN DEFAULTS
END-EXEC

EXEC SQL INSERT INTO SESSION.TEMPPROD ......???

How to proceed further ??

Thanks,
hema
Back to top
View user's profile Send private message
Manas Biswal
Intermediate


Joined: 29 Nov 2002
Posts: 382
Topics: 27
Location: Chennai, India

PostPosted: Thu Dec 29, 2005 10:33 am    Post subject: Reply with quote

Hema_Manyam,

Scrollable cursors use declared temporary tables for storing intermediate resultsets and for scrolling through them. You don't have to explicitly declare the temporary tables in your application if you want to use scrollable cursors. Just declare your scroll cursor and carry on with your open/fetch statements. The necessary temporary tables will be automatically declared and destroyed in the background. You don't have to worry about that from a programmer's perspective.

However, verify that a couple of things are in place with regards to temporary tables before you attempt to use scrollable cursors, particularly if your installation is using temporary tables for the first time.
Declared temporary tables are materialised in the TEMP database on your subsystem. Don't confuse these temporary tables with "created temporary tables" which are created on the workfile database - DSNDB07. There can be only one TEMP database in a subsystem. So, verify with your DBA, if there is a TEMP database on your subsystem. If not, then that can be created using the "..AS TEMP" clause. And there should be segmented tablespaces within the TEMP database that you can use.
Provided all this setup is there, you are ready to roll with scrollable cursors.

HTH...Regards,
Manas
_________________
There is no path to peace. Peace is the path.
- Mahatma Gandhi (1869-1948)
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Hema_Manyam
Beginner


Joined: 15 Dec 2005
Posts: 20
Topics: 9

PostPosted: Sat Dec 31, 2005 12:39 am    Post subject: Reply with quote

Manas,
That was an excellent explanation. Thanks for your detailed reply.
I got the complete picture now.

Regards,
Hema
Back to top
View user's profile Send private message
Hema_Manyam
Beginner


Joined: 15 Dec 2005
Posts: 20
Topics: 9

PostPosted: Sat Dec 31, 2005 9:51 am    Post subject: Reply with quote

Manas,

I have read in manual that DECLARE GLOBAL TEMPORARY TABLE is issued in program to create an empty instance and then INSERT , DELETE, UPDATE can be used in GTT. In what cases these are useful ?? Pls advise.. Thanks

Regards
Hema
Back to top
View user's profile Send private message
Manas Biswal
Intermediate


Joined: 29 Nov 2002
Posts: 382
Topics: 27
Location: Chennai, India

PostPosted: Tue Jan 03, 2006 10:17 am    Post subject: Reply with quote

Hema_Manyam,

Temporary tables have their own uses. They are used in stored procedures to store intermediate data. They are also used extensively in programs which combine usage of relational and non-relational data. For example, suppose you use a VSAM file and a DB2 table in the same program. You can then read the entire VSAM file within the program to a temporary table and then use that as relational data within your program. So, in effect now, your program deals with relational data.
The usage of temporary tables is infinite. All depends on your imagination. Very Happy

You can have a look at the following article by Craig Mullins. It explores both the types of temporary tables in detail alongwith their potential usage -

http://www.craigsmullins.com/dbu_0802.htm

HTH...Regards,
Manas
_________________
There is no path to peace. Peace is the path.
- Mahatma Gandhi (1869-1948)
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
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