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
 

 

Initializing the variable having value clause

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
lalitha.rayala5

New User


Joined: 25 Aug 2010
Posts: 10
Location: Bangalore, India

PostPosted: Fri Sep 17, 2010 5:07 pm    Post subject: Initializing the variable having value clause
Reply with quote

Some var X is initialized in WS sec as below.

01 X pic x(03) "ABC".

What happens if we initialize the variable X in procedure division?
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Fri Sep 17, 2010 5:14 pm    Post subject:
Reply with quote

Did you read the manual?

Did you try it to see what happened?
Back to top
View user's profile Send private message
prahalad

New User


Joined: 14 Sep 2010
Posts: 18
Location: Pune

PostPosted: Fri Sep 17, 2010 5:42 pm    Post subject:
Reply with quote

If you initialize the variable X in procedure division the value of X will be "ABC".
Back to top
View user's profile Send private message
lalitha.rayala5

New User


Joined: 25 Aug 2010
Posts: 10
Location: Bangalore, India

PostPosted: Fri Sep 17, 2010 5:44 pm    Post subject: Reply to: Initializing the variable having value clause
Reply with quote

Ok Thank you. Actually I dont have mainframe access to check it.
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Fri Sep 17, 2010 6:14 pm    Post subject: Reply to: Initializing the variable having value clause
Reply with quote

mmmm

when I run this program:
Code:

...
working-storage section.
   01 X pic x(03) VALUE "ABC".           
...

procedure division.                                   
    DISPLAY 'VALUE OF X before INITIALIZE is: <' X '>'   
    INITIALIZE X                                         
    DISPLAY 'VALUE OF X after  INITIALIZE is: <' X '>'   
    GOBACK.


this is what I get:
Code:
VALUE OF X before INITIALIZE is: <ABC>
VALUE OF X after  INITIALIZE is: <   >
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Sep 17, 2010 6:17 pm    Post subject: Reply to: Initializing the variable having value clause
Reply with quote

It's always better to specify a VALUE clause as opposed to initializing the variable during execution. but this may not be applicable for sub-programs unless the INITIAL keyword is included, associated with the program-name.

The compiler will ensure the VALUE is in effect during program prologue.

Bill
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Sep 17, 2010 6:18 pm    Post subject:
Reply with quote

WTF?
why are we continually bombarded with these idiot questions and responses?
this belongs in the rookie forum.

1. 01 X pic x(03) "ABC". will not compile. it is missing a keyword 'VALUE'.
2. the COBOL instruction INITIALIZE does not take into consideration any VALUE clause.

3. You don't need a mainframe to check this. You need to read the manual!
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Sep 17, 2010 6:23 pm    Post subject: Reply to: Initializing the variable having value clause
Reply with quote

Dick brought to our attention
Quote:
1. 01 X pic x(03) "ABC". will not compile. it is missing a keyword 'VALUE'.

Oops, missed that one by a mile.... icon_redface.gif

Bill
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Fri Sep 17, 2010 9:40 pm    Post subject:
Reply with quote

yeap, the question is so 'basic'... but what really surprised me was the (2nd) answer.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Sep 17, 2010 9:42 pm    Post subject:
Reply with quote

Hello,

Quote:
but what really surprised me was the (2nd) answer.
Which is why it is good to be quite familiar/comfortable with the manual icon_smile.gif
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Fri Sep 17, 2010 11:57 pm    Post subject:
Reply with quote

Why is someone sans mainframe even posting here?
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat Sep 18, 2010 12:05 am    Post subject:
Reply with quote

Hi Phil,

Quote:
Why is someone sans mainframe even posting here?
Often, because they are between jobs or between training and a job.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Sep 18, 2010 4:30 am    Post subject:
Reply with quote

In this case it probably doesn't make sense, but you can INITIALIZE X to 'ABC' using the REPLACING phrase.
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 Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm
No new posts Variable for cursor names ravikumar15 DB2 5 Sun Jul 17, 2016 7:08 am
No new posts Need help on SQL Dynamic WHERE Clause subratarec DB2 12 Sat Jul 16, 2016 3:11 pm
No new posts OPC JCL Variable passion_sujesh IBM Tools 5 Fri Jul 01, 2016 4:21 am
No new posts JOINKEYs and Variable files migusd SYNCSORT 8 Fri Jun 17, 2016 3:16 am


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