Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Initialization Query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Initialization Query
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Mon Jul 27, 2009 3:44 pm    Post subject: Reply to: Initialization Query
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Mon Jul 27, 2009 4:46 pm    Post subject: Reply to: Initialization Query
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    Post subject:
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    Post subject:
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    Post subject: Initialization Query
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

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Jul 27, 2009 9:43 pm    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Mon Jul 27, 2009 10:38 pm    Post subject: Reply to: Initialization Query
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

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Jul 27, 2009 11:42 pm    Post subject:
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: 1238
Location: Richfield, MN, USA

PostPosted: Tue Jul 28, 2009 3:36 am    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Tue Jul 28, 2009 5:42 am    Post subject: Reply to: Initialization Query
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    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
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm
No new posts Problem in Running Query via JCL vickey_dw DB2 3 Tue Oct 18, 2016 11:11 pm
No new posts SQL Query optimization. arunsoods DB2 12 Sun Sep 04, 2016 6:27 am
No new posts Query on BLSR Nileshkul JCL & VSAM 2 Sat Aug 13, 2016 5:18 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us