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

How to Initialize all occurences of a specific Sub Variable


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

New User


Joined: 10 Jul 2008
Posts: 14
Location: Chennai

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

Hi ,

I've a group variable which has 4 subvariables. The group variable has an occurs of 250. I need to initialize all the occurences of a specific sub variable

See below

01 FILE-DATA OCCURS 250 TIMES.

05 NAME PIC X(20).
05 AGE PIC 9(3).
05 TOTAL-PREM PIC S9(5)V99 COMP-3

In the above, I need to initialize all the 250 occurences of TOTAL-PREM alone. Is there any way to do it other than looping 250 times and initializing it ?
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:36 pm
Reply with quote

Occurs cannot be at 01 level ... i dont think MOVE or INITIALIZE would work here ... you will have to use PERFORM ...
Back to top
View user's profile Send private message
sri_mf

Active User


Joined: 31 Aug 2006
Posts: 218
Location: India

PostPosted: Wed Aug 06, 2008 5:56 pm
Reply with quote

I have tried the following cases.
Code:
01 WS-VARIABLES.
   05 WS-OCCURS.
      10 WS-A1  OCCURS 3 TIMES
                      INDEXED BY I.
          20 WS-A1-1 PIC 9(9).
          20 WS-A1-2 PIC X(9).

01 WS-OCCURS.
   10 WS-A1  OCCURS 3 TIMES
                   INDEXED BY I.
       20 WS-A1-1 PIC 9(9).
       20 WS-A1-2 PIC X(9).


INITIALIZE WS-OCCURS worked fine.

Please correct me if i am wrong.
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 5:59 pm
Reply with quote

Sri, You are right it will initialize both WS-A1-1 and WS-A1-2 ... but INITIALIZE WS-A1-1 will not work ....
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Aug 06, 2008 6:05 pm
Reply with quote

Assign a VALUE clause to each elementary array-field and it will be initialized to the specified value prior to program execution.

This has been valid since COBOL2 or COBOL/370, can't recall.

Code:

01 WS-VARIABLES.
   05 WS-OCCURS.
      10 WS-A1  OCCURS 3 TIMES
                      INDEXED BY I.
          20 WS-A1-1 PIC 9(9) VALUE ZERO.
          20 WS-A1-2 PIC X(9) VALUE SPACES.


Bill
Back to top
View user's profile Send private message
sri_mf

Active User


Joined: 31 Aug 2006
Posts: 218
Location: India

PostPosted: Wed Aug 06, 2008 6:18 pm
Reply with quote

ashimer wrote:
but INITIALIZE WS-A1-1 will not work ....


Yes ashmir,I too accept with you.
If that is the case then OP has to follow your first solution ie.using perform.
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: Wed Aug 06, 2008 9:42 pm
Reply with quote

Hello,

Quote:
If that is the case then OP has to follow your first solution ie.using perform.
Or simply provide a VALUE in the definition as Bill suggests.
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 9:48 pm
Reply with quote

true, and second time you want to initialize use perform ...
Back to top
View user's profile Send private message
Ezhil Murugan

New User


Joined: 10 Jul 2008
Posts: 14
Location: Chennai

PostPosted: Thu Aug 07, 2008 9:03 pm
Reply with quote

Thanks all for your help !
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 Moving Or setting POINTER to another ... COBOL Programming 2
No new posts parsing variable length/position data... DFSORT/ICETOOL 5
No new posts Masking variable size field - min 10 ... DFSORT/ICETOOL 4
Search our Forums:

Back to Top