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

Why FD variable initializes automatically?


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

New User


Joined: 25 Oct 2006
Posts: 33

PostPosted: Mon Nov 10, 2008 2:31 pm
Reply with quote

I didn't use FROM, just MOVE some values into the FD variables and WRITE into the file, then I found that after WRITE, the FD variables will be initialized automatically... Just wondering why it happened?

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

Global Moderator


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

PostPosted: Mon Nov 10, 2008 3:00 pm
Reply with quote

Quote:

then I found that after WRITE, the FD variables will be initialized automatically


You did not find what you think you found.
Back to top
View user's profile Send private message
cser_oxygen

New User


Joined: 25 Oct 2006
Posts: 33

PostPosted: Mon Nov 10, 2008 3:16 pm
Reply with quote

dbzTHEdinosauer wrote:
Quote:

then I found that after WRITE, the FD variables will be initialized automatically


You did not find what you think you found.


For example:

FD FILE-NAME.
01 RECORD-NAME PIC XXX.

In the pgm:

MOVE ABC TO RECORD-NAME

WRITE RECORD-NAME

Then:
DISPLAY RECORD-NAME

It will show empty, means no data in variable RECORD-NAME
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Nov 10, 2008 3:47 pm
Reply with quote

When you write directly from the buffer (WRITE without the workarea option),
each successive WRITE will position the register, which is assigned to the buffer, to the next record position w/in the buffer.

It is possible after the 1st write that the next record position in the buffer seems to be initialized. But if it is initialized to anything, it would be low-values.

IBM COBOL does not guarentee any 'automatic' initialization other than that explilcitly required due to
a VALUE clause of data element description
or
the INITIAL clause of the PROGRAM-ID paragraph.

If you had a block size of one (1), I imagine you would find that after the WRITE, your display would be that of the record just written.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Mon Nov 10, 2008 5:33 pm
Reply with quote

cser_oxygen wrote:
I didn't use FROM, just MOVE some values into the FD variables and WRITE into the file, then I found that after WRITE, the FD variables will be initialized automatically... Just wondering why it happened?

Thanks!


It would be a bad idea to write a program based on that assumption.
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: Mon Nov 10, 2008 6:07 pm
Reply with quote

Quote:
IBM COBOL does not guarentee any 'automatic' initialization other than that explilcitly required due to
a VALUE clause of data element description
or
the INITIAL clause of the PROGRAM-ID paragraph.
On the other hand, LE does have the STORAGE option to automatically initialize storage to a given value -- and it can be turned on at the site level by default.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Nov 10, 2008 6:32 pm
Reply with quote

Robert,
thanks for the expansion/correction.
That would account for spaces in the OPs subsequent record area.
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: Mon Nov 10, 2008 6:41 pm
Reply with quote

The manual clearly states:
"6.2.40.5 WRITE for sequential files

The maximum record size for sequential files is established at the time the file is created and cannot subsequently be changed.

After the WRITE statement is executed, the logical record is no longer available in record-name-1 unless either:


The associated file is named in a SAME RECORD AREA clause (in which case, the record is also available as a record of the other files named in the SAME RECORD AREA clause)

The WRITE statement is unsuccessful because of a boundary violation.


In either of these two cases, the logical record is still available in record-name-1."
Copyright IBM
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: Mon Nov 10, 2008 9:30 pm
Reply with quote

Hello,

Something that has caused problems for very many systems/programs is that when there have been "enough" writes to a file, the address for the "next" write is an address that has been written from previously. If the output record area is not completely, properly initialized, some value(s) from some previous record are written and can be a nightmare to diagnose.

If it is early in the run and some field is unitialized, it is usually easier to detect than completely valid data that is "left over" from some previous write.
Back to top
View user's profile Send private message
cser_oxygen

New User


Joined: 25 Oct 2006
Posts: 33

PostPosted: Mon Nov 10, 2008 10:29 pm
Reply with quote

Craq Giegerich wrote:
cser_oxygen wrote:
I didn't use FROM, just MOVE some values into the FD variables and WRITE into the file, then I found that after WRITE, the FD variables will be initialized automatically... Just wondering why it happened?

Thanks!


It would be a bad idea to write a program based on that assumption.


I just did some test on this icon_razz.gif

Thank you for all the replies!
Back to top
View user's profile Send private message
cser_oxygen

New User


Joined: 25 Oct 2006
Posts: 33

PostPosted: Wed Nov 02, 2016 11:01 pm
Reply with quote

Just happen to be back to ibmmainframes today.
After 10 years working this field, I have to admit I am being very selfish, just search for answers and walk away, zero contribute...

Today I thought why not take a look what I have posted previously... so here i am...

Reading my 8 years back post still moves me... what a great forum! icon_exclaim.gif icon_exclaim.gif icon_exclaim.gif
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 Moving Or setting POINTER to another ... COBOL Programming 2
No new posts parsing variable length/position data... DFSORT/ICETOOL 5
No new posts Masking variable size field - min 10 ... DFSORT/ICETOOL 4
Search our Forums:

Back to Top