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 SkipVought 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 (cont.)

Status
Not open for further replies.

k5tm

Programmer
Aug 24, 2001
2,038
0
0
US
This is a continuation of a previous thread that has become extremely long due to long source listings. This continuation was suggested by slade at
You may find the older thread by clicking on:
thread209-219820
===========================================

Deidre,

Put a counter in for each successful RETURN in the sort output procedure. Compare the results to the counter that you alkready have in the sort input procedure.

Then, please post the counts you get here so that Jack and I can see them actual counts. Seeing the actual counts might help us diagnose what the problem is. Nothing is obviously wrong to me.
Tom Morrison
 
Hi Tom,

You got in ahead of me. Iposted this to the old thread.

Deidre,

What you're saying is not precise enough. Do you find 20 ssn's of 123456789 in the IP procedure? Or do you "lose" them in the OP procedure?

The code you show in the IP procedure should pick up all the ssn's in the ip file. Does it?

If you're losing them in the OP Proc, I would look into rewriting it. When doing "look ahead" reads, I find it helpful to do a 1st read outside the loop and another read before exiting the loop. Once I know where you're losing the dupes, I'll help you to recode it, if necessary.

Until then: How many IP recs are you using? I would use only 1 or 2 until you get it to work the way you expect. Then add recs to test one additional circumstance at a time. Don't use too many ssn's in the array.

Put this display in after the RELEASE:

DISPLAY SORT-REC

Don't worry about this now, but eventually you'll want to test for no ssn's in the array, then 23 ssn's in the array.

Jack
 
Okay, I ran the program with different variations searching on:
'999999999' and got 1281
'123456789' and got 13

on all ssn with a count of all '999999999' got 1280
on all ssn with a count of all '123456789' got 12
on all ssn's without specifiying a certain ssn and apprently it does not include the 1st occurance of '999999999' or '123456789'.
 
I WANT TO THANK ALL OF YOU THAT HELPED ME. I REALLY APPRECIATE IT.

Thank you!
 
Deidre,

One way to interpret your results is:

If I have 13 SSN = '123456789' then my count of duplicates will be 12. This is due to the fact that I do not count the first '123456789' as a duplicate. In general, if there exist n duplicate numbers, I will treat n - 1 of them as duPlicate and one (1) of them as nonduplicate.

If the goal is detect and report all n duplicates, then the code must be modified to achieve that result. In addition to saving LAST-SSN, you must also save the LAST-ID and LAST-OCCURS and defer the rewrite.

Code:
       01                      PIC X.
           88 LAST-WAS-DUPLICATE VALUE "T" FALSE "F".
       01  LAST-ID             PIC X(9).
       01  LAST-OCCURS         PIC 99.
=======================================
       C000-SORT-OUT-PROC SECTION.
       C100-OPEN-FILES.
           OPEN I-O NEW-HHMF-FILE
                OUTPUT ERROR-FILE.
           MOVE 999999999 TO LAST-SSN.
           MOVE ZERO TO B-IDX.

           SET LAST-WAS-DUPLICATE TO FALSE.
      
       C200-READ-FILES.
           IF LAST-WAS-DUPLICATE
              PERFORM C200-PROCESS-DUPLICATE
           END-IF
           RETURN SORT-WORK
             AT END
               IF LAST-WAS-DUPLICATE
                  PERFORM C200-PROCESS-DUPLICATE
               END-IF
               CLOSE NEW-HHMF-FILE
                        ERROR-FILE
               GO C000-EXIT-SECTION
           END-RETURN
           COMPUTE SORT-CNT = SORT-CNT + 1
           IF SR-SSN = LAST-SSN
              SET LAST-WAS-DUPLICATE TO TRUE
           ELSE
              SET LAST-WAS-DUPLICATE-TO-FALSE
           END-IF
           MOVE SR-SSN TO LAST-SSN
           MOVE SR-OCCURS TO LAST-OCCURS
           MOVE SR-ID TO LAST-ID
           GO TO C200-READ-FILES.

       C200-PROCESS-DUPLICATE.
           MOVE LAST-ID TO NEW-HHMF-KEY
           READ NEW-HHMF-FILE INTO NEWMAST-DATA
                INVALID KEY DISPLAY 'NOT VALID'
                NOT INVALID KEY
                  MOVE HM-SSN(LAST-OCCURS) TO BAD-SSN, 
                                          ER-ORG-SSN
                  COMPUTE B-IDX = B-IDX + 1
                  MOVE B-IDX TO BAD-SSN
                  MOVE BAD-SSN TO HM-SSN(LAST-OCCURS), 
                                  ER-NEW-SSN
                  MOVE HMFN-ID TO ER-ID
                  MOVE HM-FNAME(LAST-OCCURS) TO ER-FNAME
                  MOVE HM-LNAME(LAST-OCCURS) TO ER-LNAME
                  WRITE ERROR-REC FROM ERROR-RECORDS
                  COMPUTE ERROR-CNT = ERROR-CNT + 1
                  REWRITE NEW-HHMF-REC FROM NEWMAST-DATA
           END-READ.


       C000-EXIT-SECTION.
           EXIT.

Perhaps this will do what you want?
Tom Morrison
 
Oops, Minor programming bug!

The following line should be added at the end of C200-PROCESS-DUPLICATE:
Code:
           SET LAST-WAS-DUPLICATE TO FALSE.
Also, remove the following two lines from C200-READ-FILES:
Code:
          ELSE
              SET LAST-WAS-DUPLICATE-TO-FALSE

I apologize. Haven't had enough coffee yet this morning!
[smile]

Tom Morrison
 
Hi Deidre,

Glad to hear you got it working. now that the heat is off you might want to take a look at this site:


You may not agree w/all the points made but your pgms (and the pgm maintenance staff) will thank you for it. Computer programs are unique, in that they're the only tools that function as their own maintenance manuals. This is especially true of COBOL pgms. So, a pgmr's task is twofold; to solve the problem and explain the solution. In a COBOL pgm, carefully crafted code, along with targeted comments, can accomplish both.

Good luck in your career, Jack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top