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
 

 

Get 1/10 of a file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Get 1/10 of a file
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    Post subject: Reply to: Get 1/10 of a file
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: 1703
Location: Australia

PostPosted: Thu Jul 10, 2008 3:06 pm    Post subject:
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    Post subject: Reply to: Get 1/10 of a file
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

Moderator Team Head


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

PostPosted: Thu Jul 10, 2008 4:39 pm    Post subject: Re: Reply to: Get 1/10 of a file
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    Post subject: Reply to: Get 1/10 of a file
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: 1703
Location: Australia

PostPosted: Thu Jul 10, 2008 6:11 pm    Post subject:
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Thu Jul 10, 2008 7:40 pm    Post subject: Reply to: Get 1/10 of a file
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: 7905
Location: Bellevue, IA

PostPosted: Thu Jul 10, 2008 7:50 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Thu Jul 10, 2008 7:53 pm    Post subject: Reply to: Get 1/10 of a file
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Fri Jul 11, 2008 12:26 am    Post subject: Reply to: Get 1/10 of a file
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    Post subject: Re: Reply to: Get 1/10 of a file
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: 4
Location: bangalore

PostPosted: Wed Jul 16, 2008 10:24 am    Post subject: Reply to: Get 1/10 of a file
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm


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