-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compares files
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
* C Bristow / 2019.05.09 / Rocket Software | ||
* Compare Record ids and data between two files and put the difference in a 3rd file | ||
* | ||
PROGRAM.NAME="COMPARE.FILE" | ||
DIFF.FILE = "DIFF.OUT" | ||
COMMAND = @SENTENCE | ||
CONVERT " " TO @FM IN COMMAND | ||
NUM.SENTENCE.ELEMENTS = DCOUNT(COMMAND,@FM) | ||
FILE1 = COMMAND<NUM.SENTENCE.ELEMENTS-1> | ||
FILE2 = COMMAND<NUM.SENTENCE.ELEMENTS> | ||
* | ||
IF (FILE2 = PROGRAM.NAME) OR (NUM.SENTENCE.ELEMENTS < 3) THEN | ||
CRT "COMPARE.FILES <file1> <file2>" | ||
CRT "Compares what is in file1 not in file 2." | ||
CRT "Writes missing or different record ids and record data to ":DIFF.FILE | ||
STOP | ||
END | ||
* CREATE THE FILE TO STORE FILE DIFFERENCE | ||
CMD = "DELETE.FILE ":DIFF.FILE; EXECUTE CMD CAPTURING Ignore | ||
CMD = "CREATE.FILE ":DIFF.FILE:" 30 101 4 64BIT"; EXECUTE CMD CAPTURING Ignore | ||
* OPEN ALL FILES | ||
OPEN FILE1 TO F1 ELSE STOP "CAN'T OPEN ":FILE1 | ||
OPEN FILE2 TO F2 ELSE STOP "CAN'T OPEN ":FILE2 | ||
OPEN DIFF.FILE TO F3 ELSE STOP "CAN'T OPEN ":DIFF.FILE | ||
* SELECT FILE1 KEYS | ||
SELECT F1 | ||
* START LOOPING THROUGH RECORD KEYS | ||
COUNT=0 | ||
20* | ||
READNEXT RECORD.ID ELSE | ||
PRINT 'FILE COMPLETE. NUMBER OF RECORDS SCANNED: ',COUNT | ||
CLOSE F1; CLOSE F2; CLOSE F3 | ||
STOP | ||
END | ||
* READ RECORD DATA FOR RECORD ID IN FILE1 | ||
READ F1.RECORD.DATA FROM F1,RECORD.ID ELSE | ||
CRT "CAN'T READ RECORD.ID :":RECORD.ID | ||
END | ||
* COUNT RECORD.ID PROCESSED | ||
COUNT+=1 | ||
* READ RECORD DATA FOR RECORD ID IN FILE2 | ||
READ F2.RECORD.DATA FROM F2,RECORD.ID THEN | ||
RECORD.ID.FLAG = 1 | ||
END | ||
ELSE | ||
* RECORD.ID FROM FILE1 NOT IN FILE2 WRITE IN DIFF.FILE | ||
RECORD.ID.FLAG = 0 | ||
END | ||
* CHECK IF THERE'S ANY DIFFENCE IN RECORD DATA | ||
RECORD.DIFF=EQS(F1.RECORD.DATA, F2.RECORD.DATA) | ||
* IF ID NOT IN FILE2 OR ID RECORD IN FILE1/FILE2 IS DIFFERENCE WRITE ID AND RECORD TO DIFF.FILE | ||
IF RECORD.DIFF=0 OR RECORD.ID.FLAG=0 THEN | ||
WRITE F1.RECORD.DATA TO F3, RECORD.ID | ||
END | ||
GOTO 20 |