MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Array initialisation in COBOL.

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
sunnys_day
Beginner


Joined: 17 Feb 2003
Posts: 1
Topics: 1

PostPosted: Wed Jun 11, 2003 12:31 am    Post subject: Array initialisation in COBOL. Reply with quote

Consider the following array.

01 working-storage.
03 array1 occurs 10 .
05 ele1 pic 9.
05 ele2 pic x.

03 other-element pic 9(2).

Now, suppose that I want to initialise only array1, how do i got about it?
Pls note that I do not want to initialise other-element.

I tried
INITIALIZE array1.
However, this gives an error on the lines of "Trying to access an array without mentioning the subscript."

A work around would be as following:-

Perform varying ws-no 1 by 1 until ws-no>10
Initialize array1(ws-no)
End-Perform.

However, I do not want to use this.
Could you pls suggest an alternative.
Back to top
View user's profile Send private message
satjag
Beginner


Joined: 19 Dec 2002
Posts: 19
Topics: 2

PostPosted: Wed Jun 11, 2003 12:41 am    Post subject: Reply with quote

Hello,

It is not possible to access an array or its element without using the subscript.The method you have suggested is the usual method used for initialising the array elements.
_________________
Regards,
satjag
Back to top
View user's profile Send private message
Tophe
Beginner


Joined: 02 Dec 2002
Posts: 8
Topics: 0
Location: Tours, France

PostPosted: Wed Jun 11, 2003 12:58 am    Post subject: Reply with quote

You can also rewrite your WSS like this :

01 working-storage.
03 table.
05 array1 occurs 10 .
07 ele1 pic 9.
07 ele2 pic x.

05 other-element pic 9(2).

and you can use INITIALIZE TABLE.

HTH

Chris
Back to top
View user's profile Send private message
vp
Beginner


Joined: 30 Jun 2003
Posts: 9
Topics: 0

PostPosted: Mon Jun 30, 2003 11:45 am    Post subject: Reply with quote

If you don't want your other-element to be initialized make it a 03 level (same as table).
Back to top
View user's profile Send private message
CaptBill
Beginner


Joined: 02 Dec 2002
Posts: 100
Topics: 2
Location: Pasadena, California, USA

PostPosted: Mon Jun 30, 2003 2:43 pm    Post subject: Reply with quote

Or you could say
Code:
 MOVE '0 0 0 0 0 0 0 0 0 0 ' TO TABLE.
as defined by Tophe.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
slade
Intermediate


Joined: 07 Feb 2003
Posts: 266
Topics: 1
Location: Edison, NJ USA

PostPosted: Mon Jun 30, 2003 6:06 pm    Post subject: Reply with quote

Or you could code:
Code:

 03 table value '0 0 0 0 0 0 0 0 0 0 ' .

if you only have to init once.

Also, I think you can now value each element definition in the array. Don't know what COBOL Std Version started that.

Regards, Jack.[/quote]
Back to top
View user's profile Send private message
Meera
Beginner


Joined: 27 Jun 2003
Posts: 7
Topics: 0

PostPosted: Tue Jul 01, 2003 11:16 am    Post subject: Reply with quote

Why bother? rewrite your fields:
01 working-storage.
02 init-array.
03 num-1 pic 9.
03 alpha-1 pic x.
03 num-2 pic 9.
03 alpha-2 pic x.
03 num-3 pic 9.
03 alpha-3 pic x.
03 num-4 pic 9.
03 alpha-4 pic x.
03 num-5 pic 9.
03 alpha-5 pic x.
03 num-6 pic 9.
03 alpha-6 pic x.
03 num-7 pic 9.
03 alpha-7 pic x.
03 num-8 pic 9.
03 alpha-8 pic x.
03 num-9 pic 9.
03 alpha-9 pic x.
03 num-10 pic 9.
03 alpha-10 pic x.
02 filler redefines init-array.
03 array1 occurs 10 .
05 ele1 pic 9.
05 ele2 pic x.

02 other-element pic 9(2).


and write

initialize init-array replacing numeric by zero alphanumeric by spaces.
Back to top
View user's profile Send private message
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Tue Jul 01, 2003 1:41 pm    Post subject: Reply with quote

Here is a bithead way to do it.

03 table.
05 array1 occurs 10 .
07 ele1 pic 9.
07 ele2 pic x.
03 r-1 redefines table.
07 r-1-a pic x(18).
07 filler pic x(2).
03 r-2 redefines table.
07 filler pic x(2).
07 r-2-a pic x(18).

move 0 to ele1 (1).
move ' ' to ele2 (1).
move r-1-a to r-2-a.
Back to top
View user's profile Send private message
slade
Intermediate


Joined: 07 Feb 2003
Posts: 266
Topics: 1
Location: Edison, NJ USA

PostPosted: Tue Jul 01, 2003 3:41 pm    Post subject: Reply with quote

Meera,

Why bother what?

Bithead,

What's so cool about r-1-a and r-2-a? Smile

Regards, Jack.
Back to top
View user's profile Send private message
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Tue Jul 01, 2003 3:58 pm    Post subject: Reply with quote

3 lines of executable code - high performance. Try defining a variable with all the initial values for element 1 then this is reduced to 2 lines of executable code.

03 init-values.
07 filler pic 9 value 0.
07 filler pic x value ' '.

move init-values to array1 (1).
move r-1-a to r-2-a.


Any table, any size. Can't get any faster.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group