View previous topic :: View next topic
|
Author |
Message |
sreddy
New User
Joined: 16 Mar 2005 Posts: 8 Location: Bangalore
|
|
|
|
Hi
Can any one explain how I'll find the duplicates in an array? |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
sreddy,
Is this a CICS question, or a COBOL question? If COBOL, this should probable be posted in one of the COBOL forums.
Could you be more specific in your question please. What does the array structure look like, are you looking for 100% duplicates (every field equal) are just some key fields. What do you want to do with the duplicates when found?
The more information you can give, the better we can help.
Please come back
Dave |
|
Back to top |
|
|
sreddy
New User
Joined: 16 Mar 2005 Posts: 8 Location: Bangalore
|
|
|
|
Ex:
Array of 10 elements.
Like A C D B C A S R P D
My requirement is to find the repeated ones, like A C D in the above. |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
sreddy,
First, send a PM to the Moderator for the CICS forum and have them move this to one of the COBOL forums please.
Does this code suit your porpose?
Code: |
WORKING-STORAGE SECTION.
01 TABLES.
05 TABL-ENTRIES PIC S9(3) COMP-3
VALUE 10.
05 TABL-VALUES.
10 FILLER PIC X(8) VALUE 'A'.
10 FILLER PIC X(8) VALUE 'C'.
10 FILLER PIC X(8) VALUE 'D'.
10 FILLER PIC X(8) VALUE 'B'.
10 FILLER PIC X(8) VALUE 'C'.
10 FILLER PIC X(8) VALUE 'A'.
10 FILLER PIC X(8) VALUE 'S'.
10 FILLER PIC X(8) VALUE 'R'.
10 FILLER PIC X(8) VALUE 'P'.
10 FILLER PIC X(8) VALUE 'D'.
05 TABL REDEFINES TABL-VALUES
PIC X(8) OCCURS 10 TIMES.
05 SUB-1 PIC S9(3) COMP-3
VALUE 1.
05 SUB-2 PIC S9(3) COMP-3
VALUE 1.
LINKAGE SECTION.
PROCEDURE DIVISION.
DISPLAY 'TABLE VALUES'
DISPLAY ' '.
PERFORM
VARYING SUB-1 FROM 1 BY 1
UNTIL SUB-1 > TABL-ENTRIES
DISPLAY TABL(SUB-1)
END-PERFORM.
DISPLAY ' '
DISPLAY 'DUP LIST'
DISPLAY ' '
PERFORM
VARYING SUB-1 FROM 1 BY 1
UNTIL SUB-1 > TABL-ENTRIES
PERFORM
VARYING SUB-2 FROM 1 BY 1
UNTIL SUB-2 > SUB-1 - 1
IF TABL(SUB-1) = TABL(SUB-2)
THEN
PERFORM DUP-FOUND
MOVE SUB-1 TO SUB-2
END-IF
END-PERFORM
END-PERFORM.
GOBACK.
DUP-FOUND.
DISPLAY 'DUP VALUE ''' TABL(SUB-1)
''' AT TABLE LOC ''' SUB-1
''' WAS FOUND AT TABLE LOC ''' SUB-2 ''''.
|
Results
Code: |
TABLE VALUES
A
C
D
B
C
A
S
R
P
D
DUP LIST
DUP VALUE 'C ' AT TABLE LOC '005' WAS FOUND AT TABLE LOC '002'
DUP VALUE 'A ' AT TABLE LOC '006' WAS FOUND AT TABLE LOC '001'
DUP VALUE 'D ' AT TABLE LOC '010' WAS FOUND AT TABLE LOC '003'
|
Dave |
|
Back to top |
|
|
|