File writing from ps to ps fails



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

File writing from ps to ps fails

Postby gowthamgyaa » Thu Oct 25, 2012 4:06 pm

Hi everyone,
I m just Reading a PS file and writing it to empty PS file , eventhough Open, read and write was successful, Contents are not actually written to file
Kindly guide me to clear this error.

ERROR shown in PS file:
The data contains invalid (non-display) characters.


Kind regards
gyaa
gowthamgyaa
 
Posts: 101
Joined: Wed Sep 05, 2012 11:18 pm
Has thanked: 67 times
Been thanked: 0 time

Re: File writing from ps to ps fails

Postby BillyBoyo » Thu Oct 25, 2012 4:16 pm

Impossible to say without seeing the code.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: File writing from ps to ps fails

Postby Robert Sample » Thu Oct 25, 2012 4:33 pm

Are you using the FILE STATUS clause for both files? If not, you need to add them to your code since knowing what the file status code value for the open, read, and write statements can be very helpful in debugging problems.

But, as BillyBoyo said, you have not provided anywhere near enough information for us to provide assistance.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: File writing from ps to ps fails

Postby gowthamgyaa » Thu Oct 25, 2012 5:07 pm

Hi Billy & Robert,
Thank you both for your kind reply.
IDENTIFICATION DIVISION.
PROGRAM-ID. PS1.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
            SELECT INFILE ASSIGN TO SYSUT1
            ORGANIZATION IS SEQUENTIAL
            ACCESS IS SEQUENTIAL
             FILE STATUS IS FSPS.
                                         
             SELECT OUTFILE ASSIGN TO SYSUT2
            ORGANIZATION IS SEQUENTIAL
            ACCESS IS SEQUENTIAL
             FILE STATUS IS PSFS.
DATA DIVISION.
FILE SECTION.
FD INFILE.
01 INREC.
               88 E-EOF VALUE HIGH-VALUES.
               02 E-NO PIC 9(3).
               02 FILLER PIC 9(5).
               02 E-NAME PIC 9(10).
               02 FILLER PIC 9(5).
               02 E-ACCT PIC X(5).
               02 FILLER PIC 9(5).
               02 E-MOB PIC 9(10).
               02 FILLER PIC 9(37).
FD OUTFILE.
01 OUTREC.
               88 E1-EOF VALUE HIGH-VALUES.
               02 E1-NO PIC 9(3).
               02 FILLER PIC 9(5).
               02 E1-NAME PIC 9(10).
               02 FILLER PIC 9(5).
               02 E1-ACCT PIC X(5).
               02 FILLER PIC 9(5).
               02 E1-MOB PIC 9(10).
               02 FILLER PIC 9(37).

WORKING-STORAGE SECTION.
77 FSPS PIC 9(2).
77 PSFS PIC 9(2).

PROCEDURE DIVISION.
MAIN-PARA.
                    PERFORM OPEN-PARA
                    DISPLAY "OPEN WAS SUCCESSFUL".
                    PERFORM READ-PARA
                    DISPLAY "READ WAS SUCCESSFUL".
                    PERFORM WRITE-PARA
                    DISPLAY "CONTENTS OF WRITE FILE:" OUTREC.
                    PERFORM CLOSE-PARA.
                    STOP RUN.

OPEN-PARA.
                   OPEN INPUT INFILE.
                    IF FSPS NOT = '00'
                    DISPLAY "ERROR IN OPENING A FILE:" FSPS
                    PERFORM CLOSE-PARA
                    ELSE
                    DISPLAY "FILE OPENED:" FSPS
                    END-IF.

                   
                    OPEN OUPUT OUTFILE.
                    IF PSFS NOT = '00'
                    DISPLAY "ERROR IN OPENING A FILE:" PSFS
                    PERFORM CLOSE-PARA
                    ELSE
                    DISPLAY "FILE OPENED:" PSFS
                    END-IF.                     

READ-PARA.
                    PERFORM UNTIL EOF
                    READ INFILE AT END SET EOF TO TRUE
                     NOT AT END
                     DISPLAY INREC
                     IF FSPS NOT = '00'
                      DISPLAY "READ ERROR:" FSPS
                    ELSE
                       DISPLAY "FILE WAS READ:" FSPS
                    END-IF
                    END-READ
                    END-PERFORM.

WRITE-PARA.
                     WRITE OUTREC FROM INREC.
                      IF PSFS NOT = '00'
                       DISPLAY "WRITE ERROR:" PSFS
                       PERFORM CLOSE-PARA
                      ELSE
                        DISPLAY "FILE WAS WRITTEN:" PSFS
                      END-IF.

CLOSE-PARA.
                     CLOSE INFILE.
                     CLOSE OUTFILE.
                     




OUTPUT:

FILE OPENED 00
FILE OPENED 00
OPEN WAS SUCCESSFUL
102 GOWT AC123 1234567890
101 GYAA BC126 0987654321
FILE WAS READ 00
READ WAS SUCCESSFUL
FILE WAS WRITTEN 00
CONTENTS OF WRITE FILE:



ACTUAL CONTENT OF PSFILE WHICH IS READ.
102 GOWT AC123 1234567890
101 GYAA BC126 0987654321

PS FILE WRITTEN.
00001 DATA CONTAINS THE INVALID (NON-DISPLAY) CHARACTER.



Kind regards
gyaa
gowthamgyaa
 
Posts: 101
Joined: Wed Sep 05, 2012 11:18 pm
Has thanked: 67 times
Been thanked: 0 time

Re: File writing from ps to ps fails

Postby Robert Sample » Thu Oct 25, 2012 6:11 pm

In your read paragraph, you read the entire file without ever attempting to write a record. Only AFTER you hit end of file do you attempt to write anything to the output file, and by then there's nothing to write into the file.

Your logic should be
Open input file
Open output file
Read input file
PERFORM UNTIL END OF FILE
    Write a record
    Read input file
END-PERFORM

These users thanked the author Robert Sample for the post:
gowthamgyaa (Thu Oct 25, 2012 6:53 pm)
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post