View previous topic :: View next topic
|
Author |
Message |
vicky11121982
New User
Joined: 21 Jun 2007 Posts: 9 Location: gurgaon
|
|
|
|
I was asked this question of getting 1/10 of file of millions of records in a flat file, record number varying in each run, through COBOL code. First 10 bytes of the code has sequence numbers. Using read and count was discounted as it will have to read the whole file. Can anyone suggest anyother way? |
|
Back to top |
|
|
Antonio Barata Warnings : 1 New User
Joined: 04 Apr 2007 Posts: 37 Location: Lisbon, Portugal
|
|
|
|
Hi
Have you considered using SORT/ICETOOL instead of application program?
I think that it could solve it with much less effort.
Try to put the question in the DFSORT/ICETOOL forum.
Regards |
|
Back to top |
|
|
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi,
why do you need to read the whole file unless you don't know the count before hand, then you don't have any choice whether it's cobol or any other tool.
I'm not sure having the sequence number matters, you read and count and stop when you have reached your target.
Gerry |
|
Back to top |
|
|
vicky11121982
New User
Joined: 21 Jun 2007 Posts: 9 Location: gurgaon
|
|
|
|
While digging found READ LAST.Can we make the access mode as dynamic and use READ LAST to read the last record and get the record sequence number.Dividing that by 10 will give us our limit till the count can reach.Any suggestions?? |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
vicky11121982 wrote: |
While digging found READ LAST.Can we make the access mode as dynamic and use READ LAST to read the last record and get the record sequence number.Dividing that by 10 will give us our limit till the count can reach.Any suggestions?? |
Digging where? That's not an IBM Mainframe COBOL instruction. Could you please provide the source of the reference material for your statement. |
|
Back to top |
|
|
vicky11121982
New User
Joined: 21 Jun 2007 Posts: 9 Location: gurgaon
|
|
Back to top |
|
|
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi,
I take back what I said earlier, if you have FILEAID you can get the last record by using the following
Code: |
//COPYREC EXEC PGM=FILEAID
//DD01 DD DSN=input file
//DD01O DD DSN=output file
//SYSIN DD *
$$DD01 COPYBACK OUT=1
//SYSPRINT DD SYSOUT=* |
You can then use the following
Code: |
//S1 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=OUTPUT FROM FILEAID
//SORTOUT DD DSN=&&END,DISP=(,PASS,DELETE),UNIT=SYSDA,SPACE=(TRK,(1))
//SYSIN DD *
OPTION COPY
INREC OVERLAY=(81:01,10,ZD,DIV,+10,EDIT=(TTTTTTTTTT))
OUTFIL BUILD=(1:C' OUTFIL FNAMES=OUT,ENDREC=',81,10,80:X)
/*
//**********************************************************************
//S2 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=MILLIONS OF RECORDS FILE
//OUT DD DSN=OUTPUT FILE 10TH OF FILE
//SYSIN DD *
OPTION COPY
/*
// DD DSN=&&END,DISP=(OLD,DELETE)
|
Gerry |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Which 1/10 of the file do you want, the first, the last, a random select or just 1 record of each 10 as the file is read? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
that' s just an interview question with no business logic behind |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Enrico: actually, I've had to do this for business reasons -- statistical sampling of the input file; we had to pull out the sample, run some statistical analyses on the sample, and then compare the sample results to the full file results to verify the sampling tests were providing valid results. However, statistical sampling usually only needs a few thousand records; pulling 10% of a multi-million-record file would be overkill.
Vicky: you're not going to get away from having to read the file to pull the records. In COBOL you can use FUNCTION RANDOM to return a random number and use that for selecting the records. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
I was not implying the lack of business reasons as a general point,
it was just the way the question was posed |
|
Back to top |
|
|
vicky11121982
New User
Joined: 21 Jun 2007 Posts: 9 Location: gurgaon
|
|
|
|
Thanks Robert and Gerry
Enrico:Even i/w question have answers and I was just curious to find one. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
the point is that answering interview question has a different approach...
it' s more like puzzle solving,
when I ask what is the business need I want to know as much info as I can in order to provide the best answer
and whenever, like in the original question, also the how is specified
I have the impression that something is not going the right way |
|
Back to top |
|
|
vicky11121982
New User
Joined: 21 Jun 2007 Posts: 9 Location: gurgaon
|
|
|
|
enrico-sorichetti wrote: |
the point is that answering interview question has a different approach...
it' s more like puzzle solving, |
Agreed |
|
Back to top |
|
|
hanucob
New User
Joined: 15 Jul 2008 Posts: 3 Location: bangalore
|
|
|
|
Hai!!
My answere is like write a query using count(*) ,then u will get
no of records in it,then divide it by 10.......then can read required records
... |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
the topic is: Get 1/10 of a file
you can not execute sql against a non-db2 organization. |
|
Back to top |
|
|
|