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



IBM's Command List programming language & Restructured Extended Executor

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

Postby santosh bm » Thu Nov 14, 2013 9:45 am

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...??
santosh bm
 
Posts: 14
Joined: Tue Oct 29, 2013 11:53 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby NicC » Thu Nov 14, 2013 2:32 pm

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:)
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

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

Postby prino » Thu Nov 14, 2013 4:22 pm

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...
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 635
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 28 times

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

Postby enrico-sorichetti » Thu Nov 14, 2013 4:43 pm

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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

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

Postby NicC » Thu Nov 14, 2013 5:16 pm

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"
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

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

Postby enrico-sorichetti » Thu Nov 14, 2013 5:38 pm

implementing full sequence checking is one of my pet peeves ... ;)
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post