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

How to initialize two dimantional arrayes in cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Mon Dec 20, 2010 10:54 am
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: 6966
Location: porcelain throne

PostPosted: Mon Dec 20, 2010 12:46 pm
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
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: 6966
Location: porcelain throne

PostPosted: Mon Dec 20, 2010 1:56 pm
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
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: 6966
Location: porcelain throne

PostPosted: Mon Dec 20, 2010 2:49 pm
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
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
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

Moderator Emeritus


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

PostPosted: Mon Dec 20, 2010 9:02 pm
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: 1353
Location: Israel

PostPosted: Mon Dec 20, 2010 10:07 pm
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 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