Random row selection



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Random row selection

Postby rakesh086 » Wed May 16, 2012 1:24 pm

i want to fetch a specific row from a file. like 150th row only.
how i can go ahead with cobol.
rakesh086
 
Posts: 13
Joined: Fri Jan 06, 2012 9:21 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Random row selection

 

Re: Random row selection

Postby enrico-sorichetti » Wed May 16, 2012 2:30 pm

files do not have rows, they HAVE RECORDS
did You think about reading, incrementing a counter and stop when the counter reaches 150 ???
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2644
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: Random row selection

Postby dick scherrer » Wed May 16, 2012 7:09 pm

Hello,

Why record 150?

What happens when the file content changes (adds / deletes)?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Random row selection

Postby Akatsukami » Wed May 16, 2012 8:49 pm

rakesh086 wrote:i want to fetch a specific row from a file. like 150th row only.
how i can go ahead with cobol.

The real question is, what kind of data set are you reading?

As Dr. Sorichetti indicates, a sequential data set must be read sequentially; reading record 150 involves reading and discarding records 1-149. A relative data set can have a specific record read from it directly. The question is meaningless for an indexed data set, as key value, not position, is significant.

Tell us the organization of the data set, and you might get a useful answer.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1053
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Random row selection

Postby gokulNmf » Sat May 19, 2012 8:30 am

Hi Rakesh,
If you know the record number (n) to read and if it is sequential then you have to read all the n-1 records.
If its a VSAM(KSDS,RRDS) you can use the key or RBA to find nth record.
Cheers,
Gokul
User avatar
gokulNmf
 
Posts: 114
Joined: Sat Mar 28, 2009 6:41 pm
Location: India
Has thanked: 0 time
Been thanked: 0 time

Re: Random row selection

Postby Pandora-Box » Sun May 27, 2012 12:24 am

If the record number keeps changing and if you know it .

Suggest to pass it as a parm or control record

So you could read the Random number from Parm or control record and process it
User avatar
Pandora-Box
 
Posts: 65
Joined: Fri Feb 10, 2012 8:30 pm
Location: Mars
Has thanked: 3 times
Been thanked: 6 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post