Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...(I) have been able to get my problems solved from past messages and also new posts that other users have responded to promptly..."

Geography

Where in the world do Tek-Tips members come from?
DarkByte (Programmer)
22 Feb 12 10:04
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?

Helpful Member!  webrabbit (MIS)
22 Feb 12 12:54

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
  .    
      
coboldeke (Programmer)
29 Feb 12 13:44
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.
webrabbit (MIS)
29 Feb 12 16:58
You are right.  I will have to rethink it.
DarkByte (Programmer)
2 Mar 12 7:56
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.
webrabbit (MIS)
2 Mar 12 13:33
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.
k5tm (Vendor)
2 Mar 12 17:45
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

webrabbit (MIS)
4 Mar 12 10:26
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.

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!

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