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
 

 

Best way to define file for Cobol read

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
jtwohig

New User


Joined: 24 Jul 2006
Posts: 18

PostPosted: Sat Jan 27, 2007 12:04 am    Post subject: Best way to define file for Cobol read
Reply with quote

Hi,

I'm trying to determine the best way to define and then read a file based on the following. The first four fields in the file will, potentially, be scrutinized and all can have duplicate values. The read in the Cobol program will search the values in the first field (based on the input value) until it finds a match. If it does not, it goes on to field two, and then field 3, etc.

My first thought was to make it a VSAM file but none of the 4 fields, or any other field in the file for that matter, is unique. I know alternate indexes can have duplicates but not the main key, correct ?

So my question is can I make this a VSAM somehow, some way or should it be a sequential file and sequential read ?
Thanks,
J
Back to top
View user's profile Send private message

William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Sat Jan 27, 2007 1:20 am    Post subject: Re: Best way to define file for Cobol read
Reply with quote

jtwohig wrote:
I'm trying to determine the best way to define and then read a file based on the following. The first four fields in the file will, potentially, be scrutinized and all can have duplicate values. The read in the Cobol program will search the values in the first field (based on the input value) until it finds a match. If it does not, it goes on to field two, and then field 3, etc.

My first thought was to make it a VSAM file but none of the 4 fields, or any other field in the file for that matter, is unique. I know alternate indexes can have duplicates but not the main key, correct ?

So my question is can I make this a VSAM somehow, some way or should it be a sequential file and sequential read ?
Firstly, you can make it an ESDS VSAM file and lay alternate indexes down on top of that.
What does "based on the input value" mean?
Why can't you check all four fields for each record at the same time?
This sounds like sort might be usable, but i don't know because I'm not sure of what your requirements are...
Back to top
View user's profile Send private message
jtwohig

New User


Joined: 24 Jul 2006
Posts: 18

PostPosted: Sat Jan 27, 2007 2:50 am    Post subject: Re: Best way to define file for Cobol read
Reply with quote

Thanks William,

This file would be read in a "called" program which, actually, passes in 4 values via the linkage section. The first value passed into the called program is used to attempt a match on the first field in the proposed VSAM file. If a match is not found there, the 2nd value passed into the called program is used to attempt a match on the 2nd field in the proposed VSAM file. I don't know if that clarifies things any more or just muddies the waters.

Thanks,
J
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Sat Jan 27, 2007 3:10 am    Post subject:
Reply with quote

Well, if you can turn it into a vsam file, alt index would be a quick solution.

And, you're welcome,

Bill
Back to top
View user's profile Send private message
DavidatK

Active Member


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

PostPosted: Sat Jan 27, 2007 3:35 am    Post subject: Re: Best way to define file for Cobol read
Reply with quote

If you are going to need more than one record from the file, VSAM is absolutely the way to go on this. However, if there are duplicate values in the fields and you need the first matched record on the input sequential file that satisfies the criteria instead of any record that satisfies the criteria, VSAM may not be able to guarantee that without creating unique keys.

The following code snippet is probably useless to you, but it gave me some distraction while I was waiting for a job to complete.

Some pseudo code that I think will work, single pass. (Untested).

Code:

01  WS-FIELD-MATCH        PIC 9  VALUE 0.             
    88 FIELD-NOT-MATCHED         VALUE 0.             
    88 FIELD-1-MATCH             VALUE 1.             
    88 FIELD-2-MATCH             VALUE 2.             
    88 FIELD-3-MATCH             VALUE 3.             
    88 FIELD-4-MATCH             VALUE 4.             
                                                     
01  MATCHED-RECORD.                                   
    05 ...                                           
    :                                                 
    :                                                 
                                                                   
                                                         
    PERFORM                                             
      UNTIL EOF                                         
      OR FIELD-1-MATCH                                   
        READ RECORD INTO INPUT-RECORD                   
        IF NOT EOF                                       
          IF FIELD-1 = PASSED-VALUE-1                   
            SET FIELD-1-MATCH TO TRUE                   
            MOVE INPUT-RECORD TO MATCHED-RECORD
          ELSE                                                 
            IF NOT FIELD-2-MATCH                               
              IF FIELD-2 = PASSED-VALUE-2                     
                SET FIELD-2-MATCH TO TRUE                     
                MOVE INPUT-RECORD TO MATCHED-RECORD           
              ELSE                                             
                IF NOT FIELD-3-MATCH                           
                  IF FIELD-3 = PASSED-VALUE-3                 
                    SET FIELD-3-MATCH TO TRUE                 
                    MOVE INPUT-RECORD TO MATCHED-RECORD       
                  ELSE                                         
                    IF NOT FIELD-4-MATCH                       
                      IF FIELD-4 = PASSED-VALUE-4             
                        SET FIELD-4-MATCH TO TRUE             
                        MOVE INPUT-RECORD TO MATCHED-RECORD   
                      END-IF                                   
                    END-IF                                     
                  END-IF                                       
                END-IF                                         
              END-IF                             
            END-IF                               
          END-IF                                 
        END-IF                                   
    END-PERFORM.

    IF FIELD-NOT-MATCHED
      DO SOMETHING
    ELSE
      DO SOMETHING ELSE
    END-IF.

                                   
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Sat Jan 27, 2007 3:46 am    Post subject: Re: Best way to define file for Cobol read
Reply with quote

jtwohig wrote:
If a match is not found there
DavidatK wrote:
you need the first matched record
I'm sorry David, but where was the requirement for the "first" match?
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat Jan 27, 2007 4:16 am    Post subject:
Reply with quote

Hello J,

Please post some sample input records, sample parms that woiuld be passed to the routine, and what you want the output to be when the process works correctly for the sample input and the sample parms.

If you post them as "code" they line up. . . icon_biggrin.gif
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 Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Issue with NDM process to transmit ES... chetanambi All Other Mainframe Topics 6 Wed May 03, 2017 10:52 am


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