×
Siemens Industry Online Support
Siemens AG
Entry type: FAQ Entry ID: 837001, Entry date: 07/19/2010
(20)
Rate

What is the significance of the initial and actual values of a data block?

  • Entry
  • Associated product(s)

Description
The name for variables, the data type, a commentary and an initial value are configured in the declaration table for a data block. This initial value is a pure configuration variable which is applied as an actual value when generating a data block on the basis of a UDT (user-defined data type) or in a declaration for a new variable in a global data block. The actual values become visible via the menu commands "View > Data view".

The initial value is only configured once for a data block or for a newly declared variable data block. If the variable already exists, the actual value is unaffected by any change in the initial value. The only value of significance to the CPU is the value in the column headed "Actual value". Even if the initial value is also loaded onto the CPU and can be monitored there in online mode, this value is not used by the CPU.

You have two options for starting your CPU with a new value:

  1. Switch to the data view and enter your new initial value in the "Actual value" column.
  2. Go to the declaration view and enter your new initial value in the "Initial value" column. Then switch to the data view. You can then transfer all the values from the "Initial value" column to the "Actual value" column via the menu command "Edit > Initialize Data Block".

Then load the data block into the CPU.

Since the initial value does not continue to use the initial values, there is no need to perform the opposite procedure, i.e. to load the values from the "Actual value" column to the "Initial value" column. There is no menu command for this either in STEP 7. The following instructions are used in some uncommon configurations for saving the actual values of a data block as initial values. This procedure can either be conducted directly within an STL source or by saving the values with Excel.

Saving the actual values of a data block as initial values directly in the STL source
Once the STL source has been generated, the actual values can be copied line-by-line into the declaration lines in the STL source.
 

No. Procedure
1 Select the online view in the SIMATIC Manager via "View > Online" and open the data block within the online view. Save the data block either by clicking the floppy disk button or via "File > Save".
2 Create a source for the data block via "File > Generate Source...".
3 Open the source, which you have generated, in the source folder in the SIMATIC Manager.
4 In the STL source, copy the actual values, which are positioned between "BEGIN" and "END_DATA_BLOCK", line-by-line into the corresponding declaration lines (initial values) after the corresponding data types.


Fig. 01

As Fig. 01 shows, you have to copy the actual values with the assignments ":=" into the declaration lines of the initial values. As a result, the declaration lines are defined as shown in the example below:

  • Data_1 : BYTE := B#16#AA;
5 Save and compile the STL source via
  • File > Save
  • File > Compile

The actual values are then applied as initial values.

Saving the actual values of a data block as initial values with Excel (the convenient way)
The actual values of a data block can also be saved in Excel as initial values. This option is particularly advisable for large data blocks because the data is copied into the declaration lines in a block here, not line-by-line. The table below explains what you need to watch out for when importing and exporting the STL source and when saving in Excel.
 

No. Procedure
1 Select the online view in the SIMATIC Manager via "View > Online" and open the data block within the online view. Save the data block either by clicking the floppy disk button or via "File > Save".
2 Create a source for the data block via "File > Generate Source...".
3 Mark the generated source in the source in the SIMATIC Manager and right-click it. Then select the "Export Source..." command in the pop-up menu.
4 Select "STL source (*.awl)" as the file type in the "Export source" dialog box, as well as the folder where the source is to be exported. The file name must contain the file extension ".AWL", e.g. "Source_DB2.AWL". Then click the "Save" button.


Fig. 02

5 Start Microsoft Excel and open the exported STL source via "File > Open...". The "Text-import Wizard" dialog opens.

Note
You have to select "All files (*.*)" as the file type in order to ensure that the STL source is visible in the "Open" dialog box.

6 In step one of the text-import wizard, enable the "Delimited" formatting option.


Fig. 03

Then click on the "Next" button.

7 In the next dialog box of the text-import wizard, select "tab" or "space" as the delimiter.


Fig. 04

Then click on the "Next" button.

8 In the third step of the text-import wizard, select "standard" as the data format for the columns.


Fig. 05

Then click on the "Finish" button. The converted STL source is now opened in Excel.

9 Select all the cells belonging to the STL source in Microsoft Excel and right-click. Then select the "Format Cells..." command in the pop-up menu.


Fig. 06

10 Select "Right" or "Right (Indent)" as the horizontal text alignment in the dialog box "Format Cells > Alignment" and click OK to confirm.


Fig. 07

11 Now select the actual values between "BEGIN" and "END_DATA_BLOCK", including the assignments ":=", and copy the data into the declaration lines between "STRUCT" and "END_STRUCT" after the corresponding data types, as shown in Fig. 08.


Fig. 08

12 Then check whether the syntax agrees after copying the actual values into the lines for the initial values. Example:
STRUCT
  Data_1 : BYTE := B#16#AA;
  ...
END_STRUCT;


Fig. 09

13 Save the file in Excel via "File > Save as..." and select
  • Formatted Text (Space delimited)(*.prn) as the file type.

Note
Once you have saved the file as described above, you receive the file, e.g. "Source_DB2.AWL". However, if you save the file under another name, such as "Source_DB20.AWL", the file "Source_DB20.AWL.PRN" will be stored on your system. This file then has to be renamed from "Source_DB20.AWL.PRN" to "Source_DB20.AWL" (delete the extension PRN). The extension "PRN" has been added by the system in cases where the file name ending "AWL", which is being saved, has already been entered once.

14 Import the STL source, which you processed in Excel, into the source folder for your STEP 7 project in the SIMATIC Manager via "Import > External Source...".
15 Mark the imported STL source in the source folder and right-click. Then select the "Compile..." command in the pop-up menu. The actual values are saved as initial values following compilation.


Fig. 10

Note
If you use UDTs in your data block, there is a restriction here. You cannot attach the actual values to the variables as initial values. While the UDTs can be exported, any change in the initial value of the UDT affects all (!) the places where the UDTs are used equally. Distinctions cannot be made between the places where it is used.

Keywords
Programming help, Initialization, Initial values, System behavior
 

Security information
In order to protect technical infrastructures, systems, machines and networks against cyber threats, it is necessary to implement – and continuously maintain – a holistic, state-of-the-art IT security concept. Siemens’ products and solutions constitute one element of such a concept. For more information about cyber security, please visit
https://www.siemens.com/cybersecurity#Ouraspiration.