Novice Programmer needs help doing something simple, MERGE 
Author Message
 Novice Programmer needs help doing something simple, MERGE

I have 2 files coming into the program that need to be merged, there is a
common key field but the rest of the data does not match,
1st file 69 characters, 2nd file 33 characters, the only field that matches
up is the key.  Can you send some examples of what my code should look like
or offer suggestions, I know this is a simple one, but my college books just
graze over it.
Thanks in advance




Sun, 03 Feb 2002 03:00:00 GMT  
 Novice Programmer needs help doing something simple, MERGE

Ray,

Try posting your code here, if your code is very long then just post the
problem area, and im very sure one of us can help you.

Simon R Hart
Eaton.

Quote:

> I have 2 files coming into the program that need to be merged, there is a
> common key field but the rest of the data does not match,
> 1st file 69 characters, 2nd file 33 characters, the only field that
matches
> up is the key.  Can you send some examples of what my code should look
like
> or offer suggestions, I know this is a simple one, but my college books
just
> graze over it.
> Thanks in advance





Sun, 03 Feb 2002 03:00:00 GMT  
 Novice Programmer needs help doing something simple, MERGE


Quote:
> I have 2 files coming into the program that need to be merged, there
is a
> common key field but the rest of the data does not match,
> 1st file 69 characters, 2nd file 33 characters, the only field that
matches
> up is the key.  Can you send some examples of what my code should look
like
> or offer suggestions, I know this is a simple one, but my college
books just
> graze over it.
> Thanks in advance



You have your basic 2 file match here.  I'm going to call your 69
character file FILE-A and the 33 character file FILE-B.  Basic code is:

    PERFORM READ-FILE-A-PARA
    PERFORM READ-FILE-B-PARA
    PERFORM MATCH-PARA UNTIL END-OF-FILE-A AND END-OF-FILE-B

MATCH-PARA.
    IF KEY-A = KEY-B
        PERFORM CREATE-OUTPUT-PARA
    ELSE
    IF KEY-A > KEY-B
        what you want to do in this case
        PERFORM READ-FILE-B-PARA
    ELSE
    IF KEY-A < KEY-B
        what you want to do in this case
        PERFORM READ-FILE-A-PARA
    END-IF
    END-IF
    END-IF
    .

READ-FILE-A-PARA.
    READ FILE-A AT END MOVE HIGH-VALUES TO KEY-A.

READ-FILE-B-PARA.
    READ FILE-B AT END MOVE HIGH-VALUES TO KEY-B.

CREATE-OUTPUT-PARA.
     what you want to do here
     WRITE OUTPUT-REC

If you are putting the 2 different records on the same output file then
your output file will be variable length and in your JCL the LRECL would
be 73 (that's 69 the larger record + 4 for the variable stuff).  Be sure
that your FD specifies variable as well.

Once you've coded this up save it in your forever file, you will
definately be doing this again and why reinvent the wheel?

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.



Sun, 03 Feb 2002 03:00:00 GMT  
 Novice Programmer needs help doing something simple, MERGE
I hope this one gets through....

I have 2 files coming into the program that need to be merged, there is a
common key field but the rest of the data does not match,
1st file 69 characters, 2nd file 33 characters, the only field that matches
up is the key.  Can you send some examples of what my code should look like
or offer suggestions, I know this is a simple one, but my college books just
graze over it.
Thanks in advance




Sun, 03 Feb 2002 03:00:00 GMT  
 Novice Programmer needs help doing something simple, MERGE

Quote:

>I have 2 files coming into the program that need to be merged, there is a
>common key field but the rest of the data does not match,
>1st file 69 characters, 2nd file 33 characters, the only field that matches
>up is the key.  Can you send some examples of what my code should look like
>or offer suggestions, I know this is a simple one, but my college books just
>graze over it.

I suggest that you do your own homework, please.

DD



Sun, 03 Feb 2002 03:00:00 GMT  
 Novice Programmer needs help doing something simple, MERGE

Quote:

>I have 2 files coming into the program that need to be merged, there is a
>common key field but the rest of the data does not match,

PROCESS.
    OPEN INPUT  FILE-1
                FILE-2
         OUTPUT FILE-3.
    PERFORM READ-FILE-1.
    PERFORM READ-FILE-2.
    PERFORM MERGE-FILES
        UNTIL (HIGH-VALUES = FILE-1-KEY AND FILE-2-KEY).
    CLOSE FILE-1 FILE-2 FILE-3.
    STOP RUN.

READ-FILE-1.
    READ FILE-1
       AT END
           MOVE HIGH-VALUES TO FILE-1-KEY.

READ-FILE-2.
    READ FILE-2
       AT END
           MOVE HIGH-VALUES TO FILE-2-KEY.

MERGE-FILES.
    IF (FILE-1-KEY NOT > FILE-2-KEY)
        <write FILE-1 to FILE-3>
        PERFORM READ-FILE-1
    else
        <write FILE-2 to FILE-3>
        PERFORM READ-FILE-2.
--

Sun Valley Systems    http://personal.bhm.bellsouth.net/~judmc
"For God so loved the world that He gave His only begotten Son, that
whoever believes in Him should not perish but have everlasting life."



Sun, 03 Feb 2002 03:00:00 GMT  
 Novice Programmer needs help doing something simple, MERGE

Quote:

> I hope this one gets through....

> I have 2 files coming into the program that need to be merged, there is a
> common key field but the rest of the data does not match,
> 1st file 69 characters, 2nd file 33 characters,

Ask yourself why the different length make a difference. Just match the
keys. Can you get duplicate keys? Does the output sequence matter when
you do?

As someone else suggested, take a stab & post here. Few of us want to do
some else's homework, but most are happy to help someone who's doing
his/her own.

Bill {*filter*}



Mon, 04 Feb 2002 03:00:00 GMT  
 Novice Programmer needs help doing something simple, MERGE

Quote:

> I have 2 files coming into the program that need to be merged, there
> is a common key field but the rest of the data does not match,
> 1st file 69 characters, 2nd file 33 characters, the only field that
> matches up is the key.  Can you send some examples of what my code
> should look like or offer suggestions, I know this is a simple one,
> but my college books just graze over it.

Look up balanced line algorithm.

There was a link posted about six months ago that described this
method.

Ken



Mon, 04 Feb 2002 03:00:00 GMT  
 Novice Programmer needs help doing something simple, MERGE

Quote:

> I hope this one gets through....

> I have 2 files coming into the program that need to be merged, there is a
> common key field but the rest of the data does not match,
> 1st file 69 characters, 2nd file 33 characters, the only field that matches
> up is the key.  Can you send some examples of what my code should look like
> or offer suggestions, I know this is a simple one, but my college books just
> graze over it.
> Thanks in advance


A Generalized Merge Algorithm in pseudo code:

Initialize and Open files
Read next filea record
If EOF-on-filea Then{set filea_key to high_values}
Read next fileb record
If EOF-on-fileb Then {set fileb_key to high_values}
While ~EOF-on-fileb | ~EOF-on-fileb
  {Case
    {(filea_key < fileb_key):
         {Process unmatched filea record and get next filea record
          }
     (filea_key = fileb_key):
         {If filea_key = high_values Then Leave loop
          Else {Merge filea record and fileb record and get next
                record for both filea and fileb
                }
         }
     (filea_key > fileb_key):
         {Process unmatched fileb record and get next fileb record
         }
    }
  }
Close files and other termination actions

As long as high-values is not an acceptable key value in the external
files, by forcing the fields used for the key comparisons to high-values
on an EOF, the loop logic doesn't need to handle EOF as a special case.
Translating this into acceptable COBOL, which requires resolving the
details of the merge process and how to handle unmatched records,
depends on the details of your specific application and is left as an
exercise to the reader.
--



Sat, 09 Feb 2002 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Novice Programmer Needs Help!

2. Novice Ada Programmer Stumped By Simple Type Declaration!

3. Need assistance with doing something [semi-LONG]

4. On helping a novice scheme programmer

5. Help a novice scheme programmer

6. HELP: novice Ada programmer looking for libraries ...

7. Help doing simple threading

8. help with something that ought to be simple

9. Novice having merge problem

10. Need Help on Database Merge

11. Merging Ada Code and HTML - Done!

12. VMARK merges with EASEL - the deal is done ...

 

 
Powered by phpBB® Forum Software