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

Difference between Initialize and usine Value clause


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

Active User


Joined: 27 May 2008
Posts: 121
Location: India

PostPosted: Wed Dec 02, 2009 10:49 am
Reply with quote

Hi All,

Can anybody tell me the difference between Initailze and using value clause?

Sometimes we use value clause while decalration, for ex--

05 CMN PIC S9(4) COMP VALUE 0.

and some times we decalre a variable and in procedure division and we write--

MOVE SPACE TO WS-ADDRESS

where WS-ADDRESS happens to be alphanumeric

Please let me know the right way to initialize a numeric and alphanumeic variable, with example.

Thanks
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Dec 02, 2009 11:38 am
Reply with quote

Hi Meenakshi,
Basic difference is very clear. VALUE clause will assign value only once at start of execution of program where as INITIALIZE or MOVE are procedure division statements which can be used based of requirement of programming logic multiple times to reassign values to variables
Back to top
View user's profile Send private message
meenakshi_forum
Warnings : 1

Active User


Joined: 27 May 2008
Posts: 121
Location: India

PostPosted: Wed Dec 02, 2009 12:09 pm
Reply with quote

Thanks for the reply

This confusion happens becuse in the languages like C, C++, Java,

It is said that initialization takes place first and then is the assignment.

So there the value you assign during declaration is intialization and futher in coding the value assigned is called assignment.

Any suggestions/comments are welcome.

Thanks.
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: Wed Dec 02, 2009 12:17 pm
Reply with quote

Another way of saying VALUEs are assigned at compile time and INITIALIZEs and MOVEs happen at run time.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Dec 02, 2009 12:31 pm
Reply with quote

Quote:
the value you assign during declaration is intialization

This is nothing but VALUE clause

and
Quote:
futher in coding the value assigned is called assignment

This is done by INITIALIZE\MOVE statements

Note: INITIALIZE is statement in cobol. icon_wink.gif
Back to top
View user's profile Send private message
neontech
Warnings : 1

New User


Joined: 08 Dec 2009
Posts: 11
Location: mumbai

PostPosted: Tue Dec 08, 2009 5:26 pm
Reply with quote

Its always better to have values assigned .. rather then initializing it in the procedure division... only if you are doing for the first time... so as mentioned above depends on the program...
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Tue Dec 08, 2009 6:24 pm
Reply with quote

More often, I have come across with situations where we need to initialize in the procedure division.

VALUE clause works only for one time initializations. For most of the batch programs where we need to process n number of records, this may not suffice.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Tue Dec 08, 2009 8:14 pm
Reply with quote

One line answer is -- it depends, though to explain on what it depends will vary program to program (person to person?)

But before I start with, i believe I understand your question and if I don't answer what you need, please re-ask your question.

If you code:
Code:
        01  data        pic xxxxx.

        INITIALIZE program-data.
        ...
        move input-value to program-data.
        if data = 'xxxxx'

think, do you really need INITIALIZE? You do NOT need to initialize the 'program-data' at all. The 'MOVE' statement will initialize the variable.

In other sense, you only need to initialize data variables when they
  • don't have an initial VALUE clause
  • AND are going to be referenced as a source of data prior to 'MOVE'ing something to them.
Code:
     01  var-x         pic 9999 comp.

     If var-x > zero
           ....
      else
           ....  end-if

var-x does not have a known value. If you don't initialize var-x, it may contain any value and that may cause your code to abend or give other incorrect results.
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 Timestamp difference and its average ... DB2 11
No new posts Difference when accessing dataset in ... JCL & VSAM 7
No new posts To search DB2 table based on Conditio... DB2 1
No new posts What is the difference between Taskty... Compuware & Other Tools 2
No new posts Difference between VALIDPROC and CHEC... DB2 3
Search our Forums:

Back to Top