Asynchronous Processing

This document describes asynchronous Natural processing, a method which is available under all TP monitors supported by Natural.

An asynchronous Natural session is a session which is not associated with any terminal and therefore cannot interact with a terminal user. It can be used to execute a time-consuming task "in the background" without the user having to wait for the task to finish.

This section covers the following topics:

Related Topics:


Identifying Asynchronous Natural Sessions

To identify a session as being asynchronous, the Natural system variable *DEVICE is assigned the value ASYNCH.

Anmerkung:
The value of *DEVICE may be modified by the Natural profile parameter TTYPE and by any SET CONTROL 'T=xxxx' statement; see also profile parameter TTYPE in the Parameter Reference documentation and terminal command %T= in the Terminal Command documentation.

Handling Output of an Asynchronous Natural Session

As an asynchronous session is a session that is not associated with any terminal, this means that any output produced by the session cannot simply be displayed on the screen; instead, you have to explicitly specify an output destination. You specify this destination with the Natural profile parameter SENDER when invoking Natural. The SENDER destination applies to hardcopy output and primary reports; any additional reports are sent to the destinations specified with the DEFINE PRINTER statement, just as in a synchronous online session.

As an asynchronous session can also cause a Natural error, the destination to which any Natural error message is to be sent must also be specified; this is done with the Natural profile parameter OUTDEST. This parameter also provides an option to have error messages sent to the operator console. After an error message has been sent, Natural terminates the asynchronous session.

The profile parameters SENDER and OUTDEST should be set accordingly to be prepared for unexpected output by the asynchronous Natural session; otherwise, the asynchronous Natural session may abend in such a scenario.

Handling Unexpected or Unwanted Input

An asynchronous Natural session only has the Natural stack to enter the name of Natural programs and Natural system commands to be executed. If a Natural program or a Natural system command fails with an unhandled Natural error or if the entire Natural stack is exhausted and NEXT mode would be entered, the asynchronous Natural session is terminated with termination message NAT9943.

Depending on the TP monitor in use and depending on the TTYPE setting, either the CLEAR key or the EOF indicator is passed back to Natural on an INPUT request by default. This measure helps to prevent error loop situations if a program unintentionally executes an INPUT statement. To pass the ENTER key indicator back, you can issue a SET CONTROL 'N' statement prior to the INPUT statement.

Tipp:
You can make your application compatible with asynchronous sessions by evaluating the system variable *SCREEN-IO accordingly.

Other Profile Parameter Considerations

The following Natural profile parameters should be considered in the case of an asynchronous Natural session:

Profile Parameter Comment
AUTO Asynchronous sessions may have non-alphabetical user IDs. In this case, AUTO=ON will fail.
CM An unwanted input situation may happen if the Natural session accidentally falls onto the NEXT level. Setting CM=OFF will terminate the session immediately in such a situation.
ENDMSG The error message NAT9995 (normal termination message) can be suppressed by specifying ENDMSG=OFF.
IMSG Natural initialization error messages and warnings can be suppressed by specifying IMSG=OFF.
MENU Asynchronous sessions only have the Natural stack for command inputs; therefore, it is recommended to specify MENU=OFF and to navigate through Natural by using direct commands.
PLOG Dynamic parameter logging is executed by sending all parameters line by line to the SENDER destination.
PROGRAM If a standard back-end program/transaction is defined in your installation, it should be checked if this program can run asynchronously or if it is desired to deal with terminal-bound sessions only. Specifying PROGRAM=0 bypasses the back-end logic.