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

Answers were Sorted based on User's Feedback



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

Answer / harsha

1 Sort the file on any key
2 Read file sequentially. While reading, store the record
in a working storage temporary variable and add count
counter variable.
3 Every time you read record, compare it with temporary
variable. if it is same increase counter otherwise reset
counter.
4 When counter become greater than three, write record to
an outfile.

Is This Answer Correct ?    4 Yes 3 No

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

Answer / supreethi

Code:
//*******************************************************
//STEP001 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN1 DD *
AAAAAAAAA
VVVVVVVVV
GGGGGGGG
AAAAAAAAA
HHHHHHHHH
AAAAAAAAA
GGGGGGGG
VVVVVVVVV
/*
//TMP1 DD DSN=&&TEMP1,DISP=(MOD,PASS),SPACE=(TRK,(5,5)),UNIT=SYSDA
//OCCUR1 DD SYSOUT=*
//OCCUR2 DD SYSOUT=*
//OCCUR3 DD SYSOUT=*
//TOOLIN DD *
OCCUR FROM(IN1) LIST(OCCUR1) EQUAL(1)-
ON(1,9,CH) ON(VALCNT,N04)
OCCUR FROM(IN1) LIST(OCCUR2) EQUAL(2)-
ON(1,9,CH) ON(VALCNT,N04)
OCCUR FROM(IN1) LIST(OCCUR3) EQUAL(3)-
ON(1,9,CH) ON(VALCNT,N04)
/*


OCCUR1 contains:

Code:
---+----1----+----2----+
(1,9,CH) VALUE COUNT
HHHHHHHHH 1

OCCUR2 contains:

Code:
---+----1----+----2----+
(1,9,CH) VALUE COUNT
GGGGGGGG 2
VVVVVVVVV 2

OCCUR3 conatains:

Code:
---+----1----+----2----+
(1,9,CH) VALUE COUNT
AAAAAAAAA 3

Is This Answer Correct ?    0 Yes 0 No

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

Answer / 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

More COBOL Interview Questions

I have one ps file in which there are 3 fileds emp_no,emp_name and leave_app.this ps file information give the detail of employee which is going to apply for leave.suppose emp_no=113430,emp_name=ajay,leave_app=1 that means he is going to apply for 1 day leave.and accordingling the table in db2 will be updated means if he has that no of leave in his account then he will get dat leave and updated acc. in table(leave_balance=previous leave present in table-leave_app).Now i want to check whther the updated result is correct or not by comparing the two ps file using IEBCOMPARE or icetool so what is going to be the two ps file and how its is going to be compare.

0 Answers   Cap Gemini,


What is the point of the REPLACING option of a copy statement?

3 Answers  


I have 2 dimensional array with having 100 elements. So how to find the 11th item in an array?

6 Answers   IBM,


what is linkcard in cobol?

1 Answers   TCS,


EXPLAIN MAIN FRAME TESTING PROCESS...HOW TO FIX THE MAINFRAME BUGS?

0 Answers   Accenture,


wht do u mean by (*,intrdr) wht is * used for ?

2 Answers  


what is MSGLEVEL?

1 Answers   IBM,


IF there 5 to 6 files in a JCL and there is some space abends, how can we identify which file has space abend and what can be done to get off that abend or rectify that abend.

2 Answers   ADNA, CSC,


should I use Go back in the main program ? Yes we can use Go back in main program as well.

2 Answers   Xansa,


i need the code for this program in cobol. 2 + 1 = 3 4+3=7 6+5=11 8+7=15 10+9=19

2 Answers  


Which is the default, TEST BEFORE or TEST AFTER for a PERFORM statement?

0 Answers  


how do you reference the ksds vsam file formats from cobol programs

0 Answers  


Categories