3-dimensional array



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

3-dimensional array

Postby Vikrant Survase » Fri Jun 04, 2010 9:23 pm

i want to create a 3or more than 3 dimensional array, how do i create it and add some content in it? :?:
Vikrant Survase
 
Posts: 19
Joined: Fri Jun 04, 2010 9:08 pm
Has thanked: 0 time
Been thanked: 0 time

Re: 3-dimensional array

 

Re: 3-dimensional array

Postby Robert Sample » Fri Jun 04, 2010 10:06 pm

Enterprise COBOL supports arrays up to 7 dimensions. Just define the OCCURS variables, set your subscripts (or indexes) and use the array elements just like any other array in COBOL.
Robert Sample
Global moderator
 
Posts: 3443
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 242 times

Re: 3-dimensional array

Postby dick scherrer » Sat Jun 05, 2010 2:58 am

Hello and welcome to the forum,

Is this just out of curiosity or do you have some requirement? Is this a solution in search of a requirement?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 92 times

Re: 3-dimensional array

Postby Vikrant Survase » Sun Jun 06, 2010 5:17 pm

actually ths was our assingment so would u plz help me?
Vikrant Survase
 
Posts: 19
Joined: Fri Jun 04, 2010 9:08 pm
Has thanked: 0 time
Been thanked: 0 time

Re: 3-dimensional array

Postby Vikrant Survase » Sun Jun 06, 2010 5:50 pm

Robert Sample wrote:Enterprise COBOL supports arrays up to 7 dimensions. Just define the OCCURS variables, set your subscripts (or indexes) and use the array elements just like any other array in COBOL.


ya i know we hv to use OCCURS clause but for 3 dimensional it must be written 3 times as shown

01 table.
   02 tab1 occurs 5 times.
    03 tab2 occurs 4 times.
     04 tab3 occurs 3 times.
      05 num pic 9(4).


is this correct?
if not would u please tell me the proper code..!

and hw does we access it.
Vikrant Survase
 
Posts: 19
Joined: Fri Jun 04, 2010 9:08 pm
Has thanked: 0 time
Been thanked: 0 time

Re: 3-dimensional array

Postby Robert Sample » Sun Jun 06, 2010 8:20 pm

Your definition is exactly right. You would need to define subscript variables for each dimension, set them appropriately, then use them to access NUM. For example,
77  WS-I1 PIC 9.
77  WS-I2 PIC 9.
77  WS-I3 PIC 9.


MOVE 4 TO WSI1.
MOVE 3 TO WS-I2.
MOVE 2 TO WS-I3.
MOVE NUM (WS-I1, WS-I2, WS-I3) TO ...
or you could define an INDEXED BY for each OCCURS clause and use the indexes instead of subscripts.
Robert Sample
Global moderator
 
Posts: 3443
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 242 times

Re: 3-dimensional array

Postby Vikrant Survase » Mon Jun 07, 2010 12:08 am

Robert Sample, thanks thats was helpful
Vikrant Survase
 
Posts: 19
Joined: Fri Jun 04, 2010 9:08 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post