IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Need to compare the current file with the previous file


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
arvind.m

Active User


Joined: 28 Aug 2008
Posts: 205
Location: Hyderabad

PostPosted: Fri Jul 31, 2009 3:18 pm
Reply with quote

Hi

I have the following requirement:
Code:

current file: sorted.
state-id     9(05)
supplier     9(07)
item          9(07)
code          9(14)
qty            9(05)


previous file: sorted.
state-id     9(05)
supplier     9(07)
item          9(07)
code          9(14)
qty            9(05)


Now i need to compare the current file with the previous file and if there is any difference i need to write to an output file. But while comparing i need to check all the fields from one file to other.

can anyone tell me how to implement this type of file compare. if the take all all the file fields as KEY and do a file compare like

Code:

IF A>B
    PERFORM
    READ FILE B
ELSE
  IF  B>A
  PERFORM
  READ FILE A
ELSE
  READ FILEA
  READ FILEB
END-IF.


the PERFORM will write to the output file (difference file).
will the above logic work. if anyone has other way to do the file compare will share with me. even SORT will also work.

thanks,
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri Jul 31, 2009 3:25 pm
Reply with quote

Below link can help you..
www.ibmmainframes.com/viewtopic.php?t=22649
Back to top
View user's profile Send private message
arvind.m

Active User


Joined: 28 Aug 2008
Posts: 205
Location: Hyderabad

PostPosted: Fri Jul 31, 2009 3:55 pm
Reply with quote

Hi Sambhaji,
thank you for the link.

But i need to compare five fields of one file to five fields to other file. Does making all the five fields(GROUP ITEM) as a part of key will work?

for example:
KEY1
state-id 9(05)
supplier 9(07)
item 9(07)
code 9(14)
qty 9(05)

KEY2
state-id 9(05)
supplier 9(07)
item 9(07)
code 9(14)
qty 9(05)

KEY1 > KEY2

KEY1 < KEY2

KEY1 = KEY2
Back to top
View user's profile Send private message
arvind.m

Active User


Joined: 28 Aug 2008
Posts: 205
Location: Hyderabad

PostPosted: Fri Jul 31, 2009 10:18 pm
Reply with quote

can anyone help or share something.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jul 31, 2009 10:40 pm
Reply with quote

Are the fields adjacent to each other so you can treat them as one field?

It appears that you're doing more than you have to. Why not just say
Code:
IF  state-id <of file 1> NOT EQUAL state-id <of file 2>
OR  supplier <of file 1> NOT EQUAL supplier <of file 2>
OR  item <of file 1> NOT EQUAL item <of file 2>
OR  code <of file 1> NOT EQUAL code <of file 2>
OR  qty <of file 1> NOT EQUAL qty <of file 2>
    <write to output file>
END-IF.
where the <of file ?> are replaced by appropriate qualification. You don't really care about file 1's data being less than or greater than file 2's , just that they're not equal.

As far as read logic goes, just compare the fields you sorted the files on -- which is easier if they're adjacent, but not impossible otherwise.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Aug 01, 2009 6:43 am
Reply with quote

Hello,

One easy thing to do if the "key" fields are not adjacent is to move them to a ws group field immediately after each read (prior to the compare). Then the compare for file matching can still be a single field.

If there is a match on the key, then the individual fields can be compared and whatever message or data output can be created. If the keys do not match, show the "key" as an add or a delete as appropriate.
Back to top
View user's profile Send private message
arvind.m

Active User


Joined: 28 Aug 2008
Posts: 205
Location: Hyderabad

PostPosted: Mon Aug 03, 2009 2:44 pm
Reply with quote

Thank you Robert/dick,

Quote:

Are the fields adjacent to each other so you can treat them as one field?


yes the fields are in the same order. The layout is:


Code:

01 WS-CURR-FL.
     05 state-id      PIC 9(05)
     05 supplier      PIC 9(07)
     05 Item          PIC 9(07)
     05 code          PIC 9(14)
     05 qty            PIC  9(05)


but since a group item is alphanumeric, does moving 99999...99 (max value) to the KEY makes sense?

Thanks,
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Aug 03, 2009 4:49 pm
Reply with quote

Sure -- as long as none of your subfields can have a valid value of all 9s.
Code:
MOVE ALL '9' TO WS-CURR-FL.
would do it.
Back to top
View user's profile Send private message
arvind.m

Active User


Joined: 28 Aug 2008
Posts: 205
Location: Hyderabad

PostPosted: Mon Aug 03, 2009 5:49 pm
Reply with quote

Hi
i'm getting a file status of 46.

Quote:

FILE STATUS 46

A sequential READ statement was attempted on a file open in the input or I-O mode and no valid next record had been established because:
1. The preceding READ statement was unsuccessful but did not cause an at end condition
2. The preceding READ statement caused an at end condition



the below is the code for read the current file. after program reaching the end of file of current i'm getting the file status of 46.

Code:

 2000-READ-CURR-FILE.                                             
    READ EDW-EXTRACT-CURR                                       
        AT END                                                   
           MOVE 'Y'                 TO  WS-CURR-EOF-SW           
           MOVE ALL '9' TO WS-CURR-KEY                           
*           MOVE WS-KEY-MAX          TO WS-CURR-KEY               
        NOT AT END                                               
           MOVE CURR-DIVISION-NBR   TO  WS-CURR-KEY-DIVISION-NBR
           MOVE CURR-SUPP-NBR       TO  WS-CURR-KEY-SUPP-NBR     
           MOVE CURR-ITEM-NBR       TO  WS-CURR-KEY-SUPP-NBR     
           MOVE CURR-UPC            TO  WS-CURR-KEY-UPC         
           MOVE CURR-PACK           TO  WS-CURR-KEY-ITEM-NBR     
           ADD  1                   TO WS-CURR-CNT               
    END-READ.                                                   



below is the main processing para.
Code:

IF WS-PREV-KEY > WS-CURR-KEY                         
   MOVE  CURR-DIVISION-NBR    TO O-DIVISION-NBR     
   MOVE  CURR-SUPP-NBR        TO O-SUPP-NBR         
   MOVE  CURR-ITEM-NBR        TO O-ITEM-NBR         
   MOVE  CURR-UPC             TO O-UPC               
   MOVE  CURR-PACK            TO O-PACK             
   WRITE EDW-EXTRACT-DIFF-REC FROM  O-EDW-EXTRACT   
   ADD   +1                   TO WS-R-CNT           
   PERFORM 2000-READ-CURR-FILE                       
ELSE                                                 
   IF WS-PREV-KEY < WS-CURR-KEY                     
      MOVE  PREV-DIVISION-NBR    TO O-DIVISION-NBR   
      MOVE  PREV-SUPP-NBR        TO O-SUPP-NBR       
      MOVE  PREV-ITEM-NBR        TO O-ITEM-NBR       
      MOVE  PREV-UPC             TO O-UPC           
      MOVE  PREV-PACK            TO O-PACK           
      WRITE EDW-EXTRACT-DIFF-REC FROM  O-EDW-EXTRACT
      ADD   +1                   TO WS-R-CNT         
      PERFORM 2100-READ-PREV-FILE                   
       ELSE                               
          PERFORM 2000-READ-CURR-FILE     
          PERFORM 2100-READ-PREV-FILE     
       END-IF                             
    END-IF.                               
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Aug 03, 2009 5:54 pm
Reply with quote

Code:
 2000-READ-CURR-FILE.                                             
    IF  WS-CURR-KEY NOT = ALL '9'
        READ EDW-EXTRACT-CURR   
.
.
.
 
You're setting the key when you hit the end of file, but if you don't test for it and NOT read the file after you've hit the end, you are going to get file status 46 errors.
Back to top
View user's profile Send private message
arvind.m

Active User


Joined: 28 Aug 2008
Posts: 205
Location: Hyderabad

PostPosted: Mon Aug 03, 2009 6:54 pm
Reply with quote

Thank you robert.
the issue is now resolved. it was my mistake. i did not propely MOVE the input value into the key.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 4
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top