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
 

 

How to initialise two dimentional array in COBOL

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

Active User


Joined: 01 Feb 2007
Posts: 120
Location: USA

PostPosted: Thu Apr 05, 2007 8:48 am    Post subject: How to initialise two dimentional array in COBOL
Reply with quote

Hi,

I had a query.
I had two dimentional array as follows.

05 array-name occurs 4 times.
10 ws-name-1 pic x(4).
10 ws-name-2 pic x(4).

I want to initialise the following values into this two dimentional array.
The values are
name-1 name-1
0001 9996
0002 9999
0015 9995
0004 9997

Could any one of them will help me how to initialse the above values in the two dimentional array.
Back to top
View user's profile Send private message

murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1439
Location: Bangalore,India

PostPosted: Thu Apr 05, 2007 9:20 am    Post subject:
Reply with quote

Bhaskar,

Quote:
05 array-name occurs 4 times.
10 ws-name-1 pic x(4).
10 ws-name-2 pic x(4).


Are you sure the above is a two dimensional table declaration?
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Thu Apr 05, 2007 11:03 am    Post subject:
Reply with quote

Hi bhaskar,

Its one dimensional array

Code:
05 array-name occurs 4 times.
10 ws-name-1 pic x(4).
10 ws-name-2 pic x(4).


You can initialize it by using

Code:
PERFORM VARYING I FROM 1 BY UNTIL I>4
     INITIALIZE WS-NAME-1(I) 
     INITIALIZE WS-NAME-2(I) 
END-PERFORM
Back to top
View user's profile Send private message
monga

New User


Joined: 18 Apr 2006
Posts: 13

PostPosted: Thu Apr 05, 2007 11:19 am    Post subject:
Reply with quote

Well..this is a 1 dimensional array that you have declared.

You can move the values to the array using the perform statement as Ekta has mentioned.

If in case you want to initialize this array to the values at the declaration stage then you can follow this:

Code:

05 NAME-LIST.
    10 WS-NAME1 PIC X(16) VALUE '0001000200150004'.
    10 WS-NAME2 PIC X(16) VALUE '9996999999959997'.

05 NAME-ARRAY REDEFINES NAME-LIST.
    10 WS-NAME-1 OCCURS 4 TIMES PIC X(04).
    10 WS-NAME-2 OCCURS 4 TIMES PIC X(04).


or you can even modify this to have the values stored in the same order as in the original array

Thanks,

monga
Back to top
View user's profile Send private message
venosol
Warnings : 1

New User


Joined: 16 Nov 2006
Posts: 43
Location: Bangalore

PostPosted: Thu Apr 05, 2007 11:57 am    Post subject: Re: how to initialise two dimentiona array
Reply with quote

bhaskar_kanteti wrote:
Hi,

I had a query.
I had two dimentional array as follows.

05 array-name occurs 4 times.
10 ws-name-1 pic x(4).
10 ws-name-2 pic x(4).

I want to initialise the following values into this two dimentional array.
The values are
name-1 name-1
0001 9996
0002 9999
0015 9995
0004 9997

Could any one of them will help me how to initialse the above values in the two dimentional array.


That is one dimensional array.


See the below two dimensional array.

01 X PIC 9
01 Y PIC 9
01 WS-GROUP-NAME
05 WS-ARRAY OCCURS 7 TIMES
10 WS-NAME PIC X(10)
10 WS-DTLS OCCURS 5 TIMES
15 WS-ID PIC X(5)
15 WS-DEPT PIC X(6)
PROCEDURE DIVISION
1000-PARA.

PERFORM VARYING X FROM 1 BY 1 UNTIL X > 7
AFTER VARYING Y FROM 1 BY 1 UNTIL Y > 5
ACCEPT WS-NAME(X)
ACCEPT WS-ID(X,Y)
ACCEPT WS-DEPT (X,Y)
END-PERFORM.
STOP RUN.

This will suite your requirement.
Back to top
View user's profile Send private message
bhaskar_kanteti

Active User


Joined: 01 Feb 2007
Posts: 120
Location: USA

PostPosted: Mon Apr 09, 2007 11:54 am    Post subject: Re: How to initialise two dimentional array in COBOL
Reply with quote

Thank You so much friends......

Sorry for writing it as two dimentional array.
Yes, you all are right......
It is one dimentional ARRAY......

And i got my answer from all of you....
thank you so much...
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 XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm
No new posts Search utility(3.14) using JCl and Cobol RKS3 COBOL Programming 12 Sat Jun 10, 2017 10:24 pm
No new posts COBOL DB2 program - zIIP eligible vasanthz COBOL Programming 7 Wed May 31, 2017 5:12 am
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm


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