OS-ERROR function Returns, as an INTEGER value, an ABL error code that indicates whether an execution error occurred during the last OS-APPEND, OS-COPY, OS-CREATE-DIR, OS-DELETE, OS-RENAME or SAVE CACHE statement. Syntax OS-ERROR Example The following procedure prompts the user to enter a file to delete, attempts to delete the file, and then calls the OS-ERROR function to check for an execution error. If an error occurs, the procedure branches based on the error number and responds accordingly. r-os-err.p DEFINE VARIABLE err-status AS INTEGER NO-UNDO. DEFINE VARIABLE filename AS CHARACTER NO-UNDO FORMAT "x(40)" LABEL "Enter a file to delete". UPDATE filename. OS-DELETE VALUE(filename). err-status = OS-ERROR. IF err-status <> 0 THEN CASE err-status: WHEN 1 THEN MESSAGE "You are not the owner of this file or directory.". WHEN 2 THEN MESSAGE "The file or directory you want to delete does not exist.". OTHERWISE DISPLAY "OS Error #" + STRING(OS-ERROR,"99") FORMAT "x(13)" WITH FRAME b. END CASE. Notes This function returns 0 if no error occurred. Use this function immediately following an OS-APPEND, OS-COPY, OS-CREATE-DIR, OS-DELETE, OS-RENAME, or SAVE CACHE statement to determine whether an error occurred during the statement’s execution. If you do not, the next use of one of these statements overwrites the previous error code. Table 49 lists the ABL error codes that the OS-ERROR function can return. Table 49: ABL OS-ERROR codes Error number Description 0 No error 1 Not owner 2 No such file or directory 3 Interrupted system call 4 I/O error 5 Bad file number 6 No more processes 7 Not enough core memory 8 Permission denied 9 Bad address 10 File exists 11 No such device 12 Not a directory 13 Is a directory 14 File table overflow 15 Too many open files 16 File too large 17 No space left on device 18 Directory not empty 999 Unmapped error (ABL default) See also OS-APPEND statement, OS-COPY statement, OS-CREATE-DIR statement, OS-DELETE statement, OS-RENAME statement, SAVE CACHE statement
OS-ERROR
DEFINE VARIABLE err-status AS INTEGER NO-UNDO.
DEFINE VARIABLE filename AS CHARACTER NO-UNDO FORMAT "x(40)"
LABEL "Enter a file to delete".
UPDATE filename.
OS-DELETE VALUE(filename).
err-status = OS-ERROR.
IF err-status <> 0 THEN
CASE err-status:
WHEN 1 THEN
MESSAGE "You are not the owner of this file or directory.".
WHEN 2 THEN
MESSAGE "The file or directory you want to delete does not exist.".
OTHERWISE
DISPLAY "OS Error #" + STRING(OS-ERROR,"99") FORMAT "x(13)"
WITH FRAME b.
END CASE.