View previous topic :: View next topic |
Author |
Message |
ramy2016 Beginner
Joined: 18 Apr 2016 Posts: 47 Topics: 15
|
Posted: Tue Oct 04, 2016 11:38 am Post subject: Strange WS data behavior after WRITE in Cobol. |
|
|
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 |
|
|
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Tue Oct 04, 2016 12:39 pm Post subject: |
|
|
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 |
|
|
NASCAR9 Intermediate
Joined: 08 Oct 2004 Posts: 274 Topics: 52 Location: California
|
Posted: Tue Oct 04, 2016 1:08 pm Post subject: |
|
|
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 |
|
|
ramy2016 Beginner
Joined: 18 Apr 2016 Posts: 47 Topics: 15
|
Posted: Tue Oct 04, 2016 2:18 pm Post subject: |
|
|
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 |
|
|
NASCAR9 Intermediate
Joined: 08 Oct 2004 Posts: 274 Topics: 52 Location: California
|
Posted: Tue Oct 04, 2016 2:33 pm Post subject: |
|
|
Regardless, you need to initialize the record. _________________ Thanks,
NASCAR9 |
|
Back to top |
|
|
ramy2016 Beginner
Joined: 18 Apr 2016 Posts: 47 Topics: 15
|
Posted: Tue Oct 04, 2016 2:59 pm Post subject: |
|
|
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 |
|
|
ramy2016 Beginner
Joined: 18 Apr 2016 Posts: 47 Topics: 15
|
Posted: Tue Oct 04, 2016 3:25 pm Post subject: |
|
|
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 |
|
|
William Collins Supermod
Joined: 03 Jun 2012 Posts: 437 Topics: 0
|
Posted: Tue Oct 04, 2016 3:30 pm Post subject: |
|
|
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 |
|
|
|
|