Compare consecutive records in a file using a KEY



Unicenter CA-Easytrieve Plus Report Generator: CA's information retrieval and data management tool

Compare consecutive records in a file using a KEY

Postby surya4ug » Mon Mar 29, 2010 6:26 am

Hello,

i have a requirement to compare consecutive records of a file, using a key and write the output file when the records don't match. For example, the file below has 5 fields - with the 1st, 2nd and 3rd fields forming the 'key'

UID                  FNAME   LNAME    MNAME 
----------------------------------------
12345678910    BBBBBB   CCCCC    DDDDDD
12345678910    BBBBBB   CCCCC    DDDDDD
12345678910    BBBBBB   CCCCC    DDDDDD
12345678911    XXXXXX   JJJJJJ    DDDDDD
12345678911    AAAAAA  JJJJJJ   DDDDDD
12345678911    AAAAAA  JJJJJJ   DDDDDD
12345678912    XYZXXX    JJTIJJ   DDDDDD


UID - UNique ID ( 1, 11 )
FNAME - first name ( 20,20 )
LNAME - last name ( 50,40 )
MNAME - middle name ( 120,20 )


If we look at the first three records - for the UID 12345678910, same FNAME and LNAME values exist. I don't want to write any of such records
the next one - 12345678911 has FNAMEs XXXXXX, AAAAAA in the records 4th,5th records respectively and the 6th record has FNAME and LNAME
values repeating. So, we need to capture only the 4th and 5th records for 12345678911.


To summarize, any change in the FNAME + LNAME combination in consecutive records for a particular UID should be written to the output file.


Desired output
---------------

UID                   FNAME   LNAME  MNAME 
-------------------------------------------------
12345678911    XXXXXX   JJJJJJ   DDDDDD
12345678911    AAAAAA  JJJJJJ   DDDDDD
12345678912    XYZXXX   JJTIJJ   DDDDDD



I'm a novice as far as ezytrieve is concerned and tried acheiving this result thru SORT but it took about 10 steps to achieve it.

I was told that ezytrive can crack this in a much better way with simpler and smaller no of steps.

please advice. Thanks for your assistance in advance.
surya4ug
 
Posts: 11
Joined: Mon Mar 29, 2010 3:47 am
Has thanked: 0 time
Been thanked: 0 time

Re: Compare consecutive records in a file using a KEY

Postby dick scherrer » Mon Mar 29, 2010 6:50 am

Hello and welcome to the forum,

tried acheiving this result thru SORT but it took about 10 steps to achieve it.
A "solution" best abondoned.

Suggest that before you attempt the code you work thru the requirement on paper. To do this the rules must be clearly deifned. It is not clear why the last record is in the output - there was no change. Indeed, there was only one record with the 12345678912 uid.

In Easytrieve (or COBOL for that matter), one way would be to use working-data fields and compare values from the current record against the same values from the previous record.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Compare consecutive records in a file using a KEY

Postby surya4ug » Mon Mar 29, 2010 7:40 am

Hello,

thanks for your inputs. I'm sorry about the last record. I forgot to mention that, UIDs that have just 1 entry in the input file, may be excluded as well.

I m very new to using the working-data fields, so if one of you could give me a rough draft of how to code the logic, It would be great to start off with

Thanks!!
surya4ug
 
Posts: 11
Joined: Mon Mar 29, 2010 3:47 am
Has thanked: 0 time
Been thanked: 0 time

Re: Compare consecutive records in a file using a KEY

Postby dick scherrer » Mon Mar 29, 2010 10:40 am

Hello,

Suggest you look in the Easytrive documentation (or even COBOL documentation) to see some info about working-data fields. While the syntax is different, the concept is the same. These are data items (variables) that are not in an input or output file but are there for use within the program. You (as the coder) have complete control over them.

Using working-data fields is one of the first things learned when studying a programming language.

Unfortunately, we are not able to provide "classroom instruction". . .

You might also look at some other Easytrieve and COBOL programs that are already in use on your system.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times


Return to CA-Easytrieve

 


  • Related topics
    Replies
    Views
    Last post