PERFORM ERROR-FOUND,

ELSE MOVE TEST-FILE TO FILENAME, WRITE LIST-LINE FROM NEWFIL.

\

\Write TEST-DATA to test.file via file descriptor from ope￿n

CALL "write" USING BY VALUE FILE-DESCRIPTOR,

BY VALUE ADDRESS OF TEST-DATA, BY VALUE SIZE-TEST-DATA, GIVING BYTES-WRITTEN.

\

\Check for error and report status.

IF BYTES-WRITTEN = -1 MOVE "Could not write to file"

TO LIST-LINE, PERFORM ERROR-FOUND,

ELSE MOVE "Wrote to file successfully"

TO LIST-LINE,

WRITE LIST-LINE.

\

\Close test.file via file descriptor

CALL "close" USING BY VALUE FILE-DESCRIPTOR,

GIVING RETURN-INT.

\

\Check for error and report status.

IF RETURN-INT

= -1 MOVE "Could not close file"

 

TO LIST-LINE,

 

PERFORM ERROR-FOUND,

ELSE

MOVE "Successfully closed file"

 

TO LIST-LINE,

 

WRITE LIST-LINE.

\

\Open the file test.file for reading.

CALL "open" USING BY VALUE ADDRESS OF TESTFILE,

BY VALUE OFLAG-READ, GIVING FILE-DESCRIPTOR.

\

\Check for error and report status.

IF FILE-DESCRIPTOR = -1 MOVE "Could not open file"

TO LIST-LINE, PERFORM ERROR-FOUND,

ELSE MOVE "File open successful"

TO LIST-LINE,

WRITE LIST-LINE.

\

\Read from test.file via file descriptor from open

CALL "read" USING BY VALUE FILE-DESCRIPTOR,

BY VALUE ADDRESS OF BUFFER,

BY VALUE LENGTH-OF-BUFFER, GIVING BYTES-READ.

\

\Check for error and report status.

Appendix B. Original Examples in Additional BLanguages-181

Page 459
Image 459
IBM Version 4 manual To LIST-LINE Write LIST-LINE, Giving RETURN-INT, If RETURN-INT, Perform ERROR-FOUND