$batch

Return the batch mode indicator.

Return = $batch

set | reset  $batch

Return Values

Value

Meaning

1

Uniface is running in batch mode, or the Uniface Server is executing the component.

0

The application is interactive.

<0

An error occurred. $procerror contains the exact error.

Use

Allowed in all component types.

Description

$batch is set to 1 by Uniface when it is started with the /bat command (uniface.exe /bat), and by the Uniface Server (userver.exe). Thus, remote services and dynamic and static server pages are always executed in batch mode. (If you want to check whether a service is running in a web application, use $web.)

Caution: Anything which requires keyboard input or screen output (an askmess or edit statement, for example) cannot be used in batch mode. Attempting to do this may crash the application.

It can therefore be useful to test whether Uniface is operating in batch mode. For example, if a Form is designed for both reports (batch mode printing) and interactive use, you need to be able to test whether Uniface is printing in batch mode before using certain ProcScript. In these situations, you can use the following construction to execute the statements that are for interactive use only:

if (!$batch) ;running interactively
...
endif

Note: The putmess statement in batch mode writes the message directly to the terminal or batch log file, depending on your operating system settings.

Changing the Value of $batch

You can use $batch as the target in the left-hand side of an assignment, for example:

$batch=!$batch

Since $batch is essentially a Boolean function, when Expression evaluates to a non-zero value, $batch becomes 1.

3GL and $batch

The Uniface 3GL function UNIFBEG sets the value of $batch. When UNIFBEG starts an interactive session, $batch is set to 0; when UNIFBEG starts a batch session, $batch is set to 1. For more information, see unifbeg.

Using $batch

The ProcScript in the following example first checks whether the application is running in batch mode. If it is, a message is written to the message frame to record the number of pages just printed. If the application is not running in batch mode, the user is asked if they want to leave the application or return to the main menu.

if ($batch = 1)
   putmess "%%$page pages sent to printer at %%$clock"
   exit(0)
else
   askmess "Return to Main menu or Quit? (M/Q)","M,Q"
   if ($status = 1)
      exit "mainmenu"
   else
      apexit
   endif
endif

Related Topics