IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

evaluate the duplicates in an array and sum the corr array


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sri.mainframes

New User


Joined: 16 Feb 2006
Posts: 29
Location: MUMBAI

PostPosted: Tue Apr 11, 2006 7:43 pm
Reply with quote

I have two arrays , A & B .
A holds alphanumeric data that may or may not contain duplicates
if duplicate encouter we have to sum corresponding values in B.,
B holds numeric data

for ex let us suppose A and B having the following values

A B
------- -----
abc 2
xyz 1
abc 1
mno 4
abc 1
abc 1
xyz 2
mno 1
stu 2

then i want to display them as

A B
------- -----
abc 5
xyz 3
mno 5
stu 2

can anyone help me to solve this problem.

thanks in advance
sri.prince
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Tue Apr 11, 2006 8:59 pm
Reply with quote

sri.prince,

How many entries do you expect to have in the first array, and how large are each entry?

You can always use the COBOL SORT to do this, but I will do almost anything not to use this, it's very resource intensive. I would probably write a bubble sort then sum the results.

Dave
Back to top
View user's profile Send private message
martin9

Active User


Joined: 01 Mar 2006
Posts: 290
Location: Basel, Switzerland

PostPosted: Tue Apr 11, 2006 9:06 pm
Reply with quote

hy sri.mainframes,

this is not very difficult to do.
first question, if array A holds data as an identifier (alphachar)
and array B holds numeric data, how you want to join them?
probably your example is not complete.

Array A:
abc 2
xyz 1
abc 1
mno 4
abc 1
abc 1
xyz 2
mno 1
stu 2

Array B:
the sums of array A...
--> correct me if i'm wrong...

martin9
Back to top
View user's profile Send private message
sri.mainframes

New User


Joined: 16 Feb 2006
Posts: 29
Location: MUMBAI

PostPosted: Wed Apr 12, 2006 11:16 am
Reply with quote

Hi Martin
I dont want to join them .
Size of the Arrays A & B does not matter but each data item have the same length i.e., pic A(8) and B is pic 9(3)

A B
------- -----
abc 2
xyz 1
abc 1
mno 4
abc 1
abc 1
xyz 2
mno 1
stu 2
011 2
011 1



then the required outcome should be like this
A B
------- -----
abc 5
xyz 3
mno 5
stu 2
011 3

try this one and help me out



thanks
sri.mainframes
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Apr 12, 2006 11:54 pm
Reply with quote

sri.mainframes,

Try this code

Code:


WORKING-STORAGE SECTION.                                     
                                                               
 01  TABLES.                                                   
     05  A-VALUES.                                             
         10  FILLER              PIC X(8)     VALUE 'ABC'.     
         10  FILLER              PIC X(8)     VALUE 'XYZ'.     
         10  FILLER              PIC X(8)     VALUE 'ABC'.     
         10  FILLER              PIC X(8)     VALUE 'MNO'.     
         10  FILLER              PIC X(8)     VALUE 'ABC'.     
         10  FILLER              PIC X(8)     VALUE 'ABC'.     
         10  FILLER              PIC X(8)     VALUE 'XYZ'.     
         10  FILLER              PIC X(8)     VALUE 'MNO'.     
         10  FILLER              PIC X(8)     VALUE 'STU'.     
         10  FILLER              PIC X(8)     VALUE '011'.     
         10  FILLER              PIC X(8)     VALUE '011'.     
     05  A REDEFINES A-VALUES    PIC X(8)     OCCURS 11 TIMES.
     05  B-VALUES.                                             
         10  FILLER              PIC 9(3)     VALUE 2.         
         10  FILLER              PIC 9(3)     VALUE 1.         
         10  FILLER              PIC 9(3)     VALUE 1.         
         10  FILLER              PIC 9(3)     VALUE 4.           
         10  FILLER              PIC 9(3)     VALUE 1.           
         10  FILLER              PIC 9(3)     VALUE 1.           
         10  FILLER              PIC 9(3)     VALUE 2.           
         10  FILLER              PIC 9(3)     VALUE 1.           
         10  FILLER              PIC 9(3)     VALUE 2.           
         10  FILLER              PIC 9(3)     VALUE 2.           
         10  FILLER              PIC 9(3)     VALUE 1.           
     05  B REDEFINES B-VALUES    PIC 9(3)     OCCURS 11 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 'BEFORE SUM'.                               
     DISPLAY ' '.                                       
                                                         
     PERFORM                                             
       VARYING SUB-1 FROM 1 BY 1                         
       UNTIL SUB-1 > 11                                 
           DISPLAY A(SUB-1) ' ' B(SUB-1)                 
     END-PERFORM.                                       
                                                         
     PERFORM                                             
       VARYING SUB-1 FROM 1 BY 1                         
       UNTIL SUB-1 > 11                                 
         PERFORM                                         
           VARYING SUB-2 FROM 1 BY 1                     
           UNTIL SUB-2 > SUB-1 - 1                       
             IF A(SUB-1) = A(SUB-2)                     
             THEN                                       
                 ADD B(SUB-1) TO B(SUB-2)               
                 MOVE 0 TO B(SUB-1)                     
                 MOVE SPACES TO A(SUB-1)           
             ELSE                                   
                 IF A(SUB-2) = SPACES               
                 THEN                               
                     MOVE A(SUB-1) TO A(SUB-2)     
                     MOVE B(SUB-1) TO B(SUB-2)     
                     MOVE SPACES  TO A(SUB-1)       
                     MOVE 0 TO B(SUB-1)             
                 END-IF                             
             END-IF                                 
         END-PERFORM                               
     END-PERFORM.                                   
                                                   
     DISPLAY ' '.                                   
     DISPLAY 'AFTER SUM'.                           
     DISPLAY ' '.                                   
                                                   
     PERFORM                                       
       VARYING SUB-1 FROM 1 BY 1                   
       UNTIL SUB-1 > 11                     
           DISPLAY A(SUB-1) ' ' B(SUB-1)   
     END-PERFORM.                           
                                           
                                           
     GOBACK.                               


Results of running program:

Code:

.               
.BEFORE SUM     
.               
.ABC      002   
.XYZ      001   
.ABC      001   
.MNO      004   
.ABC      001   
.ABC      001   
.XYZ      002   
.MNO      001   
.STU      002   
.011      002   
.011      001   
.
.AFTER SUM                 
.               
.ABC      005   
.XYZ      003   
.MNO      005   
.STU      002   
.011      003   
.         000   
.         000   
.         000   
.         000   
.         000   
.         000   



Dave
Back to top
View user's profile Send private message
sri.mainframes

New User


Joined: 16 Feb 2006
Posts: 29
Location: MUMBAI

PostPosted: Thu Apr 13, 2006 12:20 pm
Reply with quote

Hi Davidatk,

thanks for your help

sri.prince
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL Ascending and descending sort n... COBOL Programming 5
No new posts Evaluate variable to execute a jcl step JCL & VSAM 3
No new posts How to remove block of duplicates DFSORT/ICETOOL 8
This topic is locked: you cannot edit posts or make replies. Compare files with duplicates in one ... DFSORT/ICETOOL 11
No new posts To find an array of words (sys-symbol... JCL & VSAM 9
Search our Forums:

Back to Top