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

How to initialise two dimentional array in COBOL


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

Active User


Joined: 01 Feb 2007
Posts: 123
Location: Hyderabad

PostPosted: Thu Apr 05, 2007 8:48 am
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: 1436
Location: Bangalore,India

PostPosted: Thu Apr 05, 2007 9:20 am
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: 1208
Location: Bangalore,India

PostPosted: Thu Apr 05, 2007 11:03 am
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
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
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: 123
Location: Hyderabad

PostPosted: Mon Apr 09, 2007 11:54 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top