Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

REWRITE ON A SEQUENTIAL FILE 1

Status
Not open for further replies.

hero69

Technical User
May 20, 2003
9
CH
Hi at all

I have a problem when I try to rewrtie to a sequential file. I get always this error message: IGYPS2074-S "OUTPUT-FILE" was defined as a type that was invalid in this context.

Program-Code:

CBL LIB,QUOTE,OPT
************************************************
** Counter - Read a file and count the words in
** this file.
************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. COUNTER.

ENVIRONMENT DIVISION.

INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-FILE
ASSIGN TO INFILE
FILE STATUS IS INPUT-FILE-STATUS.

SELECT OUTPUT-FILE
ASSIGN TO OUTFILE
* ORGANIZATION IS SEQUENTIAL
* ACCESS MODE IS SEQUENTIAL
* ACCESS MODE IS DYNAMIC
FILE STATUS IS OUTPUT-FILE-STATUS.

DATA DIVISION.
FILE SECTION.
FD INPUT-FILE
RECORDING MODE IS F.

01 INPUT-RECORD.
05 TEXT-STRING PIC X(80).

FD OUTPUT-FILE
RECORDING MODE IS F
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 80 CHARACTERS.
01 OUTPUT-RECORD.
05 TEXT-STRING PIC X(80).

WORKING-STORAGE SECTION.

77 INPUT-FILE-STATUS PIC XX VALUE "00".
88 EOF-EIN VALUE "10".

77 OUTPUT-FILE-STATUS PIC XX VALUE "00".
88 EOF-OUT VALUE "10".

01 WORD-COUNT PIC 9(8) VALUE 0.
01 C-COUNT PIC 9(8) VALUE 0.

01 DELIM PIC X(1) VALUE " ".

01 T-REC PIC X(80).
01 TEMP-REC PIC X(80).
01 I PIC 9(09) USAGE BINARY.

01 TARGET-AREA.
02 INDIVIDUAL-CHAR OCCURS 1 TO 1000 TIMES DEPENDING ON
C-COUNT PIC X VALUE " ".

PROCEDURE DIVISION.

OPEN-OUTPUT.
OPEN I-O OUTPUT-FILE.
DISPLAY "OUTPUT-FILE-SATUS : " OUTPUT-FILE-STATUS
READ OUTPUT-FILE INTO TEMP-REC
DISPLAY "OUTPUT-FILE-SATUS : " OUTPUT-FILE-STATUS
DISPLAY "TEMP-REC : " TEMP-REC
PERFORM UNTIL EOF-OUT
REWRITE OUTPUT-FILE FROM TEMP-REC
READ OUTPUT-FILE INTO TEMP-REC
DISPLAY "OUTPUT-FILE-SATUS : " OUTPUT-FILE-STATUS
END-PERFORM
CLOSE OUTPUT-FILE

GOBACK.
END PROGRAM COUNTER.


Some one now this problem?

Thanks
 
hero,

Does your OUTPUT-FILE already exist? You can only READ/REWRITE the records in a sequential file after they exist.

You still have to process the records sequentially though.

"Code what you mean,
and mean what you code!
But by all means post your code!"

Razalas
 
hi

Change the rewrite statemnet as follows

MOVE TEMP-REC TO TEXT-STRING.
REWRITE OUTPUT-RECORD.
 
REWRITE...FROM is valid, standard COBOL, and does not seem to be causing this diagnostic.

Tom Morrison
 
Hey Tom

Is it valid to rewrite back to a file descriptor?? I never knew that. what I know is u need to rewrite the record and not file.

what he has coded is
REWRITE OUTPUT-FILE FROM TEMP-REC
which I suppose should change to
REWRITE OUTPUT-RECORD FROM TEMP-REC

I divided the statement into 2 part only because he has a elementary field under output-record. So if he add more field tomorrow he will not need to change the rewrite statement.

Correct me if I wrong..

Devesh
 
Sorry folks

but you have all wrong!! I have found the problem, in the rewrite statement you musst code the 01 level of var or struktur!
.....
....
FD OUTPUT-FILE
RECORDING MODE IS F
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 80 CHARACTERS.
01 OUTPUT-RECORD.
05 TEXT-STRING PIC X(80).
...
...
...

REWRITE OUTPUT-RECORD
...
...

Thanks for you help.


 
Davesh,

Of course you are right -- I missed it. Won't those compiler vendors ever learn how to give informative diagnostics? [hammer]

Catch a star!

Tom Morrison
 
Hi Hero,

Sorry, but YOU have it all wrong. Perhaps you missed it, but Devesh was right on.

P.S. You might want to check your file statuses (or is it stata?), you might be posting here again, wondering why your REWRITE didn't get applied.

Regards, Jack.
 
Hi Jack,

Sorry but you can't compile the program! How you want check the file statuses?

I have tested my program after the change an it works fine. You think I will write an answer with a wrong argument? No sorry.

Regards,

Hero69
 
Hi Hero,

The following (Devesh's code) should compile fine.

REWRITE OUTPUT-RECORD FROM TEMP-REC

What you wrote, wouldn't (didn't).

REWRITE OUTPUT-FILE FROM TEMP-REC


You should check the file status after each I/O operation. If you don't you run the risk of creating a file that is either empty or may be missing records, or who knows what.

The usual sequence is:
Code:
77 INPUT-FILE-STATUS  PIC XX VALUE "00".
   88 EOF-EIN                VALUE "10". 
   88 EIN-OK                 VALUE "01" "09"
                                   "11" "99".
 
77 OUTPUT-FILE-STATUS PIC XX VALUE "00".
   88 EOF-OUT                VALUE "10". 
   88 OUT-OK                 VALUE "01" "09"
                                   "11" "99". 


OPEN... or READ... or REWRITE... or CLOSE... etc. 
IF ??-FILE-STATUS IS NOT ??-OK
   LET SOMBODY KNOW
   ABEND OR SOMETHING
END-IF

There may be some status codes that you may find acceptable. I took the easy way out for this example.

Well, you get the idea.

Regards, Jack.
 
Sorry, I'm up too late. The 88 levels should be ??-NOT-OK.

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top