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

Reading Last Record dynamically through pure COBOL program


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

New User


Joined: 19 May 2005
Posts: 31

PostPosted: Mon Jan 02, 2006 6:38 pm
Reply with quote

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

Active Member


Joined: 23 Aug 2005
Posts: 677
Location: NJ

PostPosted: Mon Jan 02, 2006 7:43 pm
Reply with quote

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

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Jan 03, 2006 12:28 am
Reply with quote

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

Active User


Joined: 02 Dec 2005
Posts: 109

PostPosted: Tue Jan 03, 2006 10:41 am
Reply with quote

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

Active Member


Joined: 23 Aug 2005
Posts: 677
Location: NJ

PostPosted: Tue Jan 03, 2006 12:09 pm
Reply with quote

Hi gowtham,

Ur logic is good but it will take time if there is large no. of records.
Back to top
View user's profile Send private message
gowtham_1982
Warnings : 1

Active User


Joined: 02 Dec 2005
Posts: 109

PostPosted: Tue Jan 03, 2006 12:53 pm
Reply with quote

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

New User


Joined: 15 Aug 2005
Posts: 62

PostPosted: Thu Jan 05, 2006 12:09 pm
Reply with quote

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

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Fri Jan 06, 2006 4:22 am
Reply with quote

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

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Jan 06, 2006 5:04 am
Reply with quote

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

New User


Joined: 19 May 2005
Posts: 31

PostPosted: Fri Jan 06, 2006 11:50 am
Reply with quote

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

New User


Joined: 19 May 2005
Posts: 31

PostPosted: Fri Jan 06, 2006 11:53 am
Reply with quote

Hi DavidatK,

Thanks for your response.

Regards,
GAFUR,
Covansys.
Back to top
View user's profile Send private message
manjinder

New User


Joined: 04 Dec 2005
Posts: 45
Location: pune

PostPosted: Sat Jan 07, 2006 2:39 pm
Reply with quote

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

New User


Joined: 04 Dec 2005
Posts: 45
Location: pune

PostPosted: Sat Jan 07, 2006 2:40 pm
Reply with quote

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
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 How to split large record length file... DFSORT/ICETOOL 7
No new posts Replace each space in cobol string wi... COBOL Programming 2
No new posts Using API Gateway from CICS program CICS 0
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top