Problem: Stacked WORD_TO_INT / INT_TO_REAL Fails to Compile
In TIA Portal SCL, converting a WORD from a data block to a REAL works when an intermediate INT tag is used, but the equivalent single-line stacked expression fails to compile. The source pattern is a WORD-typed DB element ("WordFromWS".M32001) that must end up scaled in a REAL-typed DB element ("WSSCaled".R32001).
The failing expression is not a limitation of the conversion functions — the failure is a parenthesis placement error. In the non-compiling version, the + 0 term was placed inside the WORD_TO_INT argument list, so the compiler sees an attempt to add an integer to a WORD before the conversion ever runs:
// Does NOT compile: +0 is inside WORD_TO_INT(...)
"WSSCaled".R32001 := (INT_TO_REAL(WORD_TO_INT("WordFromWS".M32001 + 0)))/1;
Corrected Syntax
Close the WORD_TO_INT call immediately after the WORD operand, then apply any arithmetic to the resulting INT. The working form from the source is:
"WSSCaled".R32001 := (INT_TO_REAL(WORD_TO_INT("WordFromWS".M32001) + 0))/1;
Note the behavioral difference between the two forms once the parenthesis moves: the two-step INT pass-through version adds +0 after the INT conversion (INT_TO_REAL("IntPass".I32001 + 0)), which is valid because both operands are INT. The broken one-liner tried to add 0 to the raw WORD inside the function argument, which the compiler rejects. When stacking conversion functions in SCL, verify that every arithmetic operator sits outside the innermost conversion and operates on the converted type.
Avoiding the Intermediate DB
An intermediate global DB of type INT works but permanently consumes DB memory for a value that is only a conversion pass-through. If you prefer the two-step style for readability or debugging (it lets you monitor the INT value online), use a temporary INT variable declared in the block's Temp area instead of a global DB element. The temp variable exists only for the block's scan, so no static memory is wasted, and the conversion chain remains easy to step through in the editor.
FAQ
Why won't my nested WORD_TO_INT / INT_TO_REAL expression compile in TIA Portal SCL?
Check parenthesis placement: arithmetic such as + 0 must be applied after WORD_TO_INT closes, not inside its argument list. Use INT_TO_REAL(WORD_TO_INT("WordFromWS".M32001) + 0) instead of placing the + 0 on the WORD operand.
How do I convert a WORD to a REAL in Siemens SCL?
Chain the two conversion functions: INT_TO_REAL(WORD_TO_INT(wordTag)) and assign the result to a REAL tag. There is no single-step WORD-to-REAL conversion in the pattern shown; the INT stage is required.
Should I use a global DB or a temp variable as an INT pass-through in SCL?
Use a temporary INT variable declared in the block's Temp area. A global DB element consumes static memory permanently for a value that only exists to feed the next conversion, while the temp variable is scratch memory valid for the current scan.