View previous topic :: View next topic
|
Author |
Message |
lalitha.rayala5
New User
Joined: 25 Aug 2010 Posts: 10 Location: Bangalore, India
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Did you read the manual?
Did you try it to see what happened? |
|
Back to top |
|
|
prahalad
New User
Joined: 14 Sep 2010 Posts: 18 Location: Pune
|
|
|
|
If you initialize the variable X in procedure division the value of X will be "ABC". |
|
Back to top |
|
|
lalitha.rayala5
New User
Joined: 25 Aug 2010 Posts: 10 Location: Bangalore, India
|
|
|
|
Ok Thank you. Actually I dont have mainframe access to check it. |
|
Back to top |
|
|
acevedo
Active User
Joined: 11 May 2005 Posts: 344 Location: Spain
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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....
Bill |
|
Back to top |
|
|
acevedo
Active User
Joined: 11 May 2005 Posts: 344 Location: Spain
|
|
|
|
yeap, the question is so 'basic'... but what really surprised me was the (2nd) answer. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1049 Location: Richmond, Virginia
|
|
|
|
Why is someone sans mainframe even posting here? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
In this case it probably doesn't make sense, but you can INITIALIZE X to 'ABC' using the REPLACING phrase. |
|
Back to top |
|
|
|