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

VALUE spaces and Initialize


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

New User


Joined: 24 Aug 2007
Posts: 4
Location: bangalore

PostPosted: Thu Oct 18, 2007 3:07 pm
Reply with quote

Would declaring a alpha numeric variable for ex:

PIC X(10) VALUE SPACES.

Will this change the content of the variable or do i need to use Initialize to make value clause effective??
Back to top
View user's profile Send private message
hemanth.nandas

Active User


Joined: 18 Aug 2007
Posts: 120
Location: India

PostPosted: Thu Oct 18, 2007 3:17 pm
Reply with quote

Hi Ranganathan,

Quote:
PIC X(10) VALUE SPACES.

Will this change the content of the variable or do i need to use Initialize to make value clause effective??


Declaration itself has a effect on Value. So whenever memory allocated for this variable, it will be allocate with value spaces.

So no need to initialize it again.
Back to top
View user's profile Send private message
HARLEEN SINGH MANN
Warnings : 2

New User


Joined: 03 Aug 2007
Posts: 17
Location: Pune

PostPosted: Fri Oct 19, 2007 11:00 pm
Reply with quote

initialize ww-<name>
moves spaces to the alphanumeric and zeros to numeric.

but the VALUE clause in the PIC statement is considered more efficient.
Since it gives a default value before the main processing of the procedure division.
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 148
Location: Ottawa Canada

PostPosted: Mon Oct 22, 2007 11:07 pm
Reply with quote

Hold on guys....

VALUE and INITIALIZE have some important differences.

VALUE will initialize the variable when your run unit starts. This means that it will only initialize on a first-time call to your program. On the other hand, INITIALIZE will initialize the variable every time your code executes.

Consider the scenario where program A calls B 5 times. VALUE clauses will only initialize on the first call to B. Not on the subsequent calls. On subsequent calls the fields will contain whatever value was left from the last call.

This is why you should only ever use VALUE to initialize constants. Always use INITIALIZE (or MOVE or SET) to initialize your variables.

The 2 exceptions to this rule are:

1. 88 levels - They need the VALUE. But you already know that an 88 level does not initialize storage.

2. first time switches - required generally for performance optimization. These switches also need a VALUE.

So - apart from constants, the value majority of your variables should be initialized using INITIALIZE or MOVE or SET.
Back to top
View user's profile Send private message
rajaherein

New User


Joined: 11 Jan 2007
Posts: 23
Location: chennai

PostPosted: Wed Oct 24, 2007 5:36 pm
Reply with quote

Using INITIALIZE verb will take more CPU time than using VALUE clause or MOVE.

Also i contradict with the above statements. If the Call is Dynamic, then for every Call from A to B will present the Program B in its initial state, also, when the Call is Static, Cancel statement in A will bring Program B to its initial state.
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 148
Location: Ottawa Canada

PostPosted: Wed Oct 24, 2007 7:00 pm
Reply with quote

Raj,

You wrote: "...will take more CPU time...".

INITIALIZE statement causes the COBOL compiler to generate 3 Assembler statements to initialize a simple variable whereas VALUE and MOVE will only generate 2 Assembler statements. Compile using the LIST option to confirm this.

So technically - you are correct. However, the difference in CPU will be so very very small that it is not significant - simply not worth worrying about.

Besides... performance is not the primary concern here. The important factor in your decision making is that VALUE and INITIALIZE behave differently.

You wrote: "If the call is Dynamic... in its initial state..."

No. That is not right.

Perhaps your program B is using the INITIAL keyword on the PROGRAM-ID statement. Or perhaps you are executing CANCEL after each CALL. Could you check this out again? There must be an explanation as to the differences we both see.
Back to top
View user's profile Send private message
rajaherein

New User


Joined: 11 Jan 2007
Posts: 23
Location: chennai

PostPosted: Thu Oct 25, 2007 12:02 pm
Reply with quote

Murphy,

Your views are correct.

Many Thanks for correcting my views on Static and Dynamic Calls.
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 leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Cobol program with sequence number ra... COBOL Programming 5
No new posts To Remove spaces (which is in hex for... JCL & VSAM 10
No new posts How to remove spaces in between. SYNCSORT 12
No new posts File transfer from host with filler f... TSO/ISPF 15
Search our Forums:

Back to Top