Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to initialize a variable with 'Depending on Clause'

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to initialize a variable with 'Depending on Clause'
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    Post subject:
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: 8165
Location: East Dubuque, Illinois, USA

PostPosted: Thu Aug 07, 2008 3:48 am    Post subject:
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    Post subject:
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: 8165
Location: East Dubuque, Illinois, USA

PostPosted: Thu Aug 07, 2008 2:58 pm    Post subject:
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    Post subject:
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: 686
Location: Earth

PostPosted: Thu Aug 07, 2008 3:10 pm    Post subject:
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    Post subject:
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    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 Moving values to a variable of copybo... Vignesh Sid COBOL Programming 6 Wed Sep 06, 2017 1:04 pm
No new posts Updating the Trailer count in variabl... satheshbabur DFSORT/ICETOOL 6 Wed Aug 30, 2017 9:49 pm
No new posts Move from Comp3 variable to Edited Va... sreekusr COBOL Programming 8 Thu Aug 10, 2017 4:20 pm
No new posts Can I traverse a STEM variable? chong.zhou CLIST & REXX 5 Wed May 31, 2017 3:54 pm
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us