View previous topic :: View next topic
|
Author |
Message |
Baby Priya
New User
Joined: 06 Aug 2008 Posts: 3 Location: Bangalore
|
|
|
|
I have an array with six fields.The occurence of the fields depends on a variable dep-val.The maximum number of occurence is 12,(as given)
01 Array1
03 Array-Val OCCURS 0 TO 12 TIMES
DEPENDING ON dep-val.
05 var1 PIC 9(2).
05 var2 PIC 9(2).
05 var3 PIC 9(2).
05 var4 PIC 9(2).
05 var5 PIC 9(2).
05 var6 PIC 9(2).
I don't want to initialize the fields individually.Please tell me how to initialize this array. |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
Use value clause for initial initialization ... and then later on use move zeroes ..
Code: |
01 Array1.
03 dep-val pic 9(2) value 12.
03 array-1.
04 Array-Val OCCURS 12 TIMES
DEPENDING ON dep-val.
05 var1 PIC 9(2) value 0.
05 var2 PIC 9(2) value 0.
05 var3 PIC 9(2) value 0.
05 var4 PIC 9(2) value 0.
05 var5 PIC 9(2) value 0.
05 var6 PIC 9(2) value 0.
move zeroes to array-1
|
If dep-val value is 5 it will move zeroes to the first 5 elements of the array ..
Try this ... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
Actually, Ashimer, from the Language Reference manual section 5.3.17.1 ...
Quote: |
A format 1 VALUE clause specified in a data description entry that contains or is subordinate to an OCCURS clause causes every occurrence of the associated data item to be assigned the specified value. Each structure that contains the DEPENDING ON phrase of the OCCURS clause is assumed to contain the maximum number of occurrences for the purposes of VALUE initialization. |
|
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
True Robert , but this happens only for the first time when working storage variables get initialized ....
now if i move 6 to var1 (1) to var1(12) and then later on move 6 to dep-val and then move zeroes to array-1 it will only initialize var(1) to var(6) to 0 .. var(12) will still be 6 ... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
Uh, the VALUE clause only applies when the program is starting up ... you're talking about run-time behavior, which is an entirely different kettle of fish. The original question was initializing the array, which is program start-up behavior. |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
You might have missed this out ...
Quote: |
Use value clause for initial initialization ... and then later on use move zeroes ..
|
|
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Is there any problem with using INITIALIZE Array1 for the above question? |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
Hi,
You cannot use INITIALIZE for a variable size array ... |
|
Back to top |
|
|
|