MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

COBOL Remove duplicate values from an array

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
shuko
Beginner


Joined: 08 Nov 2005
Posts: 73
Topics: 20

PostPosted: Wed Jul 18, 2007 11:39 am    Post subject: COBOL Remove duplicate values from an array Reply with quote

I have an array with several values. I want to remove the duplicate values.

Code:

Example

Name1         Name2        Flag

Pink           Floyd         D
Jack           Daniel
James          Bond          I
Mike           Jackson
Dave           Seibert       I
Pink           Floyd         I
James          Bond          D



The duplicates will always have a flag. I want to discard the duplicate names with the flag I

Expected output

Code:


Name1         Name2       Flag

Pink          Floyd         D
Jack          Daniel 
Mike          Jackson
Dave          Seibert       I
James         Bond          D
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12377
Topics: 75
Location: San Jose

PostPosted: Wed Jul 18, 2007 11:53 am    Post subject: Reply with quote

shuko,

Are you reading a file and loading these values into an array or how is the array populated?

If you are reading from a file or a DB2 table you can eliminate the dups right when you are loading the array it self

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shuko
Beginner


Joined: 08 Nov 2005
Posts: 73
Topics: 20

PostPosted: Wed Jul 18, 2007 1:32 pm    Post subject: Reply with quote

Kolusu

I am reading a file and populating the array and then I do some processing
with the values in the array. The duplicates are causing a problem for me.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12377
Topics: 75
Location: San Jose

PostPosted: Wed Jul 18, 2007 1:53 pm    Post subject: Reply with quote

shuko,

Try this code.

Code:

01 W-NAMES-TABLE.                                   
   05 W-NAMES-TBL OCCURS 0 TO 30000 TIMES           
                  INDEXED BY W-NAMES-NDX.           
                                                     
        10 W-FULL-NAME.                             
           15 W-FIRST-NAME   PIC X(10).             
           15 W-LAST-NAME    PIC X(10).             
        10 W-NAME-IND        PIC X(01).             
                                                     
01 W-NAME-KEY.                                       
   05 W-FNAME-KEY            PIC X(10) VALUE SPACES.
   05 W-LNAME-KEY            PIC X(10) VALUE SPACES.



OPEN FILE
READ FILE
PERFORM 1000-LOAD-INTERNAL-TABLE UNTIL END-OF-FILE

1000-LOAD-INTERNAL-TABLE

      MOVE FILE-FIRST-NAME     TO W-FNAME-KEY                 
      MOVE FILE-LAST-NAME      TO W-LNAME-KEY                 
      SET W-NAMES-NDX                TO 1                     
                                                       
      SEARCH W-NAMES-TBL                                     
          AT END                                             
             MOVE W-NAMES-REC     TO W-FULL-NAME(W-NAMES-NDX)
             MOVE FILE-IND        TO W-NAME-IND(W-NAMES-NDX) 
        WHEN W-FULL-NAME(W-NAMES-NDX) = W-NAME-KEY         
             CONTINUE                                         
      END-SEARCH                                             
       
      READ FILE
      .
                     


Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Wed Jul 18, 2007 2:25 pm    Post subject: Reply with quote

Kolusu,

Code:

...
  WHEN W-FULL-NAME(W-NAMES-NDX) = W-NAME-KEY
      EVALUATE W-NAME-IND(W-NAMES-NDX)
           WHEN 'I'
                MOVE FILE-IND TO W-NAME-IND(W-NAMES-NDX)
           WHEN OTHER
                CONTINUE
      END-EVALUATE
END-SEARCH

when there is a dup, and the table item is an I, you need to change it. Does not matter if the FILE-IND is I or D.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
shuko
Beginner


Joined: 08 Nov 2005
Posts: 73
Topics: 20

PostPosted: Wed Jul 18, 2007 2:27 pm    Post subject: Reply with quote

Thank you Kolusu. This will get me going.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group