two dimension array



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

two dimension array

Postby santhosh18888 » Tue Feb 07, 2012 12:15 am

Can you please correct me if i was wrong in the following declaring two dimension array.

10 W-NAME PIC X(10) OCCURS 10 TIMES
15 PRODUCT-NAME OCCURS 10 TIMES
20 W-PRODUCT-NAME PIC X(10)
20 W-QTY PIC S9(02)

W-NAME which is in level 10 is not coming under any group variable.

This is how i want the values to be stored
W-NAME(1) = 'Santhosh'
W-PRODUCT-NAME(1,1) = 'Shirts'
W-QTY(1,1) = 10
W-PRODUCT-NAME(1,2) = 'PANTS'
W-QTY(1,2) = 20
W-NAME(2) = 'ARUN'
W-PRODUCT-NAME(2,1) = 'Jeans'
W-QTY(2,1) = 3
W-NAME(3) = 'Charu'
W-PRODUCT-NAME(3,1) = 'Laptop'
W-QTY(3,1) = 6
W-PRODUCT-NAME(3,2) = 'Mobile'
W-QTY(3,2) = 2
W-PRODUCT-NAME(3,3) = 'Pen'
W-QTY(3,3) = 9

Whether the above declaration is correct? If wrong can you please provide me a correct declaration to serve the above need.

Thanks,
Santhosh Kumar
santhosh18888
 
Posts: 1
Joined: Mon Feb 06, 2012 11:31 pm
Has thanked: 0 time
Been thanked: 0 time

Re: two dimension array

 

Re: two dimension array

Postby Robert Sample » Tue Feb 07, 2012 12:47 am

The compiler tells the tale (copied from your post):
<2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+-->
           10  W-NAME                  PIC X(10)

1176-E The first level-number was not 01 for item "W-NAME".  A level-number of
       01 was assumed.

1052-E Group item "W-NAME" contained the "PICTURE" clause.  The clause was
       discarded.

                                       OCCURS 10 TIMES

1063-E An "OCCURS" clause was found in the definition of a level-1 item.  The
       "OCCURS" clause was discarded.

               15  PRODUCT-NAME        OCCURS 10 TIMES
                   20  W-PRODUCT-NAME  PIC X(10)

1082-E A period was required.  A period was assumed before "20".

                   20  W-QTY           PIC S9(02)

1082-E A period was required.  A period was assumed before "20".
There's no point in talking about what would work since your concepts of how tables work in COBOL are so far from reality. Once you've created a syntactically valid hierarchy of variable definitions, THEN you can proceed to talk about assigning values to them.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post