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
 

 

Difference between Initialize and usine Value clause

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Difference between Initialize and usine Value clause
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    Post subject:
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    Post subject: Reply to: Difference between Initialize and usine Value clau
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: 1239
Location: Richfield, MN, USA

PostPosted: Wed Dec 02, 2009 12:17 pm    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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

Senior Member


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

PostPosted: Tue Dec 08, 2009 8:14 pm    Post subject:
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    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 Difference between TWALENG and TWASIZE Arunkumar Chandrasekaran CICS 3 Tue Jan 03, 2017 12:57 pm
No new posts Sticky: difference between ... DUMMY ... and ... enrico-sorichetti JCL & VSAM 0 Mon Oct 17, 2016 4:31 pm
No new posts Need help on SQL Dynamic WHERE Clause subratarec DB2 12 Sat Jul 16, 2016 3:11 pm
No new posts Difference space showed for TS and it... autobox DB2 1 Thu Apr 14, 2016 1:07 pm
No new posts Difference Between CICS WebSupport an... sachinji84 CICS 1 Mon Mar 07, 2016 7:25 pm


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