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

Best way to define file for Cobol read


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 3156
Location: Tucson AZ

PostPosted: Sat Jan 27, 2007 1:20 am
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
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: 3156
Location: Tucson AZ

PostPosted: Sat Jan 27, 2007 3:10 am
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
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: 3156
Location: Tucson AZ

PostPosted: Sat Jan 27, 2007 3:46 am
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

Moderator Emeritus


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

PostPosted: Sat Jan 27, 2007 4:16 am
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 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 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
Search our Forums:

Back to Top