IF BYTES-READ = -1 MOVE "Read failed"

TO LIST-LINE, PERFORM ERROR-FOUND,

ELSE IF BYTES-READ = BYTES-WRITTEN MOVE BUFFER TO DATA-READ, WRITE LIST-LINE FROM DATAIN,

ELSE MOVE "Data Truncation on Read"

TO LIST-LINE,

PERFORM ERROR-FOUND.

\

\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.

\

\ Unlink test.file

\

CALL "unlink" USING BY VALUE ADDRESS OF TESTFILE, GIVING RETURN-INT.

\

\Check for error and report status.

IF RETURN-INT

= -1 MOVE "Unlink of file failed"

 

TO LIST-LINE,

 

PERFORM ERROR-FOUND,

ELSE

MOVE "Unlink of file successful"

 

TO LIST-LINE,

 

WRITE LIST-LINE.

\

MOVE "Program run is successful" TO LIST-LINE.

WRITE LIST-LINE. STOP RUN.

\

\End of MAINLINE

\Common error reporting subroutine

\If errors occur, the Integrated File System exports the

\variable 'errno' to assist in determining the problem. As

\'errno' is lowercase, ILE COBOL cannot directly import thi￿s

\variable and must use a C module to access it. If the

\developer has ILE C available, the following sample C cod￿e

\will import 'errno' and make it available to the COBOL

\application

\

\#include <errno.h>

\int geterrno()

\{

B-182System API Programming V4R1

Page 460
Image 460
IBM Version 4 manual To LIST-LINE Perform ERROR-FOUND Else, Write LIST-LINE. Stop RUN