View previous topic :: View next topic
|
Author |
Message |
GAFUR
New User
Joined: 19 May 2005 Posts: 31
|
|
|
|
Hi ,
I want to Know how to read dyamically the LAST record of a VSAM file ie using HIGH VALUES , START , READ commands. Is it possible through COBOL? .
I am using pure COBOL program.
I dont want to use SORT at any stage.
I am not using CICS/DB2.
Thanks & regards
Gafur. |
|
Back to top |
|
|
khamarutheen
Active Member
Joined: 23 Aug 2005 Posts: 677 Location: NJ
|
|
|
|
Hi Gafur,
By using RBA or Key value u can use the random read option either in last or mid as u like.. it depends on u my frnd |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
The problem w/KAK's solution is that you probably don't know the key/RBA of your last rec.
Since there's currently no way to do a read prev in a batch cobol pgm you'll have to look to assembler or a utility.
You can use FileAid to do this. Then read it into your cobol pgm as a separate file. |
|
Back to top |
|
|
gowtham_1982 Warnings : 1 Active User
Joined: 02 Dec 2005 Posts: 109
|
|
|
|
hi gafur,
i guess you don't know the RBA or KEY or RRN of the file. you need to use the cobol logic.
read the file till you meet the end of file condition(check the file status for a value (ten) 10 ). then for every successful read (check the file status for zeroes) increment the count by 1.
now when the end condition is met, you have the total no of records in the file. we can read the last record by subscripting the record with the total no of records.
please note that this logic is possible only for a file with records defined with OCCURS clause
corrections welcomed...
gowtham |
|
Back to top |
|
|
khamarutheen
Active Member
Joined: 23 Aug 2005 Posts: 677 Location: NJ
|
|
|
|
Hi gowtham,
Ur logic is good but it will take time if there is large no. of records. |
|
Back to top |
|
|
gowtham_1982 Warnings : 1 Active User
Joined: 02 Dec 2005 Posts: 109
|
|
|
|
khamarutheen wrote: |
Hi gowtham,
Ur logic is good but it will take time if there is large no. of records. |
hai khamarutheen.
yeah, my logic may work. but we don't have any other options left. we don't know concrete about the RBA or RRN or the KEY of the file. hence i suggested this logic.
corrections welcomed...
gowtham |
|
Back to top |
|
|
sbalajibe
New User
Joined: 15 Aug 2005 Posts: 62
|
|
|
|
Hi All,
U Cannot Use RBA in Cobol as cobol does not support RBA
move high values to the key field and read
i thing this should read last record of that key
please check
thanks and regards
Balaji |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
Hi GAFUR,
The responses above are correct; there is no way of directly accessing the last record to obtain the highest key. There are, however some logics that will greatly minimize the number of I/Os to the file. Like a binary search of the INDEX using the START verb. The START verb accesses only the INDEX to set the current position in the VSAM file.
What does the description of the key look like? i.e. the ?PIC? for the key?
Lets make an assumption that your key is PIC S9(11).
Code: |
FD VSAM-FILE
01 VSAM-RECORD.
05
:
:
01 WS-CURRENT-KEY PIC S9(11).
01 WS-LAST-VALID-KEY PIC S9(11).
01 WS-MIN-KEY PIC S9(11) VALUE 0.
01 WS-MAX-KEY PIC S9(11) VALUE 99999999999.
01 WS-HIGHEST-KEY PIC S9(11) VALUE 0.
COMPUTE WS-CURRENT-KEY = (WS-MAX-KEY + WS-MIN-KEY) / 2.
VSAM-START.
PERFORM UNTIL WS-HIGHEST-KEY NOT = 0
START VSAM-FILE KEY NOT GREATER OR EQUAL TO WS-CURRENT-KEY
INVALID KEY
MOVE WS-CURRENT-KEY TO WS-MAX-KEY
VALID KEY
MOVE WS-CURRENT-KEY TO WS-MIN-KEY
END-START
COMPUTE WS-CURRENT-KEY = (WS-MAX-KEY + WS-MIN-KEY) / 2
IF WS-CURRENT-KEY = WS-MIN-KEY
THEN
WS-HIGHEST-KEY = WS-CURRENT-KEY
END-IF
END-PERFORM.
|
I did this off the top of my head, I?m sure your going to have to do some fine tuning on this code. And I?m sure there are probably better algorithms.
I did do a short desk test and it seems to work.
This seems to do a lot of logic, and for small files it is least efficient, the larger the file, the more relative efficiency it has.
You can search a file of more than 100,000,000,000 records in just 37 STARTs. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Gafur, it would help to know the broader aspects of the problem. What do you plan to do AFTER you read the last rec? That and perhaps other info may lead to a workable solution.
The FileAid solution would make the key of the last VSAM rec available to your pgm or you could just read the rec as a PS file after FA creates it.
Gafur, are you still out there? |
|
Back to top |
|
|
GAFUR
New User
Joined: 19 May 2005 Posts: 31
|
|
|
|
Hi mmwife,
Thanks for your response. But we dont have file aid in our system. Our client is using some other tool for VSAM which dont have the all options of file-aid. And also we are not allowed to edit the Batch Jcl ( for eg to use sort or other feature).
Instead of reading sequentially and inserting some cobol logic for this requirement , i thought of using HIGH VALUES. After going through all solutions provided by group then i came to know it is not possible to get Last record using high values.
Group.Thank you very much for your solutions and response.
Regards,
GAFUR,
Covansys. |
|
Back to top |
|
|
GAFUR
New User
Joined: 19 May 2005 Posts: 31
|
|
|
|
Hi DavidatK,
Thanks for your response.
Regards,
GAFUR,
Covansys. |
|
Back to top |
|
|
manjinder
New User
Joined: 04 Dec 2005 Posts: 45 Location: pune
|
|
|
|
hi gafur
frnd you can read last read one alternate method is to use the temporary variable move the records to tht variable and at the EOF display the temporary variable it will display last record.
perform read-para until EOF
display temp.
read-para.
read file until EOF='Y'.
if not EOF then
move low values to temp.
move inrec to temp.
try this one
correct me if wrong |
|
Back to top |
|
|
manjinder
New User
Joined: 04 Dec 2005 Posts: 45 Location: pune
|
|
|
|
hi gafur
frnd you can read last read one alternate method is to use the temporary variable move the records to tht variable and at the EOF display the temporary variable it will display last record.
perform read-para until EOF
display temp.
read-para.
read file until EOF='Y'.
if not EOF then
move low values to temp.
move inrec to temp.
try this one
correct me if wrong |
|
Back to top |
|
|
|