Page 1 of 1

How to compare two records of a file in REXX..

PostPosted: Thu Nov 14, 2013 9:45 am
by santosh bm
Hi...

I need to compare a field of two consecutive records present in a seq file. My seq file looks like below :

ELENAME1  COBOLB  14NOV2013
ELENAME2  COBOLB  14NOV2013
ELENAME3  COBOLB  14NOV2013
ELENAME3  PACKDB2 14NOV2013
ELENAME4  COBOLB  14NOV2013
ELENAME5  COBOLB  14NOV2013


I need to compare the current record element name with the previous record element name. i.e., ELENAME2 with ELENAME1, ELENAME3 with ELENAME2, ELENAME3 with ELENAME3 and so on.... when the two element names matches(as in case of ELENAME3) i need to process a subroutine, else the code flow will continue.

Please help me out, how to do this...??

Re: How to compare two records of a file in REXX..

PostPosted: Thu Nov 14, 2013 2:32 pm
by NicC
read 1st records (EXECIO); until eof (DO WHILE); read next record (EXECIO); isolate the fields (PARSE); compare and process, or not (IF/THEN); repeat (END); finish program (EXIT)

(Fixed up to properly reflect the requirement as stated :roll:)

Re: How to compare two records of a file in REXX..

PostPosted: Thu Nov 14, 2013 4:22 pm
by prino
NicC wrote:read 2 records (EXECIO); until eof (DO WHILE); isolate the fields (PARSE); compare and process, or not (IF/THEN/ELSE); read 2 records (EXECIO); repeat (END); finish program (EXIT)

Then you'll miss out on comparing record 2 with record 3...

Re: How to compare two records of a file in REXX..

PostPosted: Thu Nov 14, 2013 4:43 pm
by enrico-sorichetti
where are You facing problems ... the logic or the code ?

here is a hint for the logic ...

read one record into the old_record_buffer
do while more records left
    read one record into the new_record_buffer
    compare old and new
    if old < new then
        move new to old
        iterate/continue
    if old = new
       process as needed
       move new to old
       iterate/continue
   if old > new
      take care of the error
end
process the record left ( the new one )


for the equal case add the proper flags to check for more than one duplicate

Re: How to compare two records of a file in REXX..

PostPosted: Thu Nov 14, 2013 5:16 pm
by NicC
Ah - *******! First read through I thought he was comparing consecutive pairs not just a simple next v last. So all you need is Enrico's logic but I am not sure is < or > is relevant? The requirement just seems to be "IF equal values THEN process. Get next record"

Re: How to compare two records of a file in REXX..

PostPosted: Thu Nov 14, 2013 5:38 pm
by enrico-sorichetti
implementing full sequence checking is one of my pet peeves ... ;)