Siemens S7 program to shift data block areas


Thread Starter


Siemens S7 315-2DP CPU

My application requires me to move a block area of data in a data block to other data areas to keep track of the product information. Is there a standard function block which I may utilize to implement a block shift register?
Or what would be the simplest method of implementing this?

The application is for the tracking of the Tare, net, gross weights and error code (if any) of the product during the a filling process. I need to transfer the information on the first product to the next filling station, etc.
Hi Luiz,


1. create a UDT (e.g. UDT 1) and declare the item's data to be tracked (e.g. ItemCode, tare, net, gross weights and error code).

2. create a Datablock and declare a variable "Station" as array[1..n] of UDT1. First array item in datablock will represent station #1, second station #2 and so on. In this way you obtain a "map" of items at each station: Station[1], Station[2] etc
Assign symbolic name to the datablocks (e.g. "StorageDB31")

3. use SFC20 (blk_move) to move data from a storage location to another. Be aware that SFC20 does not modify the data in source location.
call sfc 20
source: "StorageDB31".Station[1]
destination : "StorageDB31".Station[2]

if your data must be allocated across datablocks, specify each DB in the SFC20 call:
call sfc 20
source: "StorageDB31".Station[1]
destination : "StorageDB44".Station[99]

4. once you moved the data, instead of completely erasing the source location contents, you may invalid the location data by changing the sign of the ItemCode field . Assuming that ItemCode is a 16-bit Integer, do:

L "StorageDB31".Station[1].ItemCode
T "StorageDB31".Station[1].ItemCode

This technique will allow you to mark a location as "empty", still knowing what was its previous contents (pretty useful during commissioning and debugging)

I wrote the above instruction in a rush, please refer to Step7 online help (or manual) for details on SFC20 call


Luca Gallina
“SFC 20” (named Block Move - BLK_MOV) can move data. You will need to make your source and destination pointers (in ANY format) and call the block.

A different solution (still involving data transfer) is to use SCL programming language (LAD and STL are the most known, but SCL is very useful for data transfers). If your data is already structured (ex all the information you want to move are in an UDT or ARRAY) you will need to write only one line of code!!! (in SCL) But my question is: Why do you want to transfer the data from one place to another?

I did few tracking programs (for packages moving on complex conveyor lines / sorting systems) and never moved the data. I always had only one DB storing all the information about packages (in my case: barcode, weight, length, status, errors, etc.)

Directions: create an UDT containing all the data you need for the product. Add one more field (in the UDT) for the “station number”. Then, create a DB as an ARRAY of the previously created UDT. If your line has 20 stations with one product per station, have at least 25 elements in your ARRAY.

Now, each product will have an ID representing the element number of the ARRAY (where the data for this product is stored). Ex: your first product entering the filling line will have ID=1, meaning all the data for this product will be stored in element 1 of the ARRAY. Since this product is on station one, you will have to write 1 in the “station number” field (of the element 1 of the ARRAY). When this product will move to station 2 the only thing you have to do is writing 2 in the “station number” field. Product 2 entering the line will have assigned element 2 of the ARRAY (ID=2) and so on. Once a product reaches the end of the line you send all the data accumulated to a data base and clear the location ID (corresponding element of the ARRAY). You assign the IDs from 1 to the last element of the ARRAY (25 in my example) and then back to 1.

Practical considerations (that I thought about after writing above explanation): if your line is “extremely” simple (ex: 5 stations, never branching based on check conditions, you never pull out products in the middle of the line, no waiting positions in between stations) it is probably easier to go with data transfer. I still suggest keeping this data for all products in one DB using an ARRAY / UDT organization (with one element of the ARRAY for each station). A change in the data structure will affect one DB and no “instance DBs”.

Send me an email at [email protected] for more details / clarifications.


Dobrowolski, Jacek

Hi Luiz,

I think SFC20 "BLKMOV" could be much of help in your case. Using it in a loop while incrementing source and destination ANY pointers would do exactly what you need.


Jacek Dobrowolski