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

How to initialize a variable with 'Depending on Clause'


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Baby Priya

New User


Joined: 06 Aug 2008
Posts: 3
Location: Bangalore

PostPosted: Wed Aug 06, 2008 2:54 pm
Reply with quote

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
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Aug 06, 2008 3:24 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Thu Aug 07, 2008 3:48 am
Reply with quote

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
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Thu Aug 07, 2008 10:02 am
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Thu Aug 07, 2008 2:58 pm
Reply with quote

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
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Thu Aug 07, 2008 3:01 pm
Reply with quote

You might have missed this out ...

Quote:


Use value clause for initial initialization ... and then later on use move zeroes ..

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

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Thu Aug 07, 2008 3:10 pm
Reply with quote

Is there any problem with using INITIALIZE Array1 for the above question?
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Thu Aug 07, 2008 3:21 pm
Reply with quote

Hi,
You cannot use INITIALIZE for a variable size array ...
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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts To search DB2 table based on Conditio... DB2 1
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
No new posts parsing variable length/position data... DFSORT/ICETOOL 5
Search our Forums:

Back to Top