View previous topic :: View next topic |
Author |
Message |
vijay Beginner
Joined: 09 May 2003 Posts: 131 Topics: 64
|
Posted: Mon Jan 26, 2004 3:10 pm Post subject: Find Unique values inside a table in a flat file record |
|
|
Hi ,
I need help with finding unique values in a table which is in a flat file record.
The layout is like this
01 record
03 key-1 x(10)
03 bencd x(3) occurs 50 times
For a particular record I need to get all the unique values of bencd.The bencd values are not sorted in the record.Any help with the logic please?
EZT or COBOL is fine .
Thanks,
Vijay |
|
Back to top |
|
|
hari_uss Beginner
Joined: 19 Dec 2002 Posts: 78 Topics: 6 Location: Trivandrum, India
|
Posted: Tue Jan 27, 2004 2:31 am Post subject: |
|
|
Off the hook. Not tested.
Declare a temporary WS table.
Code: |
01 Ws-temp-table.
03 ws-temp-rec pic X(3) occurs 50 times.
|
Find out the unique.
Code: |
Select-Unique.
Move 1 to temp-count.
Read one record to '01 record' layout.
Perform varying out-count from 1 by 1 until out-count > 50
Perform varying in-count from 1 by 1 until in-count > temp-count or value-found
*Look for this value in the ws-temp-table, If found, it is a duplicate
If bencd(out-count) = ws-temp-table(in-count)
Set value-found to true
End-If
End-Perform
If not value-found
Move bencd(out-count) to ws-temp-table(temp-count)
Add 1 to temp-count
End-If
Initialize Value-found-sw
End-Perform.
|
After the processing, you will have unique values of bencd in an input-record in Ws-temp-table.
I know, I didnt get something right there. I would probably find it in my first round of testing. |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Tue Jan 27, 2004 6:37 am Post subject: |
|
|
Vijay,
How do you want your output to be? Do you want the key and and unique bencd values? Hari has the right idea but I would use a SEARCH for the inner perform varying.
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
vijay Beginner
Joined: 09 May 2003 Posts: 131 Topics: 64
|
Posted: Tue Jan 27, 2004 8:50 am Post subject: |
|
|
Yes Kolusu.I need key and the uniwue bencd values in the output.
Thanks,
Vijay |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Tue Jan 27, 2004 4:39 pm Post subject: |
|
|
Vijay,
The following program will give you the desired results.I used a search to load the internal table.
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. OCCR.
AUTHOR. KOLUSU.
DATE-WRITTEN. 01/27/2004
DATE-COMPILED.
******************************************************************
ENVIRONMENT DIVISION.
******************************************************************
CONFIGURATION SECTION.
SPECIAL-NAMES.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-PARM-FILE
ASSIGN TO INPARM
ORGANIZATION IS SEQUENTIAL.
SELECT OUTPUT-PARM-FILE
ASSIGN TO OUTPARM
ORGANIZATION IS SEQUENTIAL.
******************************************************************
DATA DIVISION.
******************************************************************
FILE SECTION.
FD INPUT-PARM-FILE
RECORDING MODE F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
DATA RECORD IS INPUT-PARM-REC.
01 INPUT-PARM-REC.
05 I-KEY PIC X(10).
05 I-BENCD PIC X(150).
FD OUTPUT-PARM-FILE
RECORDING MODE F
LABEL RECORDS ARE STANDARD
DATA RECORD IS OUTPUT-PARM-REC.
01 OUTPUT-PARM-REC.
05 O-KEY PIC X(10).
05 O-BENCD PIC X(03) OCCURS 50 TIMES.
******************************************************************
WORKING-STORAGE SECTION.
******************************************************************
01 T-BEN-TABLE.
05 T-BEN-REC OCCURS 0 TO 50 TIMES
DEPENDING ON W-MAX-OCCUR
INDEXED BY C-IDX.
10 T-BEN PIC X(03) VALUE SPACES.
01 S-INPUT-EOF PIC X(01) VALUE 'N'.
01 W-SUB PIC S9(4) COMP.
01 W-SEARCH-KEY PIC X(03).
01 W-MAX-OCCUR PIC S9(04) COMP VALUE 0.
******************************************************************
PROCEDURE DIVISION.
******************************************************************
0000-MAINLINE.
PERFORM 1000-INITIALIZE
PERFORM 2000-MAIN-PROCESS UNTIL S-INPUT-EOF = 'Y'
CLOSE INPUT-PARM-FILE
CLOSE OUTPUT-PARM-FILE
GOBACK
.
1000-INITIALIZE.
******************************************************************
* THIS PARAGRAPH IS PERFOMED TO OPEN THE INPUT FILE AND *
* PRIME READ OF THE FILE. *
******************************************************************
OPEN INPUT INPUT-PARM-FILE
OPEN OUTPUT OUTPUT-PARM-FILE
PERFORM 2200-READ-PARM-FILE
.
2000-MAIN-PROCESS.
******************************************************************
* THIS PARA PERFORMS THE MAIN LOGIC OF THE PROGRAM *
******************************************************************
MOVE SPACES TO OUTPUT-PARM-REC
T-BEN-TABLE
MOVE ZERO TO W-MAX-OCCUR
PERFORM VARYING W-SUB FROM 1 BY 3 UNTIL W-SUB > 150
OR I-BENCD (W-SUB : 3) = SPACE
MOVE SPACES TO W-SEARCH-KEY
MOVE I-BENCD(W-SUB : 3) TO W-SEARCH-KEY
PERFORM 2100-SEARCH-BENDCD
END-PERFORM
MOVE I-KEY TO O-KEY
PERFORM VARYING C-IDX FROM 1 BY 1 UNTIL C-IDX > W-MAX-OCCUR
MOVE T-BEN(C-IDX) TO O-BENCD(C-IDX)
END-PERFORM
WRITE OUTPUT-PARM-REC
PERFORM 2200-READ-PARM-FILE
.
2100-SEARCH-BENDCD.
******************************************************************
* THIS PARAGRAPH IS PERFORMED TO SEARCH AND POPULATE THE BENCD *
******************************************************************
SET C-IDX TO 1
SEARCH T-BEN-REC
AT END
MOVE W-SEARCH-KEY TO T-BEN(C-IDX)
COMPUTE W-MAX-OCCUR = W-MAX-OCCUR + 1
WHEN T-BEN(C-IDX) = W-SEARCH-KEY
CONTINUE
END-SEARCH
.
2200-READ-PARM-FILE.
******************************************************************
* THIS PARAGRAPH IS PERFORMED TO READ THE INPUT FILE. *
******************************************************************
READ INPUT-PARM-FILE
AT END
MOVE 'Y' TO S-INPUT-EOF
END-READ
.
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
vijay Beginner
Joined: 09 May 2003 Posts: 131 Topics: 64
|
Posted: Wed Jan 28, 2004 8:10 am Post subject: |
|
|
Thanks Kolusu.It works fine |
|
Back to top |
|
|
|
|