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

Initializing the variable having value clause


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Sep 17, 2010 5:14 pm
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
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
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Sep 17, 2010 6:17 pm
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Sep 17, 2010 6:23 pm
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
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

Moderator Emeritus


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

PostPosted: Fri Sep 17, 2010 9:42 pm
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

Senior Member


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

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

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

Moderator Emeritus


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

PostPosted: Sat Sep 18, 2010 12:05 am
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts To search DB2 table based on Conditio... DB2 1
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
No new posts parsing variable length/position data... DFSORT/ICETOOL 5
Search our Forums:

Back to Top