Hi Torben59
I would do that with interrupts. Interrupts monitor the state of (your) pre-defined inputs and they are not synchronized to a specific code position. As soon as the monitored digital input is in a certain state (for example HIGH), the program pointer jumps to a so called trap routine.
So, what to do in the RAPID code?
1. create (define) an interrupt identity intnum
VAR intnum error;
2. Connect this interrupt with your trap routine
PROC main()
CONNECT error WITH alarm_trap;
3. Define input and its state you want to monitor
ISignalDI di1, high, error;
4. Write your trap routine -> behavior if the signal (error) occurs
TRAP alarm_trap
!do something
ENDTRAP
I got most of the information out of ABB's manuals: Technical reference manual - RAPID overview & Technical reference manual - RAPID Instructions, Functions and Data types.