Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Generic DB2 statement

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
simha_it

New User


Joined: 05 May 2005
Posts: 30

PostPosted: Thu May 06, 2010 3:44 pm    Post subject: Generic DB2 statement
Reply with quote

Hi All,

I want to write one generic Service (SQL query) in which I can retrieve the data from any table using primary key.

For example, during the run time my service will get the table name (it could be any table name) as an input. Based on that table name, I have to retrieve the data. But I have to retrieve the data based on the primary key of that particular table.

Can any one suggest how to achieve this?

I have one idea in my mind. I think, we can use dynamic SQL. By using dynamic SQL we can issue Select * from [table name] but difficult to give where clause here. Is it possible to give Index (primary key) dynamically for any table.

Thanks
Simha
Back to top
View user's profile Send private message

expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Thu May 06, 2010 4:08 pm    Post subject:
Reply with quote

So why have you posted this in the DFSORT forum ?
Back to top
View user's profile Send private message
simha_it

New User


Joined: 05 May 2005
Posts: 30

PostPosted: Thu May 06, 2010 5:12 pm    Post subject:
Reply with quote

I don't know about this. But I am looking for a help. Could you please help me out in this?
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10210
Location: italy

PostPosted: Thu May 06, 2010 5:22 pm    Post subject: Reply to: Generic DB2 statement
Reply with quote

what You ask for is not suitable for a forum reply ..
if You have the skills it' s reasonably easy to do it, NO amount of replies will provide You with the skills needed

Yes it can be done once the requirements are clear, how to do it is a different show

take one of the DSNTEP flavors and modify it according to Your needs
DSNTEP resides in a dataset name along "<some_qualifier>.SDSNSAMP"
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu May 06, 2010 9:28 pm    Post subject:
Reply with quote

Hello,

Why do you believe you need to provide a substitute for SPUFI?

Hopefully, you are aware that if "anyone" is permitted to do "whatever they want" on the fly, the system will eventually melt down. . .
Back to top
View user's profile Send private message
die7nadal

Active User


Joined: 23 Mar 2005
Posts: 156

PostPosted: Fri May 07, 2010 9:25 pm    Post subject:
Reply with quote

This can done by querying the SQLDA variables. This process has been explained under Varying list Select statements using dynamic query in the IBM manuals. I can't remember exactly which manual at the top of my head.

As far as the primary key is concerned you can get them from the catalogue tables using this query
Code:
SELECT * FROM SYSIBM.SYSCOLUMNS 
WHERE TBNAME = 'NAME'             
AND KEYSEQ   > 0                 
WITH UR;                         
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1224
Location: Israel

PostPosted: Sat May 08, 2010 11:11 am    Post subject: Re: Generic DB2 statement
Reply with quote

This is a very ambitious project, and, from your basic question, I don't believe you have the necessary skills.
I'm not even sure I have the skills for that!

simha_it wrote:
I have to retrieve the data based on the primary key of that particular table.
...
but difficult to give where clause here. Is it possible to give Index (primary key) dynamically for any table.
From the way you posted your question, I feel you mixed the WHERE and ORDER BY clauses.
If you want to force DB2 to use an index, then you should ORDER BY all the key columns.

And yes, handling the WHERE will be very difficult.
You will need to handle all possible row lengths too.
And you will need authorization to access all the tables.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat May 08, 2010 7:45 pm    Post subject:
Reply with quote

Hello,

Tonrepeat:
Quote:
Why do you believe you need to provide a substitute for SPUFI?
If youn explain what you really want to do, someone may have a suggestion.

What you have asked is about a solution. What is the actual requirement?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts -913/-911 Deadlock during UPDATE stat... NoSleep319 DB2 5 Fri Nov 18, 2016 12:37 am
No new posts COBOL DB2 - CALL statement - high CPU... TS70363 DB2 15 Sun Sep 11, 2016 6:07 am
No new posts Converting NULL column into NOT NULL ... Raghu navaikulam DB2 5 Sat Aug 06, 2016 3:45 pm
This topic is locked: you cannot edit posts or make replies. Updating value of key using rewrite s... ParminderKumar COBOL Programming 4 Thu Aug 04, 2016 12:46 am
No new posts Inspect statement spoorni COBOL Programming 5 Mon Jun 06, 2016 9:53 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us