Object Oriented Programming in Step 7


Thread Starter

Assaf Golan


Following a large project our company recently finished, I would like to ask what is the best method for object oriented programming.

We program based on S-88 standard.
We programed a unit (e.g. a reactor) using a FB with a single instance DB for eachof its instances.
Inside that FB we called other FBs as instances defined in the STAT of the units FB.

we had quite a few instances of exactly the same type of unit, so we used instances of the same FB class using different DBs for each instance, and entered the I/O in the INs/Outs of the units FB.

That way, any change, made to one of the FBs was included in all instances (exactly as object oriented programming should be...).

The problem occured when we wanted to add variables or simply alter the big instance DB's structure.
when downloading the SW to the PLC, all of the instance DBs Data was reset.

We found 2 alternatives for solving that problem:

1. using source generation to save the data of online DBs and insert it into the altered instance DB. This method turned to be very uncomfortable when you have dozens of DBs to change.

2. Adding "Spare" spaces in each of the FBs or UDTs used so the DBs structure won't change when adding new variables. Besides that, we created a mechanism that saved each of the DBs to a backup DB in runtime and once we changed the DB and downloaded it to the PLC, copying the backup DB back to the original so it will receive all of its data back. That is a good mechanism if you keep your DBs structure and not going out of the "spare" boundaries.

Both ways are bothersome and requires a lot of handling.

We used Siemens OPC so we were able to use symbolic addresses from the HMI.

Now I face a new big project with a few duplicated units and I wonder if there is a better way of using Step 7 to implement Object Oriented Programming without the hassle around the lost DB data.

I thought using an external DB (and not an instance DB) would be nice, but it seems it is not possible to pass a udt from one function's in/out to another.

Can someone share the best way to implement object oriented programming in step 7?

Thanks in advance,

Luca Gallina

a pity nobody answered this interesting post.
And a pity these weeks I'm too busy to write a detailed reply.

A few, brief words:
The techniques you used are ok. Modular complex functions based on FB + instance DBs are the way. Drawbacks are exactly what you pin pointed but there are no easy or quick solutions.
A mix of instance and shared DBs could be a way to solve some problems, but in the case structures and pointers handling might become hard stuff.

And yes, you cannot pass UDT-based structures from one block to another (parameters in that case are ByReference and not ByValue), maybe some SCL code could be more useful than plain STL.

I wished to have more time to spend on this subject, will try to write more as soon as this current commissioning rush of mine is over ;-)

Thanks for your reply Luca.
I wish to hear some more insights if you have the time to share.