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 initialize two dimantional arrayes in cobol

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

New User


Joined: 27 Aug 2007
Posts: 4
Location: bangalore

PostPosted: Mon Dec 20, 2010 10:43 am    Post subject: How to initialize two dimantional arrayes in cobol
Reply with quote

HI

I have array in cobol, how to initialize this array.
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Dec 20, 2010 10:54 am    Post subject:
Reply with quote

Hello,

Loop thru the array moving the initial value into each array element. . .
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Mon Dec 20, 2010 12:46 pm    Post subject:
Reply with quote

you can also initialize the group item replacing alphanumeric or numeric data by
Back to top
View user's profile Send private message
sriram.mukundan

New User


Joined: 20 Nov 2007
Posts: 28
Location: chennai

PostPosted: Mon Dec 20, 2010 1:47 pm    Post subject:
Reply with quote

Hi,

Code:
01  WS-MAIN-ARRAY.
    03  WS-1.
        05 WS-2                  PIC X(06)   OCCURS 500.
    03  WS-3                                       OCCURS 6.
        05 WS-S4                                   PIC X(02).
        05 WS-S5                                   PIC S9(7)    COMP-3.

INITIALIZE WS-MAIN-ARRAY


Here the Variables with different data type will be initialized to their corresponding default values.

Hope i'm correct.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Mon Dec 20, 2010 1:56 pm    Post subject:
Reply with quote

Sriram,
you are correct.

you could also say,

INITIALIZE WS-MAIN-ARRAY REPLACING NUMERIC DATA BY 9999999
REPLACING ALPHANUMERIC DATA BY 'AB'


But, you do not have a two demensional table.
you have 2, 1 demensional tables.
Back to top
View user's profile Send private message
sriram.mukundan

New User


Joined: 20 Nov 2007
Posts: 28
Location: chennai

PostPosted: Mon Dec 20, 2010 2:38 pm    Post subject:
Reply with quote

HI,

Yes your correct. Hope below example deals with the 2D array

Code:
01  WS-MAIN-ARRAY.
    03  WS-1.
        05 WS-2                  PIC X(06)   OCCURS 500.
    03  WS-3                                       OCCURS 6.
        05 WS-S4                                   PIC X(02).
        05 WS-S5                                   PIC S9(7)    COMP-3.

   05 WS-S6                 PIC S9(5)V99 COMP-3
                                              OCCURS 20.
   05 WS-S7                              OCCURS 40.


Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Mon Dec 20, 2010 2:49 pm    Post subject:
Reply with quote

yes, as long as you realize the valid two demensional array is:
WS-3, WS-S6
the element would be referenced:
ws-s6(1,2,)

your example will not compile, as ws-s7 does not have a pic/usage clause.

and I suggest that you learn to use the preview button, then the 'poor' indentation would be obvious.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Mon Dec 20, 2010 2:51 pm    Post subject:
Reply with quote

Other alternatives are to initialise the uppermost group variable with spaces, low values, or high values with just a single move statement.

Or define a copy of your array storage containg the initialised values, and everytime you need to initialise your work array, just move the copy to the work array. This method is particularily useful if you have to move very specific initialisation values into your array.
Back to top
View user's profile Send private message
sriram.mukundan

New User


Joined: 20 Nov 2007
Posts: 28
Location: chennai

PostPosted: Mon Dec 20, 2010 2:56 pm    Post subject:
Reply with quote

Quote:
Your example will not compile, as ws-s7 does not have a pic/usage clause.


Yes your correct, i didnt remove it in the display, thats why it went in a wrong way.

Quote:
and I suggest that you learn to use the preview button, then the 'poor' indentation would be obvious.


I will take care of indentation in future.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Dec 20, 2010 9:02 pm    Post subject:
Reply with quote

Hello,

Quote:
I will take care of indentation in future.
Before verifying the indentation, you should use the "Code" tag - maybe you used it ablve or maybe some moderator "Code"d this. Once you have "Code"d something, then Preview.

If you copy/paste from your terminal screen, you need not do any spacing as the Code tags wil preserve the spaceing/alignment.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1232
Location: Israel

PostPosted: Mon Dec 20, 2010 10:07 pm    Post subject:
Reply with quote

sriram.mukundan wrote:
I will take care of indentation in future.

Future never happens.
Take care of this right now !!!

Good news everybody, tomorrow I work for free.
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