View previous topic :: View next topic
|
Author |
Message |
asrinuyadav Warnings : 1 New User
Joined: 27 Aug 2007 Posts: 4 Location: bangalore
|
|
|
|
HI
I have array in cobol, how to initialize this array. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Loop thru the array moving the initial value into each array element. . . |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
you can also initialize the group item replacing alphanumeric or numeric data by |
|
Back to top |
|
|
sriram.mukundan
New User
Joined: 20 Nov 2007 Posts: 28 Location: chennai
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
sriram.mukundan
New User
Joined: 20 Nov 2007 Posts: 28 Location: chennai
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
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 |
|
|
sriram.mukundan
New User
Joined: 20 Nov 2007 Posts: 28 Location: chennai
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
|