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

Initialization Query


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

New User


Joined: 15 Apr 2009
Posts: 47
Location: Bangalore

PostPosted: Mon Jul 27, 2009 12:23 pm
Reply with quote

Hi,

I am seeing two types of initialization in COBOL programs, Both are compiling fine and do not gave any issues so far as per my knowledge.

01 TABLE-WS
05 TABLE-OCCURS OCCURS 2000 TIMES
INDEXED BY IND1.
10 A-WS PIC X(01)

One way
INITIALIZE TABLE-WS

Other way
Move SPACE to A-WS(IND1)
In a Loop 2000 times.

Is there any difference in these two way of initialization methods and which is the correct way of doing it?
Please advice
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Mon Jul 27, 2009 2:53 pm
Reply with quote

Hi Sibi,

as per my knowledge...
its both the same for the example specified ... though I would suggest the INITIALIZE statement as it is readable and helpful during maintenance. icon_lol.gif
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: Mon Jul 27, 2009 3:44 pm
Reply with quote

If you MOVE SPACES to the TABLE-WS "01" level, then the compiler will generate an MVCL and clear the entire table to SPACES.

This should be the most efficient method, although internally, COBOL may also issue an MVCL if you specify an INITIALIZE. You'd have to compile your program, specifying the LIST,NOOFFSET compile options, to view what the compiler generates.

I would avoid initializing each individual table-entry (1-Byte) via a LOOP. This is not very efficient.

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

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Mon Jul 27, 2009 4:34 pm
Reply with quote

Quote:
MOVE SPACES to the TABLE-WS "01" level,

Thats the most efficient one. But, it works as expected only when the table contains alphabetic/alphanumeric items.
Quote:
MOVE ZEROS to the TABLE-WS "01" level,

would work for numeric data type.

For a table containing both numeric and alphabetic items, we
Code:
MOVE dummy-arr-01 to Real-arr-01

Where dummy-arr is identical to real-arr but has values spaces for alphbetic.alpha numeric and zeroes for numeric. We do not mind the additional storage required for dummy-array.

Code:
01 dummy-arr-01
         05 dummy-arr occurs 10 times
            10 dummy-a pic X(10) value spaces.
            10 dummy-9 pic 9(10) value zeroes.
01 real-arr-01
         05 real-arr occurs 10 times
            10 real-a pic X(10) value spaces.
            10 real-9 pic 9(10) value zeroes.
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: Mon Jul 27, 2009 4:46 pm
Reply with quote

Depending on the data-type, SPACES may not be appropriate. But in the example given by the original poster, his OCCURS 2000 Array consists of one-byte of PIC X(01).

It's really up to the reader to make that determination as to what is appropriate. But the MVCL will work every time for Array-Elements which are all PIC X (SPACES) or are all PIC 9 (ZEROS).

This is a basic level of knowledge which should not have to be explained in great detail. icon_eek.gif
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Mon Jul 27, 2009 4:59 pm
Reply with quote

Well thats why i felt INITIALIZE is better. it will take care of all the different data types and initialize all the fields accordingly in just a single statement... icon_rolleyes.gif
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Mon Jul 27, 2009 5:09 pm
Reply with quote

Quote:
But in the example given by the original poster, his OCCURS 2000 Array consists of one-byte of PIC X(01).


Yes. Of course.

But I was just trying to extend the scenario and share the method we follow. icon_exclaim.gif
Back to top
View user's profile Send private message
sibi Yohannan

New User


Joined: 15 Apr 2009
Posts: 47
Location: Bangalore

PostPosted: Mon Jul 27, 2009 5:10 pm
Reply with quote

I was under the impression that, the correct way of initializing a Table is to initialize all the occurances individually.

So INITIALIZE command at the 01 Level of the Table will do the puprose effectively.

Thanks for the information.
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: Mon Jul 27, 2009 9:43 pm
Reply with quote

Hello,

Quote:
I was under the impression that, the correct way of initializing a Table is to initialize all the occurances individually.
Why? As long as the entire area has the proper starting value, why might it matter if "all" were done or if individuals were done. . .?

Quote:
So INITIALIZE command at the 01 Level of the Table will do the puprose effectively.
As will the MOVE SPACES in this case.
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: Mon Jul 27, 2009 10:38 pm
Reply with quote

Dick,

I don't know what would go on "under the covers" regarding the INITIALIZE of the "01" level and that's why I suggested to the OP to compile the program with LIST,NOOFFSET to see what the compiler generates.

Who knows, it might be more draconian than what we're anticipating or it could be as simple as the MOVE LONG?

I've seen some INITIALIZE code translate into some wild BCT's and other forms of slipping itself into unconsciousness and it wouldn't surprise me if this type of code is generated.

This is why we can be assured that the MOVE SPACES at the "01" level will generate an MVCL.

Regards,

Bill
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: Mon Jul 27, 2009 11:42 pm
Reply with quote

Quote:
This is why we can be assured that the MOVE SPACES at the "01" level will generate an MVCL.
Yup, for sure. And yup, there has been some rather strange utc (under-the-covers) code generated. . .

I was just questioning why doing them one at a time (individually) might be "more correct"?
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Tue Jul 28, 2009 3:36 am
Reply with quote

If the table needs initializing only once, an alternative would be:
Code:
01  TABLE-WS.
    05  TABLE-OCCURS         OCCURS 2000 TIMES
                             INDEXED BY IND1.
        10  A-WS  PIC X(01)  VALUE SPACE.

No procedure division statements are necessary. See table handling in the manual.
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: Tue Jul 28, 2009 5:42 am
Reply with quote

Terry,

Ya know, sometimes the easy stuff is right on the end of your nose, but in this case, it missed everyone's nose and perhaps was lodged in a place where the sun don't shine. icon_redface.gif

IIRC, the VALUE clause for array/table elements was introduced with either VS/COBOL II or COBOL/370.

Regards,

Bill
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 RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top