I have a File that has duplicate records. I need only those records that occur more than
thrice.?

Answer Posted / nsingh

DEFINE A TABLE

01 TABLE.
05 TABLE-A OCCURS 500 TIMES
INDEXED BY IDX
10 TEXT PIC X(100)
10 COUNT PIC9(4).

01 W-REC PIC X(100).
01 W-OUT PIC X(100).
01 SUB S9(4) COMP VALUE 0
PROCEDURE DIVISION.

INITIALIZE TABLE-A

READ-PARA.
READ F1 IN W-REC
AT END
SET IDX TO 1
PERFORM VARING SUB FROM 1 BY 1 UNTIL SUB > 500
IF COUNT(IDX) > 3
WRITE W-OUT FROM TEXT(IDX)
ELSE
SET IDX UP BY 1
END-IF
END-PERFORM
STOPRUN
NOT AT-END
CONTINUE
END-READ

SEARCH TABLE-A
AT END
PERFORM TABLE-ENTRY
WHEN W-REC = TEXT(IDX)
ADD +1 TO COUNT
END-SEARCH

GO TO READ-PARA

TABLE-ENTRY.
SET IDX TO 1
PERFORM VARYING SUB FROM 1 BY 1
UNTIL SUB > 500
IF TEXT (IDX) = SPACES
MOVE 1 TO COUNT (IDX)
MOVE W-REC TO TEXT (IDX)
ELSE
SET IDX UP BY 1
END-IF
END-PERFORM

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how can i see junk values in dclgen or in hostvariable of comp ?

2540


i need a small 3d program using inline and outline.

1629


How to remove 2 duplicate records and copy only one using job control language?

740


What is comp-1 and comp-2?

758


I have a program with an Array of 5000 occurences which is being passed from 5 sub levels to the front end screen. Thess 5 programs using each 5*2 = 10 different arrays with size as 5000. This is causing the transaction to utilize more storage consupmtion. I am looking to reduce the storage consumption. As part of that initially i thought Dynamic array may solve my problem. After viewing the comments given i see its same as normal array. IS there any other way we can resolve this issue?

1228






Differentiate between structured cobol programming and object-oriented cobol programming.

663


How can we find that module can be called – whether DYNAMICALLY or STATICALLY?

708


Are you comfortable in cobol or jcl?

639


Which mode is used to operate the sequential file?

658


Explain how you can characterize tables in cobol?

636


How to change size of Initial number of records to *NOMAX for ALL PF files from perticular library, how can I do that

2728


What is rmode(24)

676


How many sections are there in data division in COBOL?

676


2 input fles: 2 flat files, with different number of records. both are having unique key for each record and already sorted in ascending order . match these files using unique key and in output only matching key value has to be written. please procide cobol logic

2104


Whats the difference between search & search ALL?

5260