×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Multi File Processing - Merge

Multi File Processing - Merge

Multi File Processing - Merge

(OP)
I'm trying to design a Purge/Merge program that uses 4 input files and merges them into one output file. The issue is I want to keep track of all four files and which record I'm processing, without having to develop a lot of spegetti code. Has anyone designed such a neatly coded program?

RE: Multi File Processing - Merge

CODE

01  WS-x-key.
88  x-AT-END Value High-Value.
  etc.


Perform Until A-AT-END and B-AT-END and C-AT-END and D-AT-END
  If A-KEY < B-KEY
    If A-KEY < c-KEY
      If A-KEY < D-KEY
        Merge-A
      Else
        Merge-D
      End-If
    Else
      If C-KEY < D-KEY
        Merge-C
      Else
        Merge-D
      End-If
   Else
  If B-KEY < c-KEY
    If B-KEY < D-KEY
      Merge-B
    Else
      Merge-D
    End-IF
  Else
    If C-KEY < D-KEY
       Merge-C
    Else
       Merge-D
    End-If
  End-If
End-Perform

Merge-x.
  Write from x
  Read x
    At End
       Move High-VALUE to WS-x-KEY
    Not At End
       MoVE x-FD-KEY   TO ws-x-key
       {Note:  This may actuallly be a series of moves if the key is complex.}
  End-Read
  .    
      

RE: Multi File Processing - Merge

You may want to look at this a little closer webrabbit.
 At the beginning ....

  If A-KEY < B-KEY
    If A-KEY < c-KEY
      If A-KEY < D-KEY
        Merge-A
      Else
        Merge-D
      End-If

You're making a big assumption in the ELSE.  You don't know how D-KEY relates to B-KEY and C-KEY.  All you know is that it is greater than A-KEY.  Just because you know that A-KEY is less than B-KEY and C-KEY, that doesn't mean that D-KEY is also less than those two.  The ELSE needs to verify that D-KEY is less than both B-KEY and C-KEY before you can merge D-KEY.

The code needs to be a little more complex than what you have written.

RE: Multi File Processing - Merge

You are right.  I will have to rethink it.

RE: Multi File Processing - Merge

(OP)
Thanks for your input webrabbit, the code you provided is close to what I'm see today, and I wanted to change that spigette code. The files are in sort order so that my take some of the guess work out it, the files have several different record types.
If file-1-ssn = file-2-ssn and = file-3
  print the elig rec for all 3 files.


I need to know if there's a more modern approach then a bunch of IF statements, perhaps using the Evaluate to make it easier to read and maintain.

RE: Multi File Processing - Merge

Well, there are actually only four conditions you need to test, but the tests are complex in COBOL. (Some other language may have a function to find the lowest of a set of strings.)
1) A<=B and A<=c and A<=D  {A is not greater than any other}
2) B<A and B<=C and B<=D  {B is not greater than any other}   
3) c<A and C<B AND C<=D  {C is not greater than any other}
4) other {D is the lowest}  
To set this in an Evaluate statement, I would do it as follows:

CODE

Evaluate A<=B A<=C A<=D B<=C B<=D c<=D
  When True True True Any Any Any *> tesing A
    Process A
  When False Any Any True True Any *> testing B
    Process B
  When Any False Any False Any True *> testing C
    Process c
  When Other
    Process D
End Evalueate
Note that there are three True/False tests and three irrelevants (Any) on the first three When's.

RE: Multi File Processing - Merge

webrabbit is showing some uncharacteristic syntactical problems, by omitting the ALSO keyword and a hyphen.    There is also, perhaps, a better way to write this in an EVALUATE that I find more readable.

CODE

Evaluate TRUE also TRUE also TRUE
  When A <= B also A <= C also A <= D  *> testing A
    Process A
  When A > B  also B <= C also B <= D  *> testing B
    Process B
  When A > C  also B > C  also C <= D  *> testing C
    Process C
  When Other
    Process D
End-Evaluate

(And, lest I make my own errors, 'typed, not tested!')

Tom Morrison
Micro Focus

RE: Multi File Processing - Merge

Yes, what I put in the 2nd time was intended to be a guideline, not actual code.  Tom, your answer is much more elegant than mine.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close