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 this
ᑍ variable and must use a C module to access it. If the
ᑍ developer has ILE C available, the following sample C code
ᑍ will import 'errno' and make it available to the COBOL
ᑍ application
ᑍ
ᑍ #include <errno.h>
ᑍ int geterrno()
ᑍ {
B-182 System API Programming V4R1