DB2 table -selective download to a flat file

Ask question on - DataBase Concepts, IBM Mainframe DB2, DB2/UDB, DB2 Tools, SQL , DB2 programming with languages like COBOL, PL1.

Moderators: Kalicharan, Moderator Group

Post Reply
mainframe_puli
Member
Posts: 2
Joined: Tue Apr 10, 2007 2:23 pm

DB2 table -selective download to a flat file

Post by mainframe_puli » Fri Apr 13, 2007 9:19 am

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

Veera
Moderator
Posts: 111
Joined: Wed Feb 22, 2006 2:59 pm

Post by Veera » Fri Apr 13, 2007 11:23 pm

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: Select all

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: Select all

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.

mainframe_puli
Member
Posts: 2
Joined: Tue Apr 10, 2007 2:23 pm

Post by mainframe_puli » Tue Apr 17, 2007 9:01 am

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?

User avatar
DavidatK
Active Member
Posts: 65
Joined: Tue Mar 27, 2007 8:41 am
Location: Troy, MI USA

Post by DavidatK » Wed Apr 18, 2007 5:04 am

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

Veera
Moderator
Posts: 111
Joined: Wed Feb 22, 2006 2:59 pm

Post by Veera » Wed Apr 18, 2007 6:26 am

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: Select all


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: Select all



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 :)

Thanks,
Veera.

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others