Feedback
Did this article resolve your question/issue?

   

Article

Can the error code returned by the OS-ERROR function be cleared or reset?

Information

 
TitleCan the error code returned by the OS-ERROR function be cleared or reset?
URL NameCan-the-error-code-returned-by-the-OS-ERROR-function-be-cleared-or-reset
Article Number000154758
EnvironmentProduct: OpenEdge
Version: 11.x, 12.x
OS: All supported platforms
Question/Problem Description
Can the error code returned by the OS-ERROR function be cleared or reset?

Is it possible to clear or set the OS-ERROR function return value without running another O.S. function compatible with os-error?
Steps to Reproduce
Clarifying Information
Error Message
Defect/Enhancement Number
Cause
Resolution
It isn't necessary to reset or clear the return value from the OS-ERROR function.  Internally the return value is initialised before the function is executed and the return value is set.  In addition the value returned by the function is only valid immediately after a call to one of the specified O.S. level functions OS-APPEND, OS-COPY, OS-CREATE-DIR, OS-DELETE, OS-RENAME or SAVE CACHE statement.  So it cannot be relied upon unless it is called immediately after the listed function.  For example:
 
DEFINE VARIABLE cFile1 AS CHARACTER NO-UNDO INITIAL "osDelete1.txt".
DEFINE VARIABLE cFile2 AS CHARACTER NO-UNDO INITIAL "osDelete2.txt".

OS-DELETE VALUE(cFile1).
IF OS-ERROR > 0 THEN
DO:
  MESSAGE "Error deleting " + cFile1 VIEW-AS ALERT-BOX.
END.

OS-DELETE VALUE(cFile2).
IF OS-ERROR > 0 THEN
DO:
  MESSAGE "Error deleting " + cFile2 VIEW-AS ALERT-BOX.
END.

In addition 'NO-ERROR' should not be used with O.S. level functions OS-APPEND, OS-COPY, OS-CREATE-DIR, OS-DELETE or OS-RENAME.  These statements do not generate error messages or affect ABL program flow, but using NO-ERROR can set the error value returned by OS-ERROR.  The reason for this is because the O.S. level functions have repetitive options.  For example the ABL Reference entry for OS-DELETE states the syntax as:

User-added image
The underlined ellipses indicates repetition.  You can therefore choose one or more of the preceding items (filenames) and if you specify a filename followed by 'NO-ERROR', then the ABL assumes it needs to delete two files the second one named 'NO-ERROR'.  This file will not be found and the failure to find and delete it will set the OS-ERROR return value.  Therefore avoid using NO-ERROR.
Workaround
Notes
References to Other Documentation:
OpenEdge Development: ABL Reference, "OS-ERROR function"
Last Modified Date2/13/2020 4:16 PM
Attachment 
Files
Disclaimer The origins of the information on this site may be internal or external to Progress Software Corporation (“Progress”). Progress Software Corporation makes all reasonable efforts to verify this information. However, the information provided is for your information only. Progress Software Corporation makes no explicit or implied claims to the validity of this information.

Any sample code provided on this site is not supported under any Progress support program or service. The sample code is provided on an "AS IS" basis. Progress makes no warranties, express or implied, and disclaims all implied warranties including, without limitation, the implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample code is borne by the user. In no event shall Progress, its employees, or anyone else involved in the creation, production, or delivery of the code be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code, even if Progress has been advised of the possibility of such damages.