IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Get 1/10 of a file


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
vicky11121982

New User


Joined: 21 Jun 2007
Posts: 9
Location: gurgaon

PostPosted: Thu Jul 10, 2008 2:10 pm
Reply with quote

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
View user's profile Send private message
Antonio Barata
Warnings : 1

New User


Joined: 04 Apr 2007
Posts: 37
Location: Lisbon, Portugal

PostPosted: Thu Jul 10, 2008 2:49 pm
Reply with quote

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
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Thu Jul 10, 2008 3:06 pm
Reply with quote

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
View user's profile Send private message
vicky11121982

New User


Joined: 21 Jun 2007
Posts: 9
Location: gurgaon

PostPosted: Thu Jul 10, 2008 4:29 pm
Reply with quote

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
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Thu Jul 10, 2008 4:39 pm
Reply with quote

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
View user's profile Send private message
vicky11121982

New User


Joined: 21 Jun 2007
Posts: 9
Location: gurgaon

PostPosted: Thu Jul 10, 2008 5:10 pm
Reply with quote

My bad.. icon_redface.gif .. you are right Kevin it was for Integrated Language Environment COBOL (ILE COBOL) ....link:http://publib.boulder.ibm.com/infocenter/iadthelp/v7r0/index.jsp?topic=/com.ibm.etools.iseries.langref.doc/c0925395485.htm
Back to top
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Thu Jul 10, 2008 6:11 pm
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Thu Jul 10, 2008 7:37 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Jul 10, 2008 7:40 pm
Reply with quote

that' s just an interview question with no business logic behind icon_sad.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jul 10, 2008 7:50 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Jul 10, 2008 7:53 pm
Reply with quote

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
View user's profile Send private message
vicky11121982

New User


Joined: 21 Jun 2007
Posts: 9
Location: gurgaon

PostPosted: Thu Jul 10, 2008 11:38 pm
Reply with quote

Thanks Robert and Gerry

Enrico:Even i/w question have answers and I was just curious to find one.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Jul 11, 2008 12:26 am
Reply with quote

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
View user's profile Send private message
vicky11121982

New User


Joined: 21 Jun 2007
Posts: 9
Location: gurgaon

PostPosted: Fri Jul 11, 2008 12:44 am
Reply with quote

enrico-sorichetti wrote:
the point is that answering interview question has a different approach...
it' s more like puzzle solving,


Agreed icon_smile.gif
Back to top
View user's profile Send private message
hanucob

New User


Joined: 15 Jul 2008
Posts: 3
Location: bangalore

PostPosted: Wed Jul 16, 2008 10:24 am
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jul 16, 2008 11:08 am
Reply with quote

the topic is: Get 1/10 of a file

you can not execute sql against a non-db2 organization.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top