SA0004: Multiple write access on outputPermalink

Detects outputs that are written to more than one location

Justification: The maintainability is degraded when an output is written in different locations in the code. Then it is uncertain which write access is the one that actually has an effect in the process. Good practice is to calculate the output variables in auxiliary variables and assign the calculated value at one location at the end of the cycle.

Importance: High

PLCopen rule: CP12

An error is not issued when an output variable (‎VAR_IN_OUT‎) is written in different branches of ‎IF‎ and ‎CASE‎ statements.

A pragma cannot deactivate this rule.

Example

VAR_GLOBAL
	g_xVar AT %QX0.0 : BOOL ; 
	g_iTest AT %QW0 : INT ;
END_VAR

PROGRAM PLC_PRG
IF g_iCondition < INT#0 THEN
	g_xVar := TRUE;
	g_iTest := INT#12;
END_IF

CASE g_iCondition OF
	INT#1:
		g_xVar := FALSE;
	INT#2:
		g_iTest := INT#11;
	ELSE
		g_xVar := TRUE;
		g_iTest := INT#9;
END_CASE

--> SA0004: Multiple write access on output '%QX0.0'
--> SA0004: Multiple write access on output '%QW0'