In SCL every variable is declared in a section that decides where it lives. Input, Output, InOut and Static variables of an FB are stored in its instance DB and keep their values between calls; Temp variables exist only while the block runs; Constants are compiled into the code. The CPU keeps the project in load memory (memory card), runs it from work memory, and keeps Retain values in retentive memory through a power cycle.
- Static = the block's memory (instance DB); Temp = scratch space for one call; Constant = no runtime memory
- Mark only values that must survive a power cycle as Retain; everything else returns to its start value
- Convert explicitly (NORM_X, SCALE_X, TRUNC, ROUND), read bits with slices like
#ZSW1.%X2, and loop over arrays with FOR
Part 3 showed addresses and data types from the PLC tag table. This part looks at the same data the way an SCL programmer does: as declarations inside blocks. Every tool below uses the conveyor project: FB_PRB from Part 4, the G120 drive from Part 2 and the Motor_UDT array from Part 3.
SCL Declaration Sections: Input, Output, InOut, Static, Temp, Constant
The section you declare a variable in decides where it is stored and whether it survives the next scan.
Reference: declaration sections in an FB and an FC
| Section | FB | FC |
|---|---|---|
| VAR_INPUT / VAR_OUTPUT | Stored in the instance DB | Parameters of the call, no instance DB |
| VAR_IN_OUT | Copy (elementary) or reference (structured) | Passed from the caller |
| VAR (Static) | Instance DB, kept between calls | Not available |
| VAR_TEMP | Local data stack, only during the call | Local data stack, only during the call |
| VAR CONSTANT | Compiled into the code | Compiled into the code |
PLC Memory: Load Memory, Work Memory and Retentive Memory
The project sits on the memory card; the CPU runs it from work memory; only values marked Retain survive a power cycle.
| DB_PRB_1 member | Type | Start value | Actual value | Retain column |
|---|
In an optimized FB you set retentivity per variable in the interface's Retain column (Non-retain, Retain or Set in IDB). Keep the list short: retentive memory is much smaller than work memory.
Want to write SCL on a real S7-1500?
Live SCL sessions: declarations, UDTs, arrays, loops and FB design on real hardware. Pune classroom or online.