This article discusses how to clone (copy) data flexibly using the MOVE_BLK_VARIANT instruction on an S7-1500 PLC in TIA Portal. The need to copy large amounts of data often arises, for example, copying a recipe from a master database to a working area, backing up parameters before they are changed, or moving some array elements to another position.
The ordinary MOVE_BLK instruction requires the source and destination type and address to be determined when the program is written. With MOVE_BLK_VARIANT, the source and destination are received as Variant, and the number of elements and their starting position can be variables determined while the program is running. As a result, one cloning block can be used for arrays of any data type.
This system is kept compact, namely one FB_Clone that wraps MOVE_BLK_VARIANT with a rising edge trigger and result reporting. The block is used in three cases: copying an entire Real array, copying part of a Real array to a different position, and copying an Int array with the same block. After the program is created, the article explains how the program works line by line, then testing is done with PLCSIM Advanced V5.0 on a virtual S7-1500 CPU.
Prerequisites
- The reader already understands how to create a PLC data type, Data Block, and array.
- The reader already understands how to create a Function Block using the SCL language and call it from OB1.
- The reader already knows how to run a virtual CPU with PLCSIM Advanced and create a Watch table.
MOVE_BLK_VARIANT Concept
MOVE_BLK_VARIANT copies a number of elements from a source area to a destination area. The SRC parameter is the source, and DEST is the destination, both of type Variant. COUNT determines the number of elements to copy, while SRC_INDEX and DEST_INDEX determine the position of the first element in the source and destination, counted from the first element of the array (starting from 0). This instruction returns a RET_VAL value of type Int. A value of 0 means the copy succeeded, and a value other than 0 indicates an error; for example, the element types are not the same or the number of elements exceeds the array size.
There are two important rules. First, the element types of the source and destination must be exactly the same. Copying a Real array to an Int array will be rejected, and copying an array of a PLC data type can only be done to an array with the same PLC data type. Second, the copied area must not cross the array boundary, either in the source or in the destination. As in the previous Variant article, a Variant parameter can only be declared as Input, InOut, or Temp, so a generic block receives data areas through Input or InOut parameters.
The main advantage of MOVE_BLK_VARIANT compared to MOVE_BLK is flexibility. A block that uses it does not need to know the data type when it is created, and the number of elements and the indexes can be sent as parameters. This allows one cloning block to be used by many parts of the program, so the copying logic is not written repeatedly.
Flexible Data Cloning in S7-1500 Tutorial
Step 1: Creating the Test Data Block
- Create a Global Data Block DB_Test (optimized) with the following variables.
- Real arrays: Master_R and Work_R, each of type Array[0..4] of Real.
- Int arrays: Master_I and Work_I, each of type Array[0..4] of Int.
- Control: Exec1 to Exec3 (Bool), Done1 to Done3 (Bool), and Status1 to Status3 (Int).
Step 2: Creating FB_Clone
- In the Project Tree, open PLC_1 > Program blocks > Add new block, select Function block (FB), name it FB_Clone, language SCL.
- Fill in the block interface as follows.
- Input: Execute (Bool), Source (Variant), Src_Index and Dest_Index (DInt), Count (UDInt).
- InOut: Dest (Variant).
- Output: Done (Bool), Status (Int).
- Static: rtExec (R_TRIG).
- Write the following SCL program:
// Detect the rising edge of Execute
#rtExec(CLK := #Execute);
IF #rtExec.Q THEN
// Copy Count elements from Source to Dest (Status = 0 means success)
#Status := MOVE_BLK_VARIANT(SRC := #Source,
COUNT := #Count,
SRC_INDEX := #Src_Index,
DEST_INDEX := #Dest_Index,
DEST => #Dest);
#Done := (#Status = 0);
END_IF;
// Clear the result flag when Execute is released
IF NOT #Execute THEN
#Done := FALSE;
END_IF;
How does FB_Clone work?
This block only copies once every time Execute changes from FALSE to TRUE. The first line calls rtExec (R_TRIG), which detects that change, and rtExec.Q is TRUE for only one cycle. As long as Execute is left TRUE, the block does not copy again, so the CPU does not copy data on every scan cycle.
When the edge is detected, MOVE_BLK_VARIANT takes Count elements from Source starting at position Src_Index, then places them in Dest starting at position Dest_Index. Its return value is stored in Status. If Status equals 0, the copy succeeded, and Done becomes TRUE. When Execute is released to FALSE, Done is cleared so the block is ready for the next copy.
Why use Variant?
Source and Dest are of type Variant, so FB_Clone does not need to know the data type. When called, TIA Portal passes the address and type information of the paired variable, and MOVE_BLK_VARIANT checks that the element types of the source and destination are the same. Because of that, the same block can copy both Real arrays and Int arrays.

Step 3: Calling FB_Clone in OB1
- In OB1 (SCL), drag FB_Clone into the editor and give a different instance DB name for each call: Clone_All, Clone_Part, and Clone_Int.
- Write the following program, then compile PLC_1 and make sure there are no errors.
// Case 1: clone all 5 Real elements (index 0 to index 0)
"Clone_All"(Execute := "DB_Test".Exec1,
Source := "DB_Test".Master_R,
Src_Index := 0, Dest_Index := 0, Count := 5,
Dest := "DB_Test".Work_R,
Done => "DB_Test".Done1, Status => "DB_Test".Status1);
// Case 2: clone only 2 elements, from source index 2 to destination index 3
"Clone_Part"(Execute := "DB_Test".Exec2,
Source := "DB_Test".Master_R,
Src_Index := 2, Dest_Index := 3, Count := 2,
Dest := "DB_Test".Work_R,
Done => "DB_Test".Done2, Status => "DB_Test".Status2);
// Case 3: same block, different data type (Int array)
"Clone_Int"(Execute := "DB_Test".Exec3,
Source := "DB_Test".Master_I,
Src_Index := 0, Dest_Index := 0, Count := 5,
Dest := "DB_Test".Work_I,
Done => "DB_Test".Done3, Status => "DB_Test".Status3);
How do the calls in OB1 work?
Each call has its own instance DB, so rtExec and Done of each call are separate. Clone_All copies five elements from index 0 of the source to index 0 of the destination, so Work_R becomes a full copy of Master_R. Clone_Part copies two elements starting from index 2 of the source to index 3 of the destination, so Work_R[3] contains Master_R[2] and Work_R[4] contains Master_R[3], while Work_R[0] to [2] do not change. Clone_Int uses the same FB_Clone for the Int array without any change to the block.

Step 4: Running the Virtual CPU
- Open PLCSIM Advanced, select PLCSIM Virtual Eth. Adapter, create an S7-1500 instance with an IP matching the CPU in the project, then Start. Make sure Support simulation during block compilation is checked in the project properties.
- Download to the virtual CPU, run the CPU, then Go online.
Siemens PLCSIM Test
Step 1: Preparing the Watch Table
- Create a Watch table containing all DB_Test variables, then click Monitor all.
Step 2: Testing Cloning of the Entire Array
- Fill Master_R[0] to [4] with 1.0, 2.0, 3.0, 4.0, 5.0 via Modify now.
- Change Exec1 to TRUE. Expected result: Done1 = TRUE, Status1 = 0, and Work_R[0..4] contains 1.0 to 5.0.
- Change Exec1 back to FALSE.

Step 3: Testing Partial Cloning
- Change Master_R[2] to 22.0 and Master_R[3] to 33.0.
- Change Exec2 to TRUE. Expected result: Done2 = TRUE, Status2 = 0, Work_R[3] = 22.0, and Work_R[4] = 33.0.
- Work_R[0..2] do not change (remain 1.0, 2.0, 3.0).
- Change Exec2 back to FALSE.

Step 4: Testing Another Data Type
- Fill Master_I[0] to [4] with 10, 20, 30, 40, 50.
- Change Exec3 to TRUE. Expected result: Done3 = TRUE, Status3 = 0, and Work_I[0..4] contains 10 to 50.
- Change Exec3 back to FALSE.
