Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

comparision within 2 dimensional array

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Shweta12j

New User


Joined: 10 May 2010
Posts: 32
Location: Mumbai

PostPosted: Thu Mar 14, 2013 5:44 pm    Post subject: comparision within 2 dimensional array
Reply with quote

Dear All ,

I have a 2 dimensional array defined as follows :
Code:

 01  WS-ARRAYS.                             
     03 WS-NAME-ELEMENT    OCCURS 3 TIMES.   
       05 WS-NAME-DETAILS  OCCURS 99 TIMES.
         10 WS-GR-ID       PIC 9(20).       
*                                           


Name- Element would occur 3 times.
And for each name elemet , GR-ID ranges from 1 to 99 times.
My requirement is the compare GR-ID of each element , if it matches then write to output.

Example :
Name-element 1
Its values are :
GR1
GR2
GR4

Name-element 2
Its values are :
GR1
GR5
GR3

Name-element 3
Its values are :
GR7
GR6
GR1

Expected Output : GR1 (included in all the name elements)
i.e GR-ID which is present for all the name-elements.

Please advice.

Regards,
shweta.
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7905
Location: Bellevue, IA

PostPosted: Thu Mar 14, 2013 5:52 pm    Post subject:
Reply with quote

Your data structure definition and the example data you posted do not match and hence as posted your question makes ABSOLUTELY no sense. Are your GR1, GR2, and so forth supposed to be in WS-NAME-ELEMENT or are they supposed to be in WS-GR-ID? If they are supposed to be in WS-GR-ID, why is it defined as numeric when you have character data in your example?

You would be much better off by coming up with a simpel, clear explanation of what you are trying to do WITHOUT attempting to show us COBOL code that merely confuses the picture. Remember, we do not have the benefit of whatever thought processes you have gone through so far, so we have no idea what assumption you have made already.
Back to top
View user's profile Send private message
Shweta12j

New User


Joined: 10 May 2010
Posts: 32
Location: Mumbai

PostPosted: Thu Mar 14, 2013 5:55 pm    Post subject: Reply to: comparision within 2 dimensional array
Reply with quote

Apology for inconvience caused.
Kindly ignore the code written above.

My requirement is as follows :

Name- Element would occur 3 times.
And for each name elemet , GR-ID ranges from 1 to 99 times.
My requirement is the compare GR-ID of each element , if it matches then write to output.

Example :
Name-element 1
Its values are :
GR1
GR2
GR4

Name-element 2
Its values are :
GR1
GR5
GR3

Name-element 3
Its values are :
GR7
GR6
GR1

Expected Output : GR1 (included in all the name elements)
i.e GR-ID which is present for all the name-elements.

I need to handle this via cobol code.
Please advice.

Regards,
Shweta.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7905
Location: Bellevue, IA

PostPosted: Thu Mar 14, 2013 6:16 pm    Post subject:
Reply with quote

What are the limitations on GR1 ... GRn ? If you are merely concerned about their presence in a name element, use an array of 20 1-byte indicators (0 / 1 if PIC 9 or 'Y' / 'N' - or any other binary combination that makes sense -- would suffice. Set each indicator to flase (zero or space or N or whatever you chose) then read in and process the name elements, setting the appropriate 1-byte indicators for each. After you've read in the three name elements, then a simple loop allows you to check each indicator set.

Inverting the data strcutre would also make sense - having the 20 indicators, and under that the 3 name element flags In such a case, something like this would work (warning: this code is not tested and could have syntax / logic errors):
Code:
01  WS-TABLE.
     05  WS-GR-IND OCCURS 20 INDEXED BY GR-IDX
         10  WS-NE-IND OCCURS 3 INDEXED BY NE-IDX.
             15  WS-FLAG PIC X(01).
.
.
.
     MOVE ALL 'N' TO WS-TABLE.
.
.
.
     SET NE-IDX TO 1.
     IF  <logic to set GR-IDX>
         MOVE 'Y' TO WS-FLAG (GR-IDX, NE-IDX).
.
.
.
     IF WS-FLAG (GR-IDX, 1) = 'Y'
     AND WS-FLAG (GR-IDX, 1) = WS-FLAG (GR-IDX, 2)
     AND WS-FLAG (GR-IDX, 1) = WS-FLAG (GR-IDX, 3)
         <handle match>
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Thu Mar 14, 2013 8:57 pm    Post subject:
Reply with quote

Hi Swetha,
A quick observation... Is the data-structure that you have provided correct ? I mean is it a real-case scenario... ?

Code:
 01  WS-ARRAYS.                             
     03 WS-NAME-ELEMENT    OCCURS 3 TIMES.   
       05 WS-NAME-DETAILS  OCCURS 99 TIMES.
         10 WS-GR-ID       PIC 9(20).
Is the WS-GR-ID really a PIC 9(20) field ? Unless you have changed the compiler option you might have got a compiler error.
If it is a 9(20) field - the important question is as Robert asked ... What is the possible values for this field... Is all value from 0 to 99999999999999999999 possible ?
Another query is repetitions possible within the GROUP ?

On the first look this could be accomplished with a complicated looping SEARCH statement ...
Back to top
View user's profile Send private message
Shweta12j

New User


Joined: 10 May 2010
Posts: 32
Location: Mumbai

PostPosted: Thu Mar 14, 2013 10:49 pm    Post subject: Reply to: comparision within 2 dimensional array
Reply with quote

Yes Binop ,

This is a real scenario.
GR-ID can have any value from starting from zeros to 999999999999....
It is having a pic clause of 9(20).
Repetition within the group is not possible.

As i am not very good with indexing concept m facing a trouble implementing the above mentioned requirement .
Is it possible using an array ?

Regards,
Shweta.
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Thu Mar 14, 2013 10:59 pm    Post subject:
Reply with quote

Shweta12j wrote:
Is it possible using an array ?
I would say using an array (table) is the best option. If you don't store it that way you might have to use a series of PERFORM and IF loops which might look ugly...

Having the data in the table allows you to do a SEARCH command... As said, the logic would still look complex but my feeling is it would easier than the PERFORM and IF loops...
Back to top
View user's profile Send private message
Shweta12j

New User


Joined: 10 May 2010
Posts: 32
Location: Mumbai

PostPosted: Thu Mar 14, 2013 11:23 pm    Post subject: Reply to: comparision within 2 dimensional array
Reply with quote

Thank you Binop for ur suggestion.

Could you please provide a psuedo code.
It would be helpful.

Regards,
Shweta.
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Thu Mar 14, 2013 11:31 pm    Post subject: Re: Reply to: comparision within 2 dimensional array
Reply with quote

Shweta12j wrote:
Thank you Binop for ur suggestion.

Could you please provide a psuedo code.
It would be helpful.

Regards,
Shweta.
As much as I would like to... at the moment my hands are a little tied up.. No guarantees... but I will try to come up with something by EOD...
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Tue Mar 19, 2013 2:44 am    Post subject:
Reply with quote

Hi Shweta,

Apologize... Its been some time since I worked in COBOL and it really more time than I thought it would... Am not saying this is the best approach and others can correct me and make this code simpler maybe... Here is my test code...

Code:
 WORKING-STORAGE SECTION.                           
  01 WS-ARRAYS.                                   
    03 WS-NAME-ELEMENT     OCCURS 03 TIMES         
                       INDEXED BY ELEMENT-INDX.     
       05 WS-NAME-DETAILS  OCCURS 05 TIMES         
                       INDEXED BY DETAILS-INDX.     
          10 WS-GR-ID         PIC 9(02).           
  01 ARR-INDX                 PIC S9(04) USAGE IS COMP.
 PROCEDURE DIVISION.                               
 MAIN-PARA.                                         
* FIRST GROUP                                       
     MOVE 05                   TO WS-GR-ID(1, 1).   
     MOVE 19                   TO WS-GR-ID(1, 2).   
     MOVE 03                   TO WS-GR-ID(1, 3).   
     MOVE 13                   TO WS-GR-ID(1, 4).   
     MOVE 84                   TO WS-GR-ID(1, 5).   
* SECOND GROUP                                     
     MOVE 18                   TO WS-GR-ID(2, 1).   
     MOVE 86                   TO WS-GR-ID(2, 2).   
     MOVE 05                   TO WS-GR-ID(2, 3).   
     MOVE 03                   TO WS-GR-ID(2, 4).   
     MOVE 00                   TO WS-GR-ID(2, 5).   
* THIRD GROUP                                   
     MOVE 18                   TO WS-GR-ID(3, 1).
     MOVE 84                   TO WS-GR-ID(3, 2).
     MOVE 99                   TO WS-GR-ID(3, 3).
     MOVE 01                   TO WS-GR-ID(3, 4).
     MOVE 05                   TO WS-GR-ID(3, 5).
* DISPLAY                                       
     DISPLAY WS-ARRAYS.                         
* SEARCH FOR SAME OCCURENCE IN ALL GROUPS       
     MOVE 1                    TO ARR-INDX.     
     PERFORM SEARCH-PARA THRU SEARCH-PARA-EXIT   
                      VARYING ARR-INDX           
                         FROM 1                 
                           BY 1                 
                        UNTIL ARR-INDX > 5.     
     STOP RUN.                                   
*                                               
 SEARCH-PARA.                                       
     SET  ELEMENT-INDX         TO 02.               
     SET  DETAILS-INDX         TO 01.               
     DISPLAY 'SEARCHING ' WS-GR-ID(1, ARR-INDX) '...'
     SEARCH WS-NAME-DETAILS                         
     AT END                                         
        DISPLAY '     NOT FOUND'                     
        GO TO SEARCH-PARA-EXIT                       
     WHEN WS-GR-ID(ELEMENT-INDX, DETAILS-INDX)       
                 = WS-GR-ID(1, ARR-INDX)             
        DISPLAY '     CONTINUING...'                 
     END-SEARCH
*                                                   
     SET  ELEMENT-INDX         TO 03.               
     SET  DETAILS-INDX         TO 01.               
     DISPLAY '     STARTING SECOND TABLE SEARCH...' 
*                                                   
     SEARCH WS-NAME-DETAILS                         
     AT END                                         
        DISPLAY '     NOT FOUND'                     
     WHEN WS-GR-ID(ELEMENT-INDX, DETAILS-INDX)       
                 = WS-GR-ID(1, ARR-INDX)             
        DISPLAY '     FOUND ' WS-GR-ID(1, ARR-INDX).
     END-SEARCH
*                                                   
 SEARCH-PARA-EXIT.                                   
     EXIT.                                           
Output:
Code:
051903138418860503001884990105     
SEARCHING 05...                     
     CONTINUING...                 
     STARTING SECOND TABLE SEARCH...
     FOUND 05                       
SEARCHING 19...                     
     NOT FOUND                     
SEARCHING 03...                     
     CONTINUING...                 
     STARTING SECOND TABLE SEARCH...
     NOT FOUND                     
SEARCHING 13...                     
     NOT FOUND                     
SEARCHING 84...                     
     NOT FOUND                     
Back to top
View user's profile Send private message
Shweta12j

New User


Joined: 10 May 2010
Posts: 32
Location: Mumbai

PostPosted: Thu Mar 21, 2013 11:29 am    Post subject: Reply to: comparision within 2 dimensional array
Reply with quote

Thank you Binop. I will try the above pseudocode and would let you know the outcome.

Regards,
Shweta.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Unstring list of values into an array. Roshnii COBOL Programming 8 Mon Jun 27, 2016 6:25 pm
No new posts COBOL Program to Read Array data raj4neo COBOL Programming 8 Sat Aug 15, 2015 12:28 am
No new posts Checking for High-Values in an array amitc23 COBOL Programming 10 Wed Aug 05, 2015 4:09 pm
No new posts How to define and use Double dimensio... pkmurali DB2 3 Mon Jun 22, 2015 8:36 am
This topic is locked: you cannot edit posts or make replies. How to Compare two values in an inter... ritnihi COBOL Programming 6 Wed Jun 10, 2015 11:49 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us