View previous topic :: View next topic
|
Author |
Message |
ranganathanv
New User
Joined: 24 Aug 2007 Posts: 4 Location: bangalore
|
|
|
|
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 |
|
|
hemanth.nandas
Active User
Joined: 18 Aug 2007 Posts: 120 Location: India
|
|
|
|
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 |
|
|
HARLEEN SINGH MANN Warnings : 2 New User
Joined: 03 Aug 2007 Posts: 17 Location: Pune
|
|
|
|
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 |
|
|
TG Murphy
Active User
Joined: 23 Mar 2007 Posts: 148 Location: Ottawa Canada
|
|
|
|
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 |
|
|
rajaherein
New User
Joined: 11 Jan 2007 Posts: 23 Location: chennai
|
|
|
|
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 |
|
|
TG Murphy
Active User
Joined: 23 Mar 2007 Posts: 148 Location: Ottawa Canada
|
|
|
|
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 |
|
|
rajaherein
New User
Joined: 11 Jan 2007 Posts: 23 Location: chennai
|
|
|
|
Murphy,
Your views are correct.
Many Thanks for correcting my views on Static and Dynamic Calls. |
|
Back to top |
|
|
|