I am trying to only print unique case numbers (which are located in the first 5 bytes of each input record). My input file structure is as in this example:
00001
00001
00002
00002
00002
00003
00004
00005
I should be able to read in the case number such as 0001 (or 00002, 00003, ...) and save that in a temp variable. Then compare the value of that temp variable to the case number of the current record being processed. When they do not match then I need to write the case number (as contained in the temp variable) to my output file. And then continue processing the remaining records.
So in the end, my output file should look similar to this one (note that only the last records with case number either 00001 or 00002 were written):
00001
00002
00003
00004
00005
Here is my code so far:
READ WORK FILE 1 #I-RECORD
IF #RECORD-READ = 0 DO
WRITE WORK 2 #OUT-HEADER
DOEND /* 510
ADD 1 TO #RECORD-READ
*
IF #AA-CASE NOT EQUAL ' ' DO
#CURRENT-CASE-NUM = #AA-CASE
IF #COUNT-CASES = 0 DO
#OLD-CASE-NUM = #AA-CASE
DOEND /* 570
*
IF #OLD-CASE-NUM NOT EQUAL #CURRENT-CASE-NUM DO
#OO-CASE-NUMBER = #OLD-CASE-NUM
* #OO-TOTAL-OF-MONTHS = 0
* #OO-TOTAL-OF-TRANSACTIONS = #COUNT-CASES
WRITE WORK 2 #OUTPUT-RECORD
#OLD-CASE-NUM = 0
DOEND
*
DISPLAY #CURRENT-CASE-NUM #OLD-CASE-NUM #COUNT-CASES
*
IF #OLD-CASE-NUM NOT EQUAL #CURRENT-CASE-NUM DO
#OO-CASE-NUMBER = #OLD-CASE-NUM
* #OO-TOTAL-OF-MONTHS = 0
* #OO-TOTAL-OF-TRANSACTIONS = #COUNT-CASES
WRITE WORK 2 #OUTPUT-RECORD
#OLD-CASE-NUM = 0
DOEND /* 610
ELSE DO
ADD 1 TO #COUNT-CASES
DOEND /* 710
DOEND /* 510
LOOP(0500)