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
 

 

VALUE spaces and Initialize

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: VALUE spaces and Initialize
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: Chennai

PostPosted: Thu Oct 18, 2007 3:17 pm    Post subject:
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    Post subject:
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: 149
Location: Ottawa Canada

PostPosted: Mon Oct 22, 2007 11:07 pm    Post subject:
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    Post subject:
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: 149
Location: Ottawa Canada

PostPosted: Wed Oct 24, 2007 7:00 pm    Post subject:
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    Post subject:
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    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
No new posts To trim spaces in a pipe delimited da... Nish84 COBOL Programming 16 Mon Oct 10, 2016 1:54 pm
No new posts Removing Extra Spaces in a comma sepa... Puspojit DFSORT/ICETOOL 3 Tue Sep 13, 2016 7:46 am
No new posts Remove intermediate spaces Pallavi Vishwanath SYNCSORT 1 Fri Jan 15, 2016 2:45 am
No new posts Syncsort to remove the leading spaces V S Amarendra Reddy SYNCSORT 5 Fri Jan 08, 2016 9:47 pm
No new posts Padding with variable number of SPACE... cybertaurean SYNCSORT 7 Wed Oct 28, 2015 11:22 pm


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