Use the OPSYS function
- Last Updated: March 30, 2020
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
To avoid the limitations of operating-system-specific statements, use the
OPSYS function to determine the appropriate operating system. The
OPSYS function allows you to build one application that can run on more than
one operating system. The OPSYS function identifies the operating system being
used so that a single version of a procedure can work differently on different operating
systems.
For example, the following procedure produces a listing of the files in your current directory.
The OPSYS function determines the operating system you are running OpenEdge on
and uses the appropriate operating system command to produce the directory listing:
|
To use operating system commands from within OpenEdge, use either the operating
system statement for the operating system you are running on or the OS-COMMAND statement. For example, use the OS-COMMAND
statement on a Windows system and on a UNIX system. If you include the operating system statement
in a procedure on a system other than the one named, the procedure compiles but does not run if
the flow of control passes through that operating system statement. OpenEdge might report an
error when it tries to process an operating system statement on a system other than the one
named. See the ABL Reference for more information on the OPSYS function.
You can also use the built-in preprocessor directive, {&OPSYS}, which expands to a character string that contains the name of the operating system that the file is being compiled on.
The preprocessor is a component of the OpenEdge Compiler. You control the preprocessor by placing preprocessor directives throughout your source code.
The {&OPSYS} preprocessor directive allows you to write code that is
conditionally compiled, while the OPSYS function is a run-time function. For
more information on preprocessor names, see the "Preprocessor" topics of Manage ABL Applications.