Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking for duplicates and rewrite

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am trying to search all hm-ssn-2 for duplicate ssn#'s but I am having problems. It will only search the hm-ssn-2 within each record.


01 NEWMAST-DATA-2.
03 HMFN-ID-2 PIC X(09).
03 HMFN-SS-ID-2 PIC 9(09).
03 FILLER PIC 9(08).
03 HMFN-LNAME-2 PIC X(20).
03 HMFN-FNAME-2 PIC X(14).
03 FILLER PIC X(498).
03 HMFN-MEMBERS-2.
05 HM-MEMBERS-2 OCCURS 23 TIMES.
07 HM-FNAME-2 PIC X(14).
07 HM-LNAME-2 PIC X(20).
07 HM-SSN-2 PIC 9(09).
07 HM-DOB-2 PIC 9(08).
03 FILLER PIC X(317).


 
I am guessing that your goal is to detect duplicate SSN within a file the record description for which is provided. Correct?

If so, then SEARCH is not the verb for you. SEARCH acts upon an in-memory array (defined by OCCURS) only.

There would be several applicable techniques to detect duplicate SSNs, but rather than enumerate them, could you provide a better problem description?
Tom Morrison
 
I want to look for all duplicate ssn numbers within a table that is within a record and when I find each duplicate, I will give it a new number and have it rewrite the record.

 
It will only find the duplicate ssn#'s within that specific record. I want it to check all records and all hm-ssn-2's in all records. When I find the 1st duplicate, I want to change the ssn# and rewrite the record, then go to the next duplicate ssn# and rewrite that one.
 
Hi Bead,

If I'm reading you correctly, the simplest way to do that is to:

Read each record and create an output rec for each ssn you find in the table for each IP rec. For example, if you have 5 input recs, each containing 20 ssn in the table, you will write 100 OP recs, each containing a ssn.

This done, sort the OP recs; read the sorted file and collect all the ssn's that are dupes; arrange them in a dupes table and finally read the original IP again and match each ssn against the dupes table.

The 1st occurrance of the ssn you'll by-pass after marking that ssn as "found" in the table. Subsequent occurrances (i.e. a "found" indicator was previously set in the dupes table for the ssn) encountered will be subject to your special processing.

This can all be done in one pgm using the SORT verb w/input & output procedures.

Let us know how you make out.

HTH, Jack.

P.S. To find the dupes you may want to to an initial read before you start the loop (sorry Stephen :)). It will simplify the dupe check logic.
 
I have that set up, but then how do I rewrite each records.

Here is my code so far, all I get are the duplicate 9' but only within certain records, I want all duplicates.

IDENTIFICATION DIVISION.
PROGRAM-ID. 221MRGE6.
AUTHOR. DEIDRE DOUGHERTY
DATE-WRITTEN. 12/2001.
********************************************************
* PROPERTY OF U.S.D.A *
********************************************************
* UNIT PROLOG *
********************************************************
*Program/Unit name: 213MRGE5.CBL *
*System: Automated Inventory System (AIS) *
* *
*======================================================*
* *
*Internal References/Files: *
* *
*Name Use Type Description *
*------------- ---- ----- ----------------------*
*HH0932 I Data HOUSEHOLD MEMBERS FROM*
* 9-32. *
*HHMF I Data HOUSEHOLD MASTER LIST *
* *
*NEWMAST Data OUTPUT NEW MASTER FILE*
* TEMP *
* *
*SORT-FILE I/O Data SORTED DATA *
*SORT-WORK O Data SORTED DATA FILE *
* *
* *
* *
*======================================================*
* *
*Library files used: *
*Name Use Type Description *
*------------- ---- ----- ----------------------*
*HH0932.LIB I I HOUSEHOLD MEMBERS FROM*
* 9-32 FORMAT *
*HHMF.LIB I I HOUSEHOLD MASTER FILE *
* *
********************************************************
* NOTES: N/A *
* *
********************************************************
* MODIFICATION LOG *
********************************************************
* REVISION HISTORY *
********************************************************
* CHANGE DATE PROGRAMMER DESCRIPTION *
*------------------------------------------------------*
*12/2001 D. DOUGHERTY CREATED MERGE PROGRAM *
********************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT HHMF-FILE
ASSIGN TO DISK
ORGANIZATION IS INDEXED
ACCESS MODE IS SEQUENTIAL
RECORD KEY IS HHMF-KEY.
SELECT HH0932-FILE
ASSIGN TO DISK
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS HH0932-KEY.
SELECT NEW-HHMF-FILE
ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT NEWMAST-FILE
ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT ERROR-FILE
ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT SORT-WORK
ASSIGN TO DISK.
SELECT SORT-FILE
ASSIGN TO DISK.

*
*
DATA DIVISION.
FILE SECTION.

FD HHMF-FILE
LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS '\FDPSYS\TABLES\DATA\HHMF.DAT'.
01 HHMF-REC.
03 HHMF-KEY PIC X(09).
03 FILLER PIC X(775).
FD HH0932-FILE
LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS '\FDPSYS\TABLES\DATA\HH0932.DAT'.
01 HH0932-REC.
03 HH0932-KEY PIC X(09).
03 FILLER PIC X(1224).
FD NEWMAST-FILE
LABEL RECORDS IS STANDARD
VALUE OF FILE-ID IS 'D:\SEQ-DATA\221MAST1.DAT'.
01 NEWMAST-REC PIC X(2048).
FD NEW-HHMF-FILE
LABEL RECORDS IS STANDARD
VALUE OF FILE-ID IS 'D:\SEQ-DATA\NEWHHMF.DAT'.
01 NEW-HHMF-REC PIC X(2048).
FD ERROR-FILE
LABEL RECORDS IS STANDARD
VALUE OF FILE-ID IS 'D:\SEQ-DATA\ERROR.DAT'.
01 ERROR-REC PIC X(70).
SD SORT-WORK.
01 SORT-REC.
03 SR-ID PIC X(09).
03 SR-SSN PIC 9(09).
03 FILLER PIC X(2030).
FD SORT-FILE
LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS 'D:\SEQ-DATA\SORT.WRK'.
01 SF-REC PIC X(2048).
* 01 SF-REC PIC X(784).



*
*
WORKING-STORAGE SECTION.
*
01 N-IDX PIC 9(06).
01 B-IDX PIC 9(09) VALUE ZERO.
01 W-IDX PIC 9(06).
01 BR-IDX PIC 9(06).
01 IDX PIC 9(06).
01 BAD-CNT PIC 9(04) VALUE ZERO.
01 OLD-CNT PIC 9(06) VALUE ZERO.
01 OLD-MEM-CNT PIC 9(06) VALUE ZERO.
01 NEW-CNT PIC 9(06) VALUE ZERO.
01 WORK-CNT PIC 9(06) VALUE ZERO.
01 SORT-CNT PIC 9(06) VALUE ZERO.
01 MEMBER-CNT PIC 9(06) VALUE ZERO.
01 NEW-SSN PIC 9(09).

COPY \SOURCE\HH0932.LIB.
COPY \SOURCE\HHMF.LIB.
COPY \SOURCE\DATE2000.LIB.

01 NEWMAST-DATA.
03 HMFN-ID PIC X(09).
03 HMFN-SS-ID PIC 9(09).
03 HMFN-BIRTHDATE PIC 9(08).
03 HMFN-LNAME PIC X(20).
03 HMFN-FNAME PIC X(14).
03 HMFN-ADDRESS PIC X(23).
03 HMFN-CITY PIC X(13).
03 HMFN-STATE PIC X(02).
03 HMFN-ZIP.
05 HMFN-ZIP1 PIC 9(05).
05 HMFN-ZIP2 PIC 9(04).
03 HMFN-COUNTY PIC X(02).
03 HMFN-LOCATION PIC X(02).
03 HMFN-PHONE.
05 HMFN-PH1 PIC 9(03).
05 HMFN-PHALL.
07 HMFN-PH2 PIC 9(03).
07 HMFN-PH3 PIC 9(04).
03 HMFN-HHSIZE PIC 9(02).
03 HMFN-ETHNIC.
05 HMFN-ETHNIC-CODE-1 PIC X(01).
05 HMFN-ETHNIC-CODE-2 PIC X(01).
03 HMFN-CERTDATE PIC 9(08).
03 HMFN-TERMDATE PIC 9(06).
03 HMFN-STATUSCODE PIC X(01).
03 HMFN-ISSUEDATA PIC X(72).
03 HMFN-HHISSUESIZE PIC X(24).
03 HMFN-PCT1.
05 HMFN-PC1.
07 HMFN-PCYR1 PIC 9(04).
07 HMFN-PCYR-R1 REDEFINES HMFN-PCYR1.
09 HMFN-PCC1 PIC 9(02).
09 HMFN-PCY1 PIC 9(02).
07 HMFN-PCM1 PIC 9(02).
05 HMFN-PT1.
07 HMFN-PTYR1 PIC 9(04).
07 HMFN-PTYR-R1 REDEFINES HMFN-PTYR1.
09 HMFN-PTC1 PIC 9(02).
09 HMFN-PTY1 PIC 9(02).
07 HMFN-PTM1 PIC 9(02).
03 HMFN-PCT2.
05 HMFN-PC2.
07 HMFN-PCYR2 PIC 9(04).
07 HMFN-PCYR-R2 REDEFINES HMFN-PCYR2.
09 HMFN-PCC2 PIC 9(02).
09 HMFN-PCY2 PIC 9(02).
07 HMFN-PCM2 PIC 9(02).
05 HMFN-PT2.
07 HMFN-PTYR2 PIC 9(04).
07 HMFN-PTYR-R2 REDEFINES HMFN-PTYR2.
09 HMFN-PTC2 PIC 9(02).
09 HMFN-PTY2 PIC 9(02).
07 HMFN-PTM2 PIC 9(02).
03 HMFN-PCT3.
05 HMFN-PC3.
07 HMFN-PCYR3 PIC 9(04).
07 HMFN-PCYR-R3 REDEFINES HMFN-PCYR3.
09 HMFN-PCC3 PIC 9(02).
09 HMFN-PCY3 PIC 9(02).
07 HMFN-PCM3 PIC 9(02).
05 HMFN-PT3.
07 HMFN-PTYR3 PIC 9(04).
07 HMFN-PTYR-R3 REDEFINES HMFN-PTYR3.
09 HMFN-PTC3 PIC 9(02).
09 HMFN-PTY3 PIC 9(02).
07 HMFN-PTM3 PIC 9(02).
03 HMFN-PCT4.
05 HMFN-PC4.
07 HMFN-PCYR4 PIC 9(04).
07 HMFN-PCYR-R4 REDEFINES HMFN-PCYR4.
09 HMFN-PCC4 PIC 9(02).
09 HMFN-PCY4 PIC 9(02).
07 HMFN-PCM4 PIC 9(02).
05 HMFN-PT4.
07 HMFN-PTYR4 PIC 9(04).
07 HMFN-PTYR-R REDEFINES HMFN-PTYR4.
09 HMFN-PTC4 PIC 9(02).
09 HMFN-PTY4 PIC 9(02).
07 HMFN-PTM4 PIC 9(02).
03 HMFN-PCT5.
05 HMFN-PC5.
07 HMFN-PCYR5 PIC 9(04).
07 HMFN-PCYR-R5 REDEFINES HMFN-PCYR5.
09 HMFN-PCC5 PIC 9(02).
09 HMFN-PCY5 PIC 9(02).
07 HMFN-PCM5 PIC 9(02).
05 HMFN-PT5.
07 HMFN-PTYR5 PIC 9(04).
07 HMFN-PTYR-R5 REDEFINES HMFN-PTYR5.
09 HMFN-PTC5 PIC 9(02).
09 HMFN-PTY5 PIC 9(02).
07 HMFN-PTM5 PIC 9(02).
03 HMFN-MESSAGE PIC X(256).
03 HMFN-UPDATED PIC X(01).
03 HMFN-RESIDENCY PIC X(01).
03 HMFN-CATEGORY PIC X(03).
03 HMFN-ELIGIBLE PIC X(01).
03 HMFN-MEMBERS.
05 HM-MEMBERS OCCURS 23 TIMES.
07 HM-FNAME PIC X(14).
07 HM-LNAME PIC X(20).
07 HM-SSN PIC 9(09).
07 HM-DOB PIC 9(08).
03 HMFN-SELF-EMPLOYED PIC X(01).
03 HMFN-TOTAL-RESOURCES PIC 9(06)V99.
03 HMFN-FREQUENCY OCCURS 4 TIMES.
05 HMFN-FREQUENCY-CODE PIC X(01).
03 HMFN-REST.
05 HMFN-EARNED-INCOME OCCURS 4 TIMES.
07 HMFN-EARNED PIC 9(06)V99.
05 HMFN-UNEARNED-INCOME OCCURS 4 TIMES.
07 HMFN-UNEARNED PIC 9(06)V99.
05 HMFN-STUDENT-INCOME OCCURS 4 TIMES.
07 HMFN-AMOUNT-REC PIC 9(06)V99.
07 HMFN-TUITION PIC 9(06)V99.
07 HMFN-S-DATE-BEG PIC 9(06).
07 HMFN-S-DATE-END PIC 9(06).
05 HMFN-DEPENDENT-CARE OCCURS 3 TIMES.
07 HMFN-D-CARE PIC 9(03)V99.
05 HMFN-CHILD-SUPPORT OCCURS 3 TIMES.
07 HMFN-C-CARE PIC 9(03)V99.
05 HMFN-MEDICARE-INS OCCURS 3 TIMES.
07 HMFN-M-INSURANCE PIC 9(03)V99.
05 HMFN-MONTH-INCOME-LIMIT PIC 9(03)V99.
03 FILLER PIC X(78).

01 NEWMAST-DATA-2.
03 HMFN-ID-2 PIC X(09).
03 HMFN-SS-ID-2 PIC 9(09).
03 FILLER PIC 9(08).
03 HMFN-LNAME-2 PIC X(20).
03 HMFN-FNAME-2 PIC X(14).
03 FILLER PIC X(498).
03 HMFN-MEMBERS-2.
05 HM-MEMBERS-2 OCCURS 23 TIMES.
07 HM-FNAME-2 PIC X(14).
07 HM-LNAME-2 PIC X(20).
07 HM-SSN-2 PIC 9(09).
07 HM-DOB-2 PIC 9(08).
03 FILLER PIC X(317).




01 HOLD-DATA.
03 HOLD-ID PIC X(09).
03 HOLD-SS-ID PIC 9(09).
03 HOLD-LNAME PIC X(20).
03 HOLD-FNAME PIC X(14).

01 HOLD-SSN-ID PIC 9(09).

01 HH-DEPENDS.
03 HH-2-8.
05 H-2-8 PIC X(51) OCCURS 7 TIMES.
03 HH-9-32.
05 H-9-32 PIC X(51) OCCURS 8 TIMES.

01 HHM-FIELDS.
03 HHM-FNAME PIC X(14).
03 HHM-LNAME PIC X(20).
03 HHM-SSN.
05 HHM-SS1 PIC 9(03).
05 HHM-SS2 PIC 9(02).
05 HHM-SS3 PIC 9(04).
03 HHM-DOB.
05 HHM-DOBM PIC 9(02).
05 HHM-DOBD PIC 9(02).
05 HHM-DOBY PIC 9(04).

01 FLAGS.
03 MORE-DATA-FLAG PIC X(03) VALUE 'YES'.
88 MORE-DATA VALUE 'YES'.
88 NO-MORE-DATA VALUE 'N0'.


01 BAD-SSN PIC 9(09).


01 ERROR-RECORDS.
03 ER-ID PIC X(09).
03 FILLER PIC X(02).
03 ER-ORG-SSN PIC 9(09).
03 FILLER PIC X(04).
03 ER-LNAME PIC X(20).
03 ER-FNAME PIC X(14).
03 FILLER PIC X(01) VALUE SPACE.
03 ER-NEW-SSN PIC 9(09).
*

01 ERROR-OUTPUT.
03 ER-HEADER1 PIC X(80).
03 ER-HEADER2 PIC X(80).
03 ER-HEADER3 PIC X(80).
03 ER-SUB-HEADER1 PIC X(80).
03 ER-SUB-HEADER2 PIC X(80).
03 ER-DETAIL-LINE1 PIC X(80).


01 CURRENT-DATE.
03 CD-CHECK.
05 CDYY PIC 9(04).
05 CDMM PIC 9(02).
03 CDDD PIC 9(02).


01 HEADER-1.
03 H1-MM PIC X(02).
03 FILLER PIC X(01) VALUE '/'.
03 H1-DD PIC X(02).
03 FILLER PIC X(01) VALUE '/'.
03 H1-YY PIC X(04).
03 FILLER PIC X(11) VALUE SPACES.
03 FILLER PIC X(28) VALUE
'AIS WINDOWS DATA CONVERSION'.
03 FILLER PIC X(23) VALUE SPACES.
03 FILLER PIC X(06) VALUE 'PAGE: '.
03 H1-PAGE PIC Z9.
01 HEADER-2.
03 FILLER PIC X(26) VALUE SPACES.
03 FILLER PIC X(18) VALUE
'DUPLICATE SSN LIST'.
03 FILLER PIC X(36) VALUE SPACES.
01 HEADER-3.
03 FILLER PIC X(26) VALUE SPACES.
03 FILLER PIC X(13) VALUE
' TRIBAL NAME '.
03 FILLER PIC X(41) VALUE SPACES.

01 SUB-HEADER-1.
03 FILLER PIC X(02) VALUE SPACES.
03 FILLER PIC X(09) VALUE ' HH-ID '.
03 FILLER PIC X(02) VALUE SPACES.
03 FILLER PIC X(11) VALUE ' OLD-SSN '.
03 FILLER PIC X(04) VALUE SPACES.
03 FILLER PIC X(12) VALUE SPACES.
03 FILLER PIC X(11) VALUE 'CLIENT NAME'.
03 FILLER PIC X(12) VALUE SPACES.
03 FILLER PIC X(02) VALUE SPACES.
03 FILLER PIC X(09) VALUE ' NEW-SSN '.

01 SUB-HEADER-2.
03 FILLER PIC X(02) VALUE SPACES.
03 FILLER PIC X(09) VALUE '_________'.
03 FILLER PIC X(04) VALUE SPACES.
03 FILLER PIC X(11) VALUE '___________'.
03 FILLER PIC X(11) VALUE '___________'.
03 FILLER PIC X(12) VALUE '___________'.
03 FILLER PIC X(03) VALUE SPACES.
03 FILLER PIC X(09) VALUE '_________'.
03 FILLER PIC X(02) VALUE SPACES.
03 FILLER PIC X(15) VALUE '_____________'.
03 FILLER PIC X(02) VALUE SPACES.

01 DETAIL-LINE.
03 DL-SS1 PIC X(03).
03 FILLER PIC X(01) VALUE '-'.
03 DL-SS2 PIC X(02).
03 FILLER PIC X(01) VALUE '-'.
03 DL-SS3 PIC X(04).
03 FILLER PIC X(04) VALUE SPACES.
03 DL-LNAME PIC X(20).
03 FILLER PIC X(01) VALUE SPACES.
03 DL-FNAME PIC X(14).
03 FILLER PIC X(03) VALUE SPACES.
03 DL-ID PIC X(09).
03 FILLER PIC X(05) VALUE SPACES.
03 DL-NSS1 PIC X(03).
03 FILLER PIC X(01) VALUE '-'.
03 DL-NSS2 PIC X(02).
03 FILLER PIC X(01) VALUE '-'.
03 DL-NSS3 PIC X(04).
03 FILLER PIC X(03) VALUE SPACES.



*
*
PROCEDURE DIVISION.
*
*
A000-INITIALIZE.
PERFORM A100-ACCEPT-NS-SEARCH-INPUT.
PERFORM Z000-TERMINATE.
STOP RUN.
A000-EXIT.
EXIT.
*
*
A100-ACCEPT-NS-SEARCH-INPUT.
PERFORM A200-MASTER-SORT.
PERFORM A300-OPEN-FILES.
PERFORM B100-READ-MASTER THRU B100-EXIT.
CLOSE SORT-FILE
HHMF-FILE
NEW-HHMF-FILE
HH0932-FILE.
PERFORM C000-SORT-NEWMAST.
OPEN INPUT SORT-FILE
I-O NEW-HHMF-FILE
OUTPUT NEWMAST-FILE
ERROR-FILE.
MOVE SPACES TO NEWMAST-DATA-2, HOLD-DATA.
MOVE ZEROS TO IDX, N-IDX, BAD-CNT, MEMBER-CNT
MOVE ZEROS TO NEW-CNT.
PERFORM C201-READ-NEWMAST.


A100-EXIT.
EXIT.


A200-MASTER-SORT.
SORT SORT-WORK
ON ASCENDING KEY SR-SSN, SR-ID
USING HHMF-FILE
GIVING SORT-FILE.
A200-EXIT.
EXIT.

A300-OPEN-FILES.
OPEN INPUT HH0932-FILE
HHMF-FILE
SORT-FILE
OUTPUT NEW-HHMF-FILE.
A300-EXIT.
EXIT.

B100-READ-MASTER.
MOVE SPACES TO NEWMAST-DATA.
READ SORT-FILE INTO HHMF-DATA
AT END
MOVE 'NO' TO MORE-DATA-FLAG
GO TO B100-EXIT.
COMPUTE OLD-CNT = OLD-CNT + 1.

IF HMF-HHSIZE > 08
MOVE HMF-ID TO HH0932-KEY
READ HH0932-FILE INTO HH0932-DATA
INVALID KEY
MOVE 08 TO HMF-HHSIZE
COMPUTE OLD-MEM-CNT = OLD-MEM-CNT + 1
DISPLAY 'HH0932 READ: ' OLD-MEM-CNT ' ' HHD-ID
DISPLAY 'HHD-0916: ' HHD-0916
DISPLAY 'HHD-1724: ' HHD-1724.


IF HMF-ID = ZERO
GO TO B100-READ-MASTER.

MOVE HMF-ID TO HMFN-ID.
MOVE HMF-SS TO HMFN-SS-ID.
MOVE HMF-BIRTHDATE TO HMFN-BIRTHDATE.
MOVE HMF-LNAME TO HMFN-LNAME.
MOVE HMF-FNAME TO HMFN-FNAME.
MOVE HMF-ADDRESS TO HMFN-ADDRESS.
MOVE HMF-CITY TO HMFN-CITY.
MOVE HMF-STATE TO HMFN-STATE.
MOVE HMF-ZIP TO HMFN-ZIP.
MOVE HMF-COUNTY TO HMFN-COUNTY.
MOVE HMF-LOCATION TO HMFN-LOCATION.
MOVE ZEROS TO HMFN-PH1.
MOVE HMF-PHONE TO HMFN-PHALL.
MOVE HMF-HHSIZE TO HMFN-HHSIZE.
MOVE HMF-ETHNIC TO HMFN-ETHNIC-CODE-1.
MOVE HMF-CERTDATE TO HMFN-CERTDATE.
MOVE HMF-TERMDATE TO HMFN-TERMDATE.
MOVE HMF-STATUSCODE TO HMFN-STATUSCODE.
MOVE HMF-ISSUEDATA TO HMFN-ISSUEDATA.
MOVE HMF-HHISSUESIZE TO HMFN-HHISSUESIZE.
MOVE HMF-PC1 TO HMFN-PC1.
MOVE HMF-PT1 TO HMFN-PT1.
MOVE HMF-PC2 TO HMFN-PC2.
MOVE HMF-PT2 TO HMFN-PT2.
MOVE HMF-PC3 TO HMFN-PC3.
MOVE HMF-PT3 TO HMFN-PT3.
MOVE HMF-PC4 TO HMFN-PC4.
MOVE HMF-PT4 TO HMFN-PT4.
MOVE HMF-PC5 TO HMFN-PC5.
MOVE HMF-PT5 TO HMFN-PT5.
MOVE HMF-MESSAGE TO HMFN-MESSAGE.
MOVE HMF-UPDATED TO HMFN-UPDATED.
MOVE ZEROS TO HMFN-TOTAL-RESOURCES.
MOVE ZEROS TO HMFN-REST.
PERFORM B150-DEPENDENTS THRU B150-EXIT.
WRITE NEW-HHMF-REC FROM NEWMAST-DATA.
COMPUTE NEW-CNT = NEW-CNT + 1.
DISPLAY 'B100-NEW-HHMF RECS READ: ' NEW-CNT ' ' HMFN-ID.
DISPLAY 'B100-OLD-HHMF1 READ: ' OLD-CNT ' ' HMF-ID.
GO TO B100-READ-MASTER.

B100-EXIT.
EXIT.


B150-DEPENDENTS.
IF HMF-HHSIZE = 01
GO TO B150-EXIT.
IF HMF-HHSIZE > 01
MOVE HMF-OTHERDATA TO HH-2-8
MOVE ZERO TO IDX, N-IDX
PERFORM B200-2-8 THRU B200-EXIT.
IF HMF-HHSIZE > 08
MOVE HHD-0916 TO HH-9-32
MOVE ZERO TO IDX, N-IDX
PERFORM B300-9-32 THRU B300-EXIT.
IF HMF-HHSIZE > 16
MOVE HHD-1724 TO HH-9-32
MOVE ZERO TO IDX, N-IDX
PERFORM B300-9-32 THRU B300-EXIT.

B150-EXIT.
EXIT.
*
B200-2-8.
COMPUTE IDX = IDX + 1.
COMPUTE N-IDX = N-IDX + 1.

IF IDX = 8
GO TO B200-EXIT.

MOVE H-2-8 (IDX) TO HHM-FIELDS.

IF HHM-FNAME = SPACE
GO TO B200-EXIT.

MOVE HHM-SSN TO HM-SSN(N-IDX).
MOVE HHM-FNAME TO HM-FNAME(N-IDX).
MOVE HHM-LNAME TO HM-LNAME(N-IDX).
MOVE HHM-DOB TO HM-DOB(N-IDX).


GO TO B200-2-8.

B200-EXIT.
EXIT.
*
B300-9-32.
COMPUTE IDX = IDX + 1.
COMPUTE N-IDX = N-IDX + 1.

IF IDX = 9
GO TO B300-EXIT.

IF HHM-FNAME = SPACES
GO TO B300-EXIT.

MOVE H-9-32 (IDX) TO HHM-FIELDS.

MOVE HHM-SSN TO HM-SSN(N-IDX).
MOVE HHM-FNAME TO HM-FNAME(N-IDX).
MOVE HHM-LNAME TO HM-LNAME(N-IDX).
MOVE HHM-DOB TO HM-DOB(N-IDX).


GO TO B300-9-32.
*
B300-EXIT.
EXIT.




C000-SORT-NEWMAST.
SORT SORT-WORK
ON ASCENDING KEY SR-SSN
USING NEW-HHMF-FILE
GIVING NEW-HHMF-FILE.
C000-EXIT.
EXIT.


C201-READ-NEWMAST.
MOVE SPACES TO NEWMAST-DATA.
READ NEW-HHMF-FILE INTO NEWMAST-DATA
AT END
GO TO C201-EXIT.
COMPUTE NEW-CNT = NEW-CNT + 1.
DISPLAY 'C201-NEWMAST READ: ' NEW-CNT ' ' HMFN-ID.


IF HMFN-ID = ZEROS
GO TO C201-READ-NEWMAST.

MOVE NEWMAST-DATA TO NEWMAST-DATA-2.

IF HMFN-HHSIZE > 01
MOVE ZEROS TO IDX, N-IDX
PERFORM C202-MEMBERS THRU C202-EXIT.

WRITE NEWMAST-REC FROM NEWMAST-DATA-2.

GO TO C201-READ-NEWMAST.

C201-EXIT.
EXIT.


C202-MEMBERS.
COMPUTE MEMBER-CNT = MEMBER-CNT + 1.
COMPUTE IDX = IDX + 1.
COMPUTE N-IDX = N-IDX + 1.


IF IDX = 24
GO TO C202-EXIT.

MOVE HM-MEMBERS(N-IDX) TO HHM-FIELDS.

IF HHM-FNAME = SPACE
GO TO C202-EXIT.


* IF MEMBER-CNT = 1
MOVE HHM-SSN TO HOLD-SS-ID.

MOVE HHM-SSN TO HM-SSN-2(N-IDX)
MOVE HHM-FNAME TO HM-FNAME-2(N-IDX)
MOVE HHM-LNAME TO HM-LNAME-2(N-IDX)
MOVE HHM-DOB TO HM-DOB-2(N-IDX).

IF HHM-SSN = HOLD-SS-ID
PERFORM C203-DUP-SSN
GO TO C202-MEMBERS.

IF HOLD-SS-ID < HHM-SSN
MOVE HHM-SSN TO HOLD-SS-ID
GO TO C202-MEMBERS.

GO TO C202-MEMBERS.

C202-EXIT.
EXIT.

C203-DUP-SSN.
COMPUTE BAD-CNT = BAD-CNT + 1
MOVE HHM-SSN TO BAD-SSN, ER-ORG-SSN
COMPUTE B-IDX = B-IDX + 1
MOVE B-IDX TO BAD-SSN
MOVE BAD-SSN TO HM-SSN-2(N-IDX), ER-NEW-SSN
MOVE HMFN-ID TO ER-ID
MOVE HHM-FNAME TO ER-FNAME
MOVE HHM-LNAME TO ER-LNAME
WRITE ERROR-REC FROM ERROR-RECORDS.
* REWRITE NEWMAST-REC FROM NEWMAST-DATA.



C203-EXIT.
EXIT.


Z000-TERMINATE.
CLOSE NEWMAST-FILE
NEW-HHMF-FILE
ERROR-FILE.


Z000-EXIT.
EXIT PROGRAM.

This is some of my output error-file
Sorry it did not keep it's format. I had id#, old-ssn, name, then newssn#.


030387806 504722571 ST. PIERRE TILDA 000000001
046764004 999999999 MUNOZ John PAUL 000000002
112642650 504742328 BENEDICT DARLA 000000003
112642650 999999999 RUNYON CODY 000000004
112642650 999999999 RUNYON LUCAS 000000005
112642650 999999999 RUNYON LINDSEY 000000006
112642650 503255338 BENEDICT DAKOTA 000000007
112642650 999999999 PULLINS SYDNEY 000000008
504724631 504667245 AFRAID OF HAWK FLOYD 000003563
504724645 999999999 WINTERS LOUIS 000003564
504724645 999999999 WINTERS JOEANN 000003565
 
Hi Deidre,

Your code didn't contain a Proc Div. Was it dropped in xmission?

I made this statement in my previous post:

For example, if you have 5 input recs, each containing 20 ssn in the table, you will write 100 OP recs, each containing one ssn.

Is this correct? To put it another way - if you have 5 input recs, each containing 20 ssn in the table portion of each record, you want to find all the dupe ssn's among the 100 ssn's contained in the file. Is that correct?

Jack
 
Diedre,

First, may I suggest that you register with tek-tips so that you may benefit from email notification, among other things.

Now to your problem. Jack is suggesting the method I would consider to be the best. I would modify his suggested solution and your solution (inferred from your data division) as follows.

In the sort INPUT PROCEDURE:
For each valid SSN write a sort record. A sort record should contain only the SSN and the data items necessary to locate the record - the HMFN-ID and the occurrence number (1 to 23) of the table entry within that record that is duplicate. You do not need to haul the entire record around in the sort file, as that will unnecessarity slow down the sort process.

In the sort OUTPUT PROCEDURE:
The idea behind this kind of processing is &quot;remember the last value.&quot; You will code a fairly straightforward loop that RETURNs sort records and compares the SSN just RETURNed to the previous SSN. When it is the same, you have a duplicate; use the HMFN-ID field to READ the correct record (this is the beauty of an indexed file), use the occurrence number to modify the offending SSN, and rewrite the record.

Note that I stated above for each valid SSN. Is it true that each record contains 23 SSNs? Or is it possible that some of the SSNs are zero or 999999999 or some other invalid value (i.e. NOT NUMERIC)?
Tom Morrison
 
Hi Tom,

When Deidre first posted I assumed the file was flat sequential. When she provided the code, I didn't check the SELECTs. Good catch.

I'd guess that the decision to update the indexed file or recreate it would depend on the % of the indexed file recs expected for update; a performance consideration.

I'm also curious about how she populates the changed ssn.

The &quot;remember the last value&quot; process I like to do in the read pgraph, e.g.:
Code:
7000-read-ssn-rec.
    set reset-dupe-sw to true
    move curr-ssn     to prev-ssn
    read ssn-rec    into curr-rec ...
    if curr-ssn        = prev-ssn
       set ssn-is-a-dupe to true
    end-if
Just had a thought about the dupes. If the 1st occurrance of an ssn is retained as is, does that mean the &quot;valid&quot; ssn of the dupe set can be selected arbitrarily? I wonder, because the ssn's can be in different recs, whose other data can differ. Deidre?


Jack
 
Hi Jack (and Deidre),

Jack is right about possible performance considerations if you anticipate a large number of updates to an indexed file. The actual impact on performance depends on the impementation of the indexed file. I just looked at the title of the thread and 'coded' accordingly. ;-)

Also, Deidre, Jack raises a valid design consideration - when you detect a duplicate SSN, how do you determine which record should keep its SSN and which record should be changed?
Tom Morrison
 
I have enclosed my program. I merge (2) files into one file, then I want to check all the ssn# for this file. hmfn-ss-id and hm-ssn (in a table). When I run it it only prints out the 9's and I want it to find all duplicate, even if it is all 9's. The I want to rewrite the record.

All it caught were the 9's, not any other dups.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT HHMF-FILE
ASSIGN TO DISK
ORGANIZATION IS INDEXED
ACCESS MODE IS SEQUENTIAL
RECORD KEY IS HHMF-KEY.
SELECT HH0932-FILE
ASSIGN TO DISK
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS HH0932-KEY.
SELECT NEW-HHMF-FILE
ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT NEWMAST-FILE
ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT ERROR-FILE
ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT SORT-WORK
ASSIGN TO DISK.
SELECT SORT-FILE
ASSIGN TO DISK.

DATA DIVISION.
FILE SECTION.
FD HHMF-FILE
LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS 'C:\AIS-CNVT\HHMF.DAT'.
01 HHMF-REC.
03 HHMF-KEY PIC X(09).
03 FILLER PIC X(775).
FD HH0932-FILE
LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS 'C:\AIS-CNVT\HH0932.DAT'.
01 HH0932-REC.
03 HH0932-KEY PIC X(09).
03 FILLER PIC X(1224).
FD NEWMAST-FILE
LABEL RECORDS IS STANDARD
VALUE OF FILE-ID IS 'C:\AIS-CNVT\225MAST6.DAT'.
01 NEWMAST-REC PIC X(2048).
FD NEW-HHMF-FILE
LABEL RECORDS IS STANDARD
VALUE OF FILE-ID IS 'C:\AIS-CNVT\NEWHHMF.DAT'.
01 NEW-HHMF-REC PIC X(2048).
FD ERROR-FILE
LABEL RECORDS IS STANDARD
VALUE OF FILE-ID IS 'C:\AIS-CNVT\ERROR.DAT'.
01 ERROR-REC PIC X(70).
SD SORT-WORK.
01 SORT-REC.
03 SR-ID PIC X(09).
03 SR-SSN PIC 9(09).
03 FILLER PIC X(2030).
FD SORT-FILE
LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS 'D:\SORT.WRK'.
01 SF-REC PIC X(2048).
*
WORKING-STORAGE SECTION.
*
01 N-IDX PIC 9(06).
01 B-IDX PIC 9(09) VALUE ZERO.
01 W-IDX PIC 9(06).
01 BR-IDX PIC 9(06).
01 IDX PIC 9(06).
01 BAD-CNT PIC 9(04) VALUE ZERO.
01 OLD-CNT PIC 9(06) VALUE ZERO.
01 OLD-MEM-CNT PIC 9(06) VALUE ZERO.
01 NEW-CNT PIC 9(06) VALUE ZERO.
01 WORK-CNT PIC 9(06) VALUE ZERO.
01 SORT-CNT PIC 9(06) VALUE ZERO.
01 MEMBER-CNT PIC 9(06) VALUE ZERO.
01 NEW-SSN PIC 9(09).

COPY \SOURCE\HH0932.LIB.
COPY \SOURCE\HHMF.LIB.
COPY \SOURCE\DATE2000.LIB.
01 NEWMAST-DATA.
03 HMFN-ID PIC X(09).
03 HMFN-SS-ID PIC 9(09).
03 HMFN-BIRTHDATE PIC 9(08).
03 HMFN-LNAME PIC X(20).
03 HMFN-FNAME PIC X(14).
03 HMFN-ADDRESS PIC X(23).
03 HMFN-CITY PIC X(13).
03 HMFN-STATE PIC X(02).
03 HMFN-ZIP.
05 HMFN-ZIP1 PIC 9(05).
05 HMFN-ZIP2 PIC 9(04).
03 HMFN-COUNTY PIC X(02).
03 HMFN-LOCATION PIC X(02).
03 HMFN-PHONE.
05 HMFN-PH1 PIC 9(03).
05 HMFN-PHALL.
07 HMFN-PH2 PIC 9(03).
07 HMFN-PH3 PIC 9(04).
03 HMFN-HHSIZE PIC 9(02).
03 HMFN-ETHNIC.
05 HMFN-ETHNIC-CODE-1 PIC X(01).
05 HMFN-ETHNIC-CODE-2 PIC X(01).
03 HMFN-CERTDATE PIC 9(08).
03 HMFN-TERMDATE PIC 9(06).
03 HMFN-STATUSCODE PIC X(01).
03 HMFN-ISSUEDATA PIC X(72).
03 HMFN-HHISSUESIZE PIC X(24).
03 HMFN-PCT1.
05 HMFN-PC1.
07 HMFN-PCYR1 PIC 9(04).
07 HMFN-PCYR-R1 REDEFINES HMFN-PCYR1.
09 HMFN-PCC1 PIC 9(02).
09 HMFN-PCY1 PIC 9(02).
07 HMFN-PCM1 PIC 9(02).
05 HMFN-PT1.
07 HMFN-PTYR1 PIC 9(04).
07 HMFN-PTYR-R1 REDEFINES HMFN-PTYR1.
09 HMFN-PTC1 PIC 9(02).
09 HMFN-PTY1 PIC 9(02).
07 HMFN-PTM1 PIC 9(02).
03 HMFN-PCT2.
05 HMFN-PC2.
07 HMFN-PCYR2 PIC 9(04).
07 HMFN-PCYR-R2 REDEFINES HMFN-PCYR2.
09 HMFN-PCC2 PIC 9(02).
09 HMFN-PCY2 PIC 9(02).
07 HMFN-PCM2 PIC 9(02).
05 HMFN-PT2.
07 HMFN-PTYR2 PIC 9(04).
07 HMFN-PTYR-R2 REDEFINES HMFN-PTYR2.
09 HMFN-PTC2 PIC 9(02).
09 HMFN-PTY2 PIC 9(02).
07 HMFN-PTM2 PIC 9(02).
03 HMFN-PCT3.
05 HMFN-PC3.
07 HMFN-PCYR3 PIC 9(04).
07 HMFN-PCYR-R3 REDEFINES HMFN-PCYR3.
09 HMFN-PCC3 PIC 9(02).
09 HMFN-PCY3 PIC 9(02).
07 HMFN-PCM3 PIC 9(02).
05 HMFN-PT3.
07 HMFN-PTYR3 PIC 9(04).
07 HMFN-PTYR-R3 REDEFINES HMFN-PTYR3.
09 HMFN-PTC3 PIC 9(02).
09 HMFN-PTY3 PIC 9(02).
07 HMFN-PTM3 PIC 9(02).
03 HMFN-PCT4.
05 HMFN-PC4.
07 HMFN-PCYR4 PIC 9(04).
07 HMFN-PCYR-R4 REDEFINES HMFN-PCYR4.
09 HMFN-PCC4 PIC 9(02).
09 HMFN-PCY4 PIC 9(02).
07 HMFN-PCM4 PIC 9(02).
05 HMFN-PT4.
07 HMFN-PTYR4 PIC 9(04).
07 HMFN-PTYR-R REDEFINES HMFN-PTYR4.
09 HMFN-PTC4 PIC 9(02).
09 HMFN-PTY4 PIC 9(02).
07 HMFN-PTM4 PIC 9(02).
03 HMFN-PCT5.
05 HMFN-PC5.
07 HMFN-PCYR5 PIC 9(04).
07 HMFN-PCYR-R5 REDEFINES HMFN-PCYR5.
09 HMFN-PCC5 PIC 9(02).
09 HMFN-PCY5 PIC 9(02).
07 HMFN-PCM5 PIC 9(02).
05 HMFN-PT5.
07 HMFN-PTYR5 PIC 9(04).
07 HMFN-PTYR-R5 REDEFINES HMFN-PTYR5.
09 HMFN-PTC5 PIC 9(02).
09 HMFN-PTY5 PIC 9(02).
07 HMFN-PTM5 PIC 9(02).
03 HMFN-MESSAGE PIC X(256).
03 HMFN-UPDATED PIC X(01).
03 HMFN-RESIDENCY PIC X(01).
03 HMFN-CATEGORY PIC X(03).
03 HMFN-ELIGIBLE PIC X(01).
03 HMFN-MEMBERS.
05 HM-MEMBERS OCCURS 23 TIMES.
07 HM-FNAME PIC X(14).
07 HM-LNAME PIC X(20).
07 HM-SSN PIC 9(09).
07 HM-DOB PIC 9(08).
03 HMFN-SELF-EMPLOYED PIC X(01).
03 HMFN-TOTAL-RESOURCES PIC 9(06)V99.
03 HMFN-FREQUENCY OCCURS 4 TIMES.
05 HMFN-FREQUENCY-CODE PIC X(01).
03 HMFN-REST.
05 HMFN-EARNED-INCOME OCCURS 4 TIMES.
07 HMFN-EARNED PIC 9(06)V99.
05 HMFN-UNEARNED-INCOME OCCURS 4 TIMES.
07 HMFN-UNEARNED PIC 9(06)V99.
05 HMFN-STUDENT-INCOME OCCURS 4 TIMES.
07 HMFN-AMOUNT-REC PIC 9(06)V99.
07 HMFN-TUITION PIC 9(06)V99.
07 HMFN-S-DATE-BEG PIC 9(06).
07 HMFN-S-DATE-END PIC 9(06).
05 HMFN-DEPENDENT-CARE OCCURS 3 TIMES.
07 HMFN-D-CARE PIC 9(03)V99.
05 HMFN-CHILD-SUPPORT OCCURS 3 TIMES.
07 HMFN-C-CARE PIC 9(03)V99.
05 HMFN-MEDICARE-INS OCCURS 3 TIMES.
07 HMFN-M-INSURANCE PIC 9(03)V99.
05 HMFN-MONTH-INCOME-LIMIT PIC 9(03)V99.
03 FILLER PIC X(78).

01 NEWMAST-DATA-2.
03 HMFN-ID-2 PIC X(09).
03 HMFN-SS-ID-2 PIC 9(09).
03 FILLER PIC 9(08).
03 HMFN-LNAME-2 PIC X(20).
03 HMFN-FNAME-2 PIC X(14).
03 FILLER PIC X(498).
03 HMFN-MEMBERS-2.
05 HM-MEMBERS-2 OCCURS 23 TIMES.
07 HM-FNAME-2 PIC X(14).
07 HM-LNAME-2 PIC X(20).
07 HM-SSN-2 PIC 9(09).
07 HM-DOB-2 PIC 9(08).
03 FILLER PIC X(317).

01 HOLD-DATA.
03 HOLD-ID PIC X(09).
03 HOLD-SS-ID PIC 9(09).
03 HOLD-LNAME PIC X(20).
03 HOLD-FNAME PIC X(14).

01 HOLD-SSN-ID PIC 9(09).

01 HH-DEPENDS.
03 HH-2-8.
05 H-2-8 PIC X(51) OCCURS 7 TIMES.
03 HH-9-32.
05 H-9-32 PIC X(51) OCCURS 8 TIMES.

01 HHM-FIELDS.
03 HHM-FNAME PIC X(14).
03 HHM-LNAME PIC X(20).
03 HHM-SSN.
05 HHM-SS1 PIC 9(03).
05 HHM-SS2 PIC 9(02).
05 HHM-SS3 PIC 9(04).
03 HHM-DOB.
05 HHM-DOBM PIC 9(02).
05 HHM-DOBD PIC 9(02).
05 HHM-DOBY PIC 9(04).

01 FLAGS.
03 MORE-DATA-FLAG PIC X(03) VALUE 'YES'.
88 MORE-DATA VALUE 'YES'.
88 NO-MORE-DATA VALUE 'N0'.


01 BAD-SSN PIC 9(09).


01 ERROR-RECORDS.
03 ER-ID PIC X(09).
03 FILLER PIC X(02).
03 ER-ORG-SSN PIC 9(09).
03 FILLER PIC X(04).
03 ER-LNAME PIC X(20).
03 ER-FNAME PIC X(14).
03 FILLER PIC X(01) VALUE SPACE.
03 ER-NEW-SSN PIC 9(09).
*
PROCEDURE DIVISION.
*
*
A000-INITIALIZE.
PERFORM A100-ACCEPT-NS-SEARCH-INPUT.
PERFORM Z000-TERMINATE.
STOP RUN.
A000-EXIT.
EXIT.
*
*
A100-ACCEPT-NS-SEARCH-INPUT.
PERFORM A200-MASTER-SORT.
PERFORM A300-OPEN-FILES.
PERFORM B100-READ-MASTER THRU B100-EXIT.
MOVE SPACES TO NEWMAST-DATA-2, HOLD-DATA.
MOVE ZEROS TO IDX, N-IDX, W-IDX, BAD-CNT, MEMBER-CNT
MOVE ZEROS TO NEW-CNT.
MOVE SPACES TO NEWMAST-DATA.
A100-EXIT.
EXIT.


A200-MASTER-SORT.
SORT SORT-WORK
ON ASCENDING KEY SR-SSN, SR-ID
USING HHMF-FILE
GIVING SORT-FILE.
A200-EXIT.
EXIT.

A300-OPEN-FILES.
OPEN INPUT HHMF-FILE
SORT-FILE
I-O HH0932-FILE
OUTPUT ERROR-FILE
NEW-HHMF-FILE.
A300-EXIT.
EXIT.

B100-READ-MASTER.
MOVE SPACES TO NEWMAST-DATA.
READ SORT-FILE INTO HHMF-DATA
AT END
MOVE 'NO' TO MORE-DATA-FLAG
GO TO B100-EXIT.
COMPUTE OLD-CNT = OLD-CNT + 1.
DISPLAY 'HHMF READ: ' OLD-CNT ' ' HMF-ID

IF HMF-HHSIZE > 08
MOVE HMF-ID TO HH0932-KEY
READ HH0932-FILE INTO HH0932-DATA
INVALID KEY
MOVE 08 TO HMF-HHSIZE
COMPUTE OLD-MEM-CNT = OLD-MEM-CNT + 1
DISPLAY 'HH0932 READ: ' OLD-MEM-CNT ' ' HHD-ID
DISPLAY 'HHD-0916: ' HHD-0916
DISPLAY 'HHD-1724: ' HHD-1724.
IF HMF-ID = ZERO
GO TO B100-READ-MASTER.
MOVE HMF-ID TO HMFN-ID.
MOVE HMF-SS TO HMFN-SS-ID.
MOVE HMF-BIRTHDATE TO HMFN-BIRTHDATE.
MOVE HMF-LNAME TO HMFN-LNAME.
MOVE HMF-FNAME TO HMFN-FNAME.
MOVE HMF-ADDRESS TO HMFN-ADDRESS.
MOVE HMF-CITY TO HMFN-CITY.
MOVE HMF-STATE TO HMFN-STATE.
MOVE HMF-ZIP TO HMFN-ZIP.
MOVE HMF-COUNTY TO HMFN-COUNTY.
MOVE HMF-LOCATION TO HMFN-LOCATION.
MOVE ZEROS TO HMFN-PH1.
MOVE HMF-PHONE TO HMFN-PHALL.
MOVE HMF-HHSIZE TO HMFN-HHSIZE.
MOVE HMF-ETHNIC TO HMFN-ETHNIC-CODE-1.
MOVE HMF-CERTDATE TO HMFN-CERTDATE.
MOVE HMF-TERMDATE TO HMFN-TERMDATE.
MOVE HMF-STATUSCODE TO HMFN-STATUSCODE.
MOVE HMF-ISSUEDATA TO HMFN-ISSUEDATA.
MOVE HMF-HHISSUESIZE TO HMFN-HHISSUESIZE.
MOVE HMF-PC1 TO HMFN-PC1.
MOVE HMF-PT1 TO HMFN-PT1.
MOVE HMF-PC2 TO HMFN-PC2.
MOVE HMF-PT2 TO HMFN-PT2.
MOVE HMF-PC3 TO HMFN-PC3.
MOVE HMF-PT3 TO HMFN-PT3.
MOVE HMF-PC4 TO HMFN-PC4.
MOVE HMF-PT4 TO HMFN-PT4.
MOVE HMF-PC5 TO HMFN-PC5.
MOVE HMF-PT5 TO HMFN-PT5.
MOVE HMF-MESSAGE TO HMFN-MESSAGE.
MOVE HMF-UPDATED TO HMFN-UPDATED.
MOVE ZEROS TO HMFN-TOTAL-RESOURCES.
MOVE ZEROS TO HMFN-REST.
DISPLAY 'GOING TO B150-DEPENDENTS'.
PERFORM B150-DEPENDENTS THRU B150-EXIT.
WRITE NEW-HHMF-REC FROM NEWMAST-DATA.
COMPUTE NEW-CNT = NEW-CNT + 1.
DISPLAY 'B100-NEW-HHMF RECS READ: ' NEW-CNT ' ' HMFN-ID.
DISPLAY 'B100-OLD-HHMF1 READ: ' OLD-CNT ' ' HMF-ID.
DISPLAY 'B100-BAD RECS READ: ' B-IDX.
GO TO B100-READ-MASTER.
B100-EXIT.
EXIT.


B150-DEPENDENTS.
IF HMF-HHSIZE = 01
GO TO B150-EXIT.
IF HMF-HHSIZE > 01
MOVE HMF-OTHERDATA TO HH-2-8
MOVE ZERO TO IDX, N-IDX
PERFORM B200-2-8 THRU B200-EXIT.
IF HMF-HHSIZE > 08
MOVE HHD-0916 TO HH-9-32
MOVE ZERO TO IDX, N-IDX
PERFORM B300-9-32 THRU B300-EXIT.
IF HMF-HHSIZE > 16
MOVE HHD-1724 TO HH-9-32
MOVE ZERO TO IDX, N-IDX
PERFORM B300-9-32 THRU B300-EXIT.
B150-EXIT.
EXIT.
*
B200-2-8.
compute MEMBER-CNT = MEMBER-CNT + 1
COMPUTE IDX = IDX + 1.
COMPUTE N-IDX = N-IDX + 1.
IF IDX = 8
GO TO B200-EXIT.
MOVE H-2-8 (IDX) TO HHM-FIELDS.
IF HHM-FNAME = SPACE
GO TO B200-EXIT.
MOVE HHM-FNAME TO HM-FNAME(N-IDX).
MOVE HHM-LNAME TO HM-LNAME(N-IDX).
MOVE HHM-DOB TO HM-DOB(N-IDX).
IF MEMBER-CNT = 1
MOVE HHM-SSN TO HOLD-SS-ID
GO TO B200-2-8.
IF HHM-SSN = HOLD-SS-ID
PERFORM B400-MOVE-SSN
ELSE
MOVE HHM-SSN TO HM-SSN(N-IDX).

IF HOLD-SS-ID < HHM-SSN
DISPLAY 'B200-HOLD<HHM=' HOLD-SS-ID, HHM-SSN
MOVE HHM-SSN TO HOLD-SS-ID
GO TO B200-2-8.
GO TO B200-2-8.
B200-EXIT.
EXIT.
*
B300-9-32.
COMPUTE MEMBER-CNT = MEMBER-CNT + 1.
COMPUTE IDX = IDX + 1.
COMPUTE N-IDX = N-IDX + 1.
IF IDX = 9
GO TO B300-EXIT.
MOVE H-9-32 (IDX) TO HHM-FIELDS.
IF HHM-FNAME = SPACES
GO TO B300-EXIT.
MOVE HHM-FNAME TO HM-FNAME(N-IDX).
MOVE HHM-LNAME TO HM-LNAME(N-IDX).
MOVE HHM-DOB TO HM-DOB(N-IDX).
IF HHM-SSN = HOLD-SS-ID
PERFORM B400-MOVE-SSN
GO TO B300-9-32
ELSE
MOVE HHM-SSN TO HM-SSN(N-IDX).

IF HOLD-SS-ID < HHM-SSN
MOVE HHM-SSN TO HOLD-SS-ID.
GO TO B300-9-32.
GO TO B300-9-32.
*
B300-EXIT.
EXIT.

B400-MOVE-SSN.
COMPUTE BAD-CNT = BAD-CNT + 1
MOVE HHM-SSN TO BAD-SSN, ER-ORG-SSN
COMPUTE B-IDX = B-IDX + 1
MOVE B-IDX TO BAD-SSN
MOVE BAD-SSN TO HM-SSN(N-IDX), ER-NEW-SSN
MOVE HMFN-ID TO ER-ID
MOVE HHM-FNAME TO ER-FNAME
MOVE HHM-LNAME TO ER-LNAME
DISPLAY 'ERROR-REC=' ERROR-RECORDS STOP ' '
WRITE ERROR-REC FROM ERROR-RECORDS.
B400-EXIT.
EXIT.

Z000-TERMINATE.
CLOSE NEW-HHMF-FILE
SORT-FILE
HHMF-FILE
HH0932-FILE
ERROR-FILE.
Z000-EXIT.
EXIT PROGRAM.
 
Deidre,

1. No need to post more code right now. Jack and I have provided suggestions that are not reflected in the code you just posted. Hope you choose to try our suggestions. :cool:

2. Register with tek-tips! You will find that the email notification feature available to registered users will make Tek-Tips much more useful to you.

Tom Morrison
 
Hi Deidre,

I looked at your code. It looks like you're sorting the masterfile recs by the ssn in the beginning of the rec. However, you said that you must find the dupes for the ssn's contained in all the 23 occurrance tables in the masterfile. Your sort won't accomplish that, or Tom and I misunderstand what you're trying to accomplish.

If we do have it right, you have to create discrete records for each ssn in the tables of every record in the masterfile. Then sort them.

BTW, what is the relationship between the ssn at the beginning of the MF record and the ssn's in the table?

Jack
 
Hi Deidre,

Here I go 'improving' on Jack's suggestion again! :)

I am supplying a simple code snippet that illustrates what Jack and I have been suggesting. This code also illustrates the use of sort input and output procedures, which, in my mind at least, make the sort more understandable and almost certainly the sort will consume less time (if the implementor of the sort algoritm did his job right, that is!).

I don't normally do code examples, but here it is anyway.

Note to those who wish to flame the coding style -- DON'T BOTHER because I COULD CARE LESS. >:-<

Code:
in FILE-CONTROL paragraph, make HHMF-FILE 'ACCESS DYNAMIC'
----------------

FD SORT-FILE
01 SORT-RECORD.
   03  SORT-SSN         PIC 9(09).
   03  SORT-MAST-KEY    PIC X(09).
   03  SORT-OCCURS      PIC 99.

..... in working-storage section:

01 LAST-SSN             PIC 9(09).
------------


In the procedure division...

    sort SORT-FILE ascending SORT-SSN
        input procedure SORT-IN-PROC
        output procedure SORT-OUT-PROC.
    stop run.

SORT-IN-PROC SECTION.
A.
    open input HHMF-FILE.
B.  
    read HHMF-FILE next into NEWMAST-DATA
      at end
        close HHMF-FILE
        go exit-section
    end-read
    perform varying SORT-OCCURS from 1 by 1 
              until SORT-OCCURS > 23
        move HMFN-ID to SORT-MAST-KEY
        move HM-SSN (SORT-OCCURS) to SORT-SSN
        release SORT-RECORD
    end-perform
    go B.

exit-section.
    exit.

SORT-OUT-PROC SECTION.
A.
    open I-O HHMF-FILE.
    move 999999999 to LAST-SSN.
B. 
    return SORT-FILE
      at end
        close HHMF-FILE
        go exit-section
    end-return
    if SORT-SSN = LAST-SSN
        move SORT-MAST-KEY to HHMF-KEY
        read HHMF-FILE into NEWMAST-DATA
          invalid key
            << the record disappeared!!  >>
          not invalid key
            << modify HM-SSN (SORT-OCCURS) >>
            REWRITE HHMF-REC from NEWMAST-DATA
        end-read
    else
        move SORT-SSN to LAST-SSN
    end-if
    go B.


exit-section.
    exit.
Tom Morrison
 
HI K5TM, Your code came across as jiberish can you resend?

Hi Slade,

The first ssn# is the head of household all the other ssn# are members of household.
 
I PRINTED OUT K5TM'S CODE AND WHEN I PRINT, IT COMES OUT OKAY. ANYWAY, I RAN THE CODE AND I GOT AN &quot;LOAD FAILURE 198 ON FILE EXTFH.GNT&quot;
 
I cleared that error up, but now I am getting an error on the sort procedure &quot;operand must be a table&quot;.
 
Deidre,

Perhaps there is an error in the definition of SORT-FILE. I notice that I omitted the period and failed to use 'SD'; it should be:
SD SORT-FILE.
01 SORT-RECORD.
Since Micro Focus COBOL applies the SORT verb to both a sort file and (as an extension) a table, the diagnostic probably is diagnosing the last thing it was looking for when it found neither a sort file or table - a table name.

Sorry about those errors. [blush] I hate to distract from the solution.
Tom Morrison
 
By the way, Deidre...

Click on the big, red checkmark near the top (on the right side of the page) to enable email notification.
Tom Morrison
 
I AM NOW GETTING AN 153 ERROR, subscript out of range. I am having problems checking the red check mark-it will not let me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top