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 

Initialize an Array 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
Siddheart22
Beginner


Joined: 11 Apr 2005
Posts: 42
Topics: 19
Location: India

PostPosted: Thu Jun 16, 2005 8:20 pm    Post subject: Initialize an Array in COBOL Reply with quote

Hi,

This may sound like a silly question, but since I don't have any reference material to look up to, I thought of putting this on your website.

I have an internal array as:
01 TABLE-1 OCCURS 10 TIMES.
05 FIELD-A PIC X(10).
05 FIELD-B OCCURS 20 TIMES PIC X(05).

I need to initialize the FIELD-A as follows:
Entry-1 should contain: AAAAA
Entry-2 should contain: BBBBB
Entry-3 should contain: CCCCC
Entry-4 should contain: DDDDD
Entry-5 should contain: EEEEE
Entry-6 should contain: FFFFF
Entry-7 should contain: GGGGG
Entry-8 should contain: HHHHH
Entry-9 should contain: IIIII
Entry-10 should contain: JJJJJ

FIELD-B are populated in the program.
But Field-A I wanted to initialize in the working storage section itself. I know there is a way, but can't think of it right now.

Your assistance is really appreciated.

Thanks.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Fri Jun 17, 2005 5:17 am    Post subject: Reply with quote

Siddheart22,

some minor corrections. You cannot have a OCCURS clause for level-1 items. Try this. I haven't tested it.


Code:

01 TABLE-1.                                 
   05 TABLE-VALUES OCCURS 10 TIMES.         
      10 FIELD-A PIC X(10).                 
      10 FIELD-B OCCURS 20 TIMES PIC X(05).
                                           
01 INIT-VAL.                               
   05 INIT-1       PIC X(10) VALUE 'AAAA'. 
   05 FILLER       PIC X(100).             
   05 INIT-1       PIC X(10) VALUE 'BBBB'. 
   05 FILLER       PIC X(100).             
   05 INIT-1       PIC X(10) VALUE 'CCCC'. 
   05 FILLER       PIC X(100).             
   05 INIT-1       PIC X(10) VALUE 'DDDD'. 
   05 FILLER       PIC X(100).             
   05 INIT-1       PIC X(10) VALUE 'EEEE'. 
   05 FILLER       PIC X(100).             
   05 INIT-1       PIC X(10) VALUE 'FFFF'. 
   05 FILLER       PIC X(100).             
   05 INIT-1       PIC X(10) VALUE 'GGGG'. 
   05 FILLER       PIC X(100).             
   05 INIT-1       PIC X(10) VALUE 'HHHH'. 
   05 FILLER       PIC X(100).             
   05 INIT-1       PIC X(10) VALUE 'IIII'.
   05 FILLER       PIC X(100).           
   05 INIT-1       PIC X(10) VALUE 'JJJJ'.
   05 FILLER       PIC X(100).           


MOVE INIT-VAL TO TABLE-1




Hope this helps..

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Siddheart22
Beginner


Joined: 11 Apr 2005
Posts: 42
Topics: 19
Location: India

PostPosted: Fri Jun 17, 2005 10:10 am    Post subject: Reply with quote

Hi,
I got an error in compiling at the MOVE statement.

MOVE INIT-VAL TO TABLE-1.

Error says:
"TABLE-1" was a table-item but was not
subscripted or indexed. The first occurrence of the
table was assumed.

I have indexed the TABLE-1 with index INDEX-1 as I need to populate the FIELD-1B of the table through a looping logic in the program.
This is how the table defination looks like in my program.

01 WSTABLE.
05 TABLE-1 OCCURS 10 TIMES INDEXED BY INDEX-1.
10 FIELD-1A PIC X(10).
10 TABLE-B OCCURS 20 TIMES.
15 FIELD-1B PIC X(05).

How should this be done?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Fri Jun 17, 2005 10:30 am    Post subject: Reply with quote

Siddheart22,

If you had actullay read my post clearly you would have found the mistake you are doing by yourself.You need to move the init-val to the 01 level item which is WSTABLE

Code:

MOVE INIT-VAL TO WSTABLE


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Siddheart22
Beginner


Joined: 11 Apr 2005
Posts: 42
Topics: 19
Location: India

PostPosted: Fri Jun 17, 2005 10:54 am    Post subject: Reply with quote

Thanks. But I have a new problem.

I have defined an array in my program as:
Code:

01 wsRptTable.
   05 wsReportAllRegionCounts occurs 10 times indexed by tranTypeIndex.
      10 wsTxnDescription pic x(35).
      10 wsCountsForAllRegions occurs 11 times indexed by RegCountIndex.
         15 wsRegCount pic 9(06) value zeros.
   05 wsTranTableMaxEntries pic 9(02) value 10.


Later, in my program I am trying to execute the following statements:
Code:

perform p5380MoveReportCounters
varying tranTypeIndex
from 1 by 1
until tranTypeIndex > wsTranTableMaxEntries

But, the program does not enters in this p5380MoveReportCounters ...
Is there something wrong with the way the table is defined? or in the way the para is being called?

Your help is really appreciated.
Back to top
View user's profile Send private message
Dibakar
Advanced


Joined: 02 Dec 2002
Posts: 700
Topics: 63
Location: USA

PostPosted: Sat Jun 18, 2005 12:15 am    Post subject: Reply with quote

I beleive i answered last question in another post.
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Sat Jun 18, 2005 12:19 am    Post subject: Reply with quote

Siddheart22,

You have defined "wsTranTableMaxEntries" as a part of the table. Change your definition as follows
Code:

01 wsRptTable.
   05 wsReportAllRegionCounts occurs 10 times indexed by tranTypeIndex.
      10 wsTxnDescription pic x(35).
      10 wsCountsForAllRegions occurs 11 times indexed by RegCountIndex.
         15 wsRegCount pic 9(06) value zeros.

01 wsTranTableMaxEntries pic 9(02) value 10.


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Dibakar
Advanced


Joined: 02 Dec 2002
Posts: 700
Topics: 63
Location: USA

PostPosted: Sat Jun 18, 2005 12:47 am    Post subject: Reply with quote

the other post is deleted. but kolusu has provided better answer.
Back to top
View user's profile Send private message Send e-mail
Crox
Beginner


Joined: 29 May 2004
Posts: 52
Topics: 9

PostPosted: Sat Jun 18, 2005 1:13 pm    Post subject: Re: Initialize an Array in COBOL Reply with quote

Siddheart22 wrote:
Hi,

This may sound like a silly question, but since I don't have any reference material to look up to, I thought of putting this on your website.

I have an internal array as:
01 TABLE-1 OCCURS 10 TIMES.
05 FIELD-A PIC X(10).
05 FIELD-B OCCURS 20 TIMES PIC X(05).

I need to initialize the FIELD-A as follows:
Entry-1 should contain: AAAAA
Entry-2 should contain: BBBBB
Entry-3 should contain: CCCCC
Entry-4 should contain: DDDDD
Entry-5 should contain: EEEEE
Entry-6 should contain: FFFFF
Entry-7 should contain: GGGGG
Entry-8 should contain: HHHHH
Entry-9 should contain: IIIII
Entry-10 should contain: JJJJJ

FIELD-B are populated in the program.
But Field-A I wanted to initialize in the working storage section itself. I know there is a way, but can't think of it right now.

Your assistance is really appreciated.

Thanks.


If you don't need to initialize the fields more than one time, you can use a redefines to get what you need.

Example:

Code:
01 INIT-VAL.                               
   03  INIT-1                       PIC X(10)  VALUE 'AAAA'. 
   03  FILLER                       PIC X(100).             
   03  INIT-2                       PIC X(10)  VALUE 'BBBB'. 
   03  FILLER                       PIC X(100).             
   03  INIT-3                       PIC X(10)  VALUE 'CCCC'. 
   03  FILLER                       PIC X(100).             
   03  INIT-4                       PIC X(10)  VALUE 'DDDD'. 
   03  FILLER                       PIC X(100).             
   03  INIT-5                       PIC X(10)  VALUE 'EEEE'. 
   03  FILLER                       PIC X(100).             
   03  INIT-6                       PIC X(10)  VALUE 'FFFF'. 
   03  FILLER                       PIC X(100).             
   03  INIT-7                       PIC X(10)  VALUE 'GGGG'. 
   03  FILLER                       PIC X(100).             
   03  INIT-8                       PIC X(10)  VALUE 'HHHH'. 
   03  FILLER                       PIC X(100).             
   03  INIT-9                       PIC X(10)  VALUE 'IIII'.
   03  FILLER                       PIC X(100).           
   03  INIT-10                      PIC X(10)  VALUE 'JJJJ'.
   03  FILLER                       PIC X(100).           
01 TABLE-1 REDEFINES INIT-VAL.       
   03 TABLE-VALUES OCCURS 10 TIMES.         
       05  FIELD-A                  PIC X(10).                 
       05  FIELD-B OCCURS 20 TIMES  PIC X(05).


Regards,

Crox
Back to top
View user's profile Send private message
dtf
Beginner


Joined: 10 Dec 2004
Posts: 110
Topics: 8
Location: Colorado USA

PostPosted: Sat Jun 18, 2005 5:54 pm    Post subject: Reply with quote

If it is a one time thing, the redefines is the way to go. Even if it is not, you could always use the defintiion with the redefines, move the storage to a wok area, and then move it back as needed
________
Roor Bongs
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