MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Strange WS data behavior after WRITE in Cobol.

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
ramy2016
Beginner


Joined: 18 Apr 2016
Posts: 47
Topics: 15

PostPosted: Tue Oct 04, 2016 11:38 am    Post subject: Strange WS data behavior after WRITE in Cobol. Reply with quote

Hello,
I have a Cobol program that reads a sequential dataset and after some data manipulation, writes out a record to sequential Out-File. The WRITE st-t is very simple: WRITE DETAIL-RECORD.
DETAIL-RECORD is defined in WS:
01 DETAIL-RECORD.
05 WS-... PIC X(6).
05 WS-... PIC X(20).
05 WS-... PIC X(09).
....................

This is what's weird: after each of the first 4 WRITES, the DETAIL-RECORD gets whipped out (weird characters, low-values, etc.), but after the 5th WRITE, it retains the written out data. And, since the logic validates a field from DETAIL-RECORD at the end of processing, it works correctly only if there were at least 5 WRITES.

It's a standalone program, there is no PARM or anything like that in JCL.

Any idea where to start looking?
Back to top
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Tue Oct 04, 2016 12:39 pm    Post subject: Reply with quote

I'd check the Language Reference Manual. I believe it says that the contents of the record area in the FD is unpredictable after a WRITE statement. You can fix your problem by doing a WRITE FROM and reference the record area in the FROM clause if you need it. I just noticed that you are writing an area in WS. You can only write the record defined in the FD. Have you populated the contents of DETAIL-RECORD before doing your WRITE of the record defined in the FD?
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Tue Oct 04, 2016 1:08 pm    Post subject: Reply with quote

INITIALIZE DETAIL-RECORD
REPLACING ALPHANUMERIC BY SPACES
NUMERIC BY ZEROS.

Fill in the WS variables

WRITE FD 01 NAME (Insert your 01 Data name here 'FD 01 NAME' )
FROM DETAIL-RECORD
_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
ramy2016
Beginner


Joined: 18 Apr 2016
Posts: 47
Topics: 15

PostPosted: Tue Oct 04, 2016 2:18 pm    Post subject: Reply with quote

Terry_Heinze wrote:
I just noticed that you are writing an area in WS. You can only write the record defined in the FD.


Sorry, my bad, the area I'm writing from is defined in FD.
Back to top
View user's profile Send private message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Tue Oct 04, 2016 2:33 pm    Post subject: Reply with quote

Regardless, you need to initialize the record.
_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
ramy2016
Beginner


Joined: 18 Apr 2016
Posts: 47
Topics: 15

PostPosted: Tue Oct 04, 2016 2:59 pm    Post subject: Reply with quote

I don't understand the point of initializing the FD area I'm writing from?
Or you mean I have to collect data in WS area and than do WRITE "FD record" FROM WS area?
Back to top
View user's profile Send private message
ramy2016
Beginner


Joined: 18 Apr 2016
Posts: 47
Topics: 15

PostPosted: Tue Oct 04, 2016 3:25 pm    Post subject: Reply with quote

It's easy to fix the problem by saving the value I need for post-processing validation in WS. I did that and everything works correctly regardless of number of WRITEs.
I was just curious as to why the data in FD was behaving in such way - getting wiped out exactly from 1 to 4 writes, and kept from 5th write on?
Back to top
View user's profile Send private message
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Tue Oct 04, 2016 3:30 pm    Post subject: Reply with quote

After the WRITE, the "pointer" for the record-area "beneath" the FD is updated to the next available position. Effectively, whether you did an explicit MOVE or a WRITE ... FROM ... (with an implicit MOVE) immediately after the WRITE, the data has "gone".

No, there's no point in INITIALIZE here (or in lots of other places where it is used, but that's another issue).

If you are really desperate for the data to stay around in the FD (not good practice to my mind) then look at specifying the file in a SAME RECORD AREA. You only need to specify one file there, and then you get a separate piece of storage which holds your record, and yet another implicit MOVE to get the data to the actual record-area. I suggest you do it just to see how it works, then change the code back, and change it further so it doesn't rely on anything in the record-area after a WRITE.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group