rewrite VB sequential file



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

rewrite VB sequential file

Postby shankarhosur » Sat Oct 16, 2010 6:47 am

FILE-CONTROL.
SELECT REC-11-FILE ASSIGN TO REC11FLE
FILE STATUS IS FS-REC11FLE.

FD REC-11-FILE
RECORDING MODE IS V
RECORD IS VARYING IN SIZE
FROM 1 TO 450
DEPENDING ON WS-REC-LEN
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0.
01 REC-11-REC PIC X(450).

WORKING STORAGE SECTION
01 WS-REC-11 PIC X(450).

PROCEDURE DIVISION.
OPEN I-O REC-11-FILE

2000-CONVERT-DIV-SUB.
Some logic
display 'bforerite- REC-11-REC:'REC-11-REC
REWRITE REC-11-REC from WS-REC-11
display 'afterrite- REC-11-REC:'REC-11-REC
.
2000-CONVERT-DIV-SUB-EXIT.
EXIT.

CLOSE REC-11-FILE

Output of this program.
bforerite- REC-11-REC:101737 12345678911CAA
afterrite- REC-11-REC:101737 12345678911CAA1

Here we are opening the file in I/O mode and updating one field from 3
byte to 4 byte. When we display in the program we are getting correct
only. But it is not re writing to dataset.

JCL:

//MAINSTEP EXEC PGM=PSG4198
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//REC11FLE DD DSN=TADPM63.RM.EXPANDED.AR.CLP3,DISP=MOD
// DCB=(LRECL=454,RECFM=VB,BLKSIZE=0),
// SPACE=(TRK,(01,05),RLSE),
// UNIT=SYSDA

Data in the REC11FLE file before submitting the JOB:
TADPM63.RM.EXPANDED.AR.CLP3--> 101737 12345678911CAA

After successful completion of the JOB. The data in the file is same.
It is not updating though we are getting correct data in the program.

Data in the REC11FLE file after submitting the JOB:
TADPM63.RM.EXPANDED.AR.CLP3--> 101737 12345678911CAA

Please assist me what would be the problem...!!!
shankarhosur
 
Posts: 10
Joined: Sat Oct 16, 2010 6:10 am
Has thanked: 0 time
Been thanked: 0 time

Re: rewrite VB sequential file

 

Re: rewrite VB sequential file

Postby Robert Sample » Sat Oct 16, 2010 7:00 am

From the COBOL Language Reference manual (emphasis added by me):
6.2.31.4 Sequential files

For files in the sequential access mode, the last prior input/output statement executed for this file must be a successfully executed READ statement. When the REWRITE statement is executed, the record retrieved by that READ statement is logically replaced.

The number of character positions in record-name-1 must equal the number of character positions in the record being replaced.

The INVALID KEY phrase must not be specified for a file with sequential organization. An EXCEPTION/ERROR procedure can be specified.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: rewrite VB sequential file

Postby shankarhosur » Sat Oct 16, 2010 7:24 am

After rewriting we could able to see the updated record... but why cant we see the same in dataset????
shankarhosur
 
Posts: 10
Joined: Sat Oct 16, 2010 6:10 am
Has thanked: 0 time
Been thanked: 0 time

Re: rewrite VB sequential file

Postby dick scherrer » Sat Oct 16, 2010 9:10 am

Hello,

After rewriting we could able to see the updated record...
Not really. . . What was displayed was something in memory, not on dasd.

Where is the file read? If there is no read, there can be no rewrite. . .

Where is the file-status? You haven't checked that the open or the rewrite were successful. . . They probably weren't. . .

Suggest you change the program to read one file and write another. Most organizations will not allow updating a sequential file "in place". If there is a problem in the middle of a run, the input has been corrupted. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: rewrite VB sequential file

Postby shankarhosur » Sat Oct 16, 2010 9:16 am

I have read the file and checked file status before read, after read; before rewrite and after rewrite all are successful(00) ...
unnecessarily i dont want to use one more file.. I want to update the same file.
please suggest me better way using I-O mode only..
I am surprised , I could see it in Display after rewrite but why is it not writing to dataset...
shankarhosur
 
Posts: 10
Joined: Sat Oct 16, 2010 6:10 am
Has thanked: 0 time
Been thanked: 0 time

Re: rewrite VB sequential file

Postby dick scherrer » Sat Oct 16, 2010 9:50 am

Hello,

unnecessarily i dont want to use one more file..
It is necessary. . . There are concerns far more important than what a developer "wants".

Why do you believe it appropriate to risk destroying the input file?

If you now work for or if you ever work for a well-managed organization , this will not be permitted. . .

Also, when a file update causes the variable length data to be longer or shorter, the process will completely fail.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: rewrite VB sequential file

Postby NicC » Sat Oct 16, 2010 10:13 am

Did you not read Robert's reply? Especially that part that is in red?

Just in case you have difficulty with English I will rephrase that - "You can only write back the same number of bytes as were read".

You are adding an extra byte - that can not be written back as it would overwrite the first byte of the next record.

Also, you have have added one byte to the record in storage but you have not incremented the record length of that record which is a value held somewhere in storage by the read/write mechanism so that it knows how many bytes to write back. With certain languages you can update this but I do not know about COBOL and when you are doing a REWRITE you cannot change it without corrupting your data.

Know that when you REWRITE you replace the data in the exact same place as it was read from - it does not get written to the end of the file.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post