Home      Mainframe Forum      Mainfarme Tutorials      IBM Manuals      Mainframe Interview Questions      Mainframe Books      IT News     SiteMap     Downloads


     
 
MAINFRAME - TIP OF THE DAY : programming pearls - The fastest algorithm can frequently be replaced by one that is almost as fast and much easier to understand.

Google
 
Web mainframegurukul.com

Welcome to the mainframegurukul forums.

You are currently viewing our mainframe forums as a guest which gives you limited access to view most discussions, articles. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support at admin@mainframegurukul.com


DB2 table -selective download to a flat file

 
Post new topic   Reply to topic    mainframegurukul.com Forum Index -> DB2 SQL - DB2 PROGRAMMING
  View previous topic :: View next topic  
Author Message
mainframe_puli
Member


Joined: 10 Apr 2007
Posts: 2

PostPosted: Fri Apr 13, 2007 9:19 am    Post subject: DB2 table -selective download to a flat file Reply with quote

Hi,

I have Agent DB2 table& a Transaction file. The transaction file has a field Agent No. I have to query the AGENT table which consists of both agent no& Employee no, to get the Employee no corresponding to the Agent no.s in the transaction file. Is this Possible?

1 more doubt.While I tried to unload the table using selective query, it was showing "SELECT" stmt is illegal.Can you tell me the reason?
Or isnt it possible to do the selective download of a DB2 table to a flat file?

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

Veera
Moderator


Joined: 22 Feb 2006
Posts: 111

PostPosted: Fri Apr 13, 2007 11:23 pm    Post subject: Reply with quote

Rinu,


I have Agent DB2 table& a Transaction file. The transaction file has a field Agent No. I have to query the AGENT table which consists of both agent no& Employee no, to get the Employee no corresponding to the Agent no.s in the transaction file. Is this Possible?

Code:

yes it is possible.

SELECT EMPOLYEE_NO ,AGENT_NO                 
  FROM AGENT
  WHERE AGENT_NO = :WS-Agent_No ----> This field should be from ur TRANS FILE.


We need to consider few things in the above query

1--> IT will give correct results only if you have UNIQUE AGENT_NO in the AGENT TABLE.
     other wise there is a posibility that you will get duplicates for that either
     you need to handle duplicates by -811 or code a CURSOR.

2---> It is always good to query the table using the full key. So instead of unloading
      the only AGENT_NO try unloading the entire key fields from the file if you have
      all the fields.If you query the table with out key fields, there will be tremendous
      performance degradation, which is not wise to use.

3---> The above query should be executed for each record in the I/P FILE. I mean you have
      to read the TRANS-FILE until EOF, and for each succesfull read you have to execute the
      above query, and display or wirte into output file as per your requirement.



1 more doubt.While I tried to unload the table using selective query, it was showing "SELECT" stmt is illegal.Can you tell me the reason? Or isnt it possible to do the selective download of a DB2 table to a flat file?

Code:

This should be possible, how are u trying to do this..may be something wrong with ur query systax.


As Info:
********

I think if you are trying to unload the AGENT_NO from other table into TRANS-FILE and then
using that AGENT_NO from TRANS-FILE if you are trying to select list of EMPOLYEE_NO for
the corresponding AGENT_NO, then instead of unloading into TRANS-FILE.We can directly
achieve the above by join/co-related query on 2 tables with appropriate keys thru one pass to DB2.

Well anyway unloading into TRANS-FILE is also not a bad option.



Thanks,
Veera.
Back to top
View user's profile Send private message
mainframe_puli
Member


Joined: 10 Apr 2007
Posts: 2

PostPosted: Tue Apr 17, 2007 9:01 am    Post subject: Reply with quote

Hi Veera,

I forgot to mention that I am trying to implement the above using JCL only.
I am not supposed to use any COBOL programs for the same.Can you give me a solution for the same?
Back to top
View user's profile Send private message
DavidatK
Active Member


Joined: 27 Mar 2007
Posts: 65
Location: Troy, MI USA

PostPosted: Wed Apr 18, 2007 5:04 am    Post subject: Reply with quote

Rinu,

What you are asking of DB2 is not possible directly, but is achievable. You cannot do a query in JCL accessing a flat file. But there are ways.

Can you please post the structure of the agent table and the copybook for the transaction file? Also the copybook for the output.

I take it this is an academic exercise rather than a business problem, right? There are things that I would do as an academic exercise that I would not do as a business solution.

How much of a volume are we talking about here? Hundreds, thousands, or millions of rows/records?

Let?s see what we can come up with.

Dave
Back to top
View user's profile Send private message
Veera
Moderator


Joined: 22 Feb 2006
Posts: 111

PostPosted: Wed Apr 18, 2007 6:26 am    Post subject: Reply with quote

Rinu,

Ok let me define ur requirement first

1. You have a transaction file -> This File has field AGENT-NO

2. you have a table AGENT -> Which consists of AGENT-NO,EMPLOYEE-NO...and some more columns.


Now what is required is you need to get the EMPLOYEE-NO corresponding to the AGENT-NO from ur I/P trans file.

and you want to achieve this using only JCL.


Ok Rinu here is what i suggest..

Code:


STEP1 : Unload the AGENT table.

           ( All the columns OR only 2 columns AGENT-NO , EMPLOYEE-NO)

This can be done using the JCL , using a query.



you dint get back to us reg whether the TRANS FILE or the TABLE will have duplicates

on AGENT-NO and EMPLOYEE-NO.

well if there can be duplicates then you need few more steps .

Code:



STEP 2: SORT THE UNLOAD FILE FROM STEP1 ON AGENT-NO AND ELIMINATE ALL THE DUPLICATES.
        (SUM FIELDS = NONE , AND SORT FIELDS)

STEP 3: SORT THE TRANS FILE AND ELIMINATE DUPLICATES ON AGENT-NO

NOTE : STEP 2 AND STEP 3 are required only if you have any DUPLICATES

step 4:  write one EZT matching program or SORT and then match on AGENT-NO from
         both the files and when ever there is a match write into outfile from
         UNLOAD FILE , which has both AGENT-NO and EMPLOYEE-NO.



NOTE : If you are planning to use EZT for matching then better to sort both the files on fields which we match.

whatever is suggested can be done using ONLY JCL without using ANY PROGRAM COBOL OR COBOL + DB2.


P.S : WHAT EVER YOU HAVE ASKED FOR IS NOT CLEAR AS DAVE SAID IF YOU CAN COME UP WITH ALL THE DETAILS AND STRUCURE YOUR REQUIREMENT CLEARLY THEN WE CAN GET BACK WITH BETTER SOLUTIONS.

If the suggested solution can give you and Idea how to procees we will be Glad Smile

Thanks,
Veera.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    mainframegurukul.com Forum Index -> DB2 SQL - DB2 PROGRAMMING 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

Related topics
 Topics   Replies   Author   Views   Last Post 
No new posts two reports to compare , both different format - URGENT 1 ar3 1493 Wed Jul 15, 2009 7:57 pm
Frank Yaeger View latest post
No new posts If both the JOBCAT & STEPCAT statements are coded in a s 1 Krishna 2095 Tue May 12, 2009 6:43 pm
Krishna View latest post
No new posts Commit both in DB2 and MQ 3 jackie 2824 Fri Jul 27, 2007 3:52 pm
dbzTHEdinosauer View latest post
No new posts How to use both lower and upper case letters in cobol? 1 Divya 4885 Fri Mar 09, 2007 10:27 pm
Veera View latest post
No new posts Stop Run in both called and calling programs !!! 2 arrbee 4480 Fri Mar 10, 2006 12:13 pm
jaydeeppal View latest post
 



This widget requires Flash Player 9 or better








Go to top of the page
 

Online ABEND Reference ||  JCL References ||  COBOL References ||  VSAM References ||  Tutorials by Drona Series ||  SQL tutorial ||  BOOKS  ||  DB2 INTERVIEW QUESTIONS ||  COBOL INTERVIEW QUESTIONS  ||  JCL INTERVIEW QUESTIONS ||  JCL2 INTERVIEW QUESTIONS ||  VSAM INTERVIEW QUESTIONS ||  CICS INTERVIEW QUESTIONS  ||  Online tutorials ||  Online ABEND Reference ||  JCL References ||  COBOL References ||  VSAM References ||  Tutorials by Drona Series ||  SQL tutorial ||  BOOKS  ||  SiteMap  ||  Expeditor Tutorial  ||  FILE-AID Tutorial  ||  Changeman Tutorial  ||  COBOL   ||  DB2   ||  JCL  ||  CICS  ||  VSAM  ||  DB2 Interview Questions ( 110 )   || Simple JCL Tutorials  || JCL Tutorial from MainframeGurukul.com   || Simple JCL Tutorial - Chapter1 ;|| Mainframe Forum - Tutorials  || Mainframe Tutorials

Drona Educational Forums - Mainframe Cobol DB2 CICS Board
Powered by phpBB