Cookies are important for this site to function properly, to guarantee your safety, and to provide you with the best experience. By clicking OK, you accept all cookies. For more information, please access our Privacy Policy.
Table of Contents
Tutorials / 
Understanding and Using SCL Regions in TIA Portal
Advanced

Understanding and Using SCL Regions in TIA Portal

PLC Programming
Structured Control Language (SCL)
Siemens
TIA Portal

Introduction

You may need to structure your program code in regions when programming PLCs using an advanced language such as SCL. It helps you not only to enhance the clarity of your code but also enables you to troubleshoot your code more efficiently.

Prerequisites

What you will need to follow along with this tutorial are:

  • An installation of TIA Portal software on your computer. The TIA Portal version 16 will be utilized in this tutorial; however other TIA Portal versions are also acceptable.
  • An understanding of how to create an SCL block in the TIA Portal.
  • An understanding of SCL Elements.
  • An understanding of using SCL instructions

Utilizing regions

SCL allows you to organize your application code into regions. It makes your program more understandable since you may combine relevant elements of the program and can collapse and expand regions as required.

For quick navigation within the regions, a region overview is accessible. The region overview is shown adjacent to the program window and can be presented or concealed as desired. The region overview also displays the regions with syntax mistakes. It helps you to go to incorrect code spots rapidly and correct issues.

The programming window and the region overview are displayed in figure 1.1.

Figure 1.1: Displaying region overview and programming window

Include the keywords "REGION" and "END_REGION" around a program segment to summarize it for a region. The keywords notation can also be "region" and "end_region" or "Region" and "End_Region", depending on your preferences in the keyword highlighting. The keywords are automatically transformed into the notation that fits the present configuration.

Figure 1.2: Keywords notation for the region

Click either "REGION" or "END_REGION" to locate the "REGION" and "END_REGION" keywords that go together. As a consequence, both terms are highlighted in color.

Figure 1.3: Finding region keywords that belong together

It is possible to name each region (although it is optional to provide a name). It offers the following benefits:

  • When a region is collapsed, the name is still visible. It enables you to maintain your program code overview.
Figure 1.4: Collapsing a region while its name is still visible
  • You can recognize the regions in the region overview more readily and go to particular regions.
Figure 1.5: Recognizing regions in the region overview
  • The name can be translated into additional project languages if it is added as a multilingual comment. To accomplish so, use the character strings "(/* " and "*/)" to enclose the name. However, you may only add the name as a multilingual comment or as a name that cannot be translated. Keep the following in mind:
  • Combining real names and names used as multilingual comments is not allowed.
  • As a multilingual comment, the name cannot span several lines, and
  • Regions with a multilingual comment as a name can also be copied. If there are already translations for this, they are likewise used for the region's copy. If you modify the region's name, it will be modified in the editing language now in use.

To merge the program components into regions, use the following syntax:

REGION <Name> or (/*<Name as a multilingual comment>*/)

<Instructions>

END_REGION

When employing regions, keep the following details in mind:

  • The keywords "REGION" and "END_REGION" must appear at the beginning of a line.
  • Before the keywords, only spaces are permitted.
  • Any characters that follow the keyword "END_REGION" are regarded as comments and, as a result, have no impact on how the program is carried out.
  • Throughout a region, all instructions must be completed.
Figure 1.6: Tips for employing regions in the program code
  • Regions can be used to surround instructions within CASE statements. However, the constants used for CASE statement comparison must exist outside the regions. There cannot be several branches covered by the regions. The following example demonstrates the proper usage of regions within a CASE statement:

CASE <Expression> OF 

<Constant1> : REGION <Instructions1> END_REGION 

<Constant2> : REGION <Instructions2> END_REGION 

ELSE REGION <Instructions0> END_REGION 

END_CASE 

The following examples demonstrate the prohibited usage of regions within CASE statements:

CASE <Expression> OF

REGION <Constant1> : <Instructions1> END_REGION

<Constant2> : REGION <Instructions2> END_REGION

ELSE <Instructions0>

END_CASE

-----------------------------------------------------------------------

CASE <Expression> OF

<Constant1> : <Instructions1> REGION

<Constant2> : END_REGION <Instructions2>

ELSE <Instructions0>

END_CASE

In the above examples, constants within a region are treated as jump labels that may be reached with GOTO but are not considered by the CASE statements.

Additionally, you have the choice to nest regions. However, ensure that regions inside other regions are finished correctly.

Figure 1.7: Nesting Regions

Adding regions

You can add regions to your program code in the following ways:

  • You may manually insert regions using the keyboard.
  • Through the "Instructions" task card, you may insert regions. You may either enter blank regions or enclose the current program code in regions.

Manually adding regions with the keyboard

Follow these methods to manually insert a region into your application code using the keyboard:

  1. Set the cursor where you wish to insert a region.
  2. Type the word "REGION" here.
  3. Enter the region's name as a standard name or multilingual comment. It is an optional step.
  4. Set the cursor to the region's end.
  5. Type the word "END_REGION" here.
Figure 3.1: Adding regions using the keyboard

As a result, the related program code is integrated into a region that you may expand and collapse. The region overview includes the new region. If you haven't given your region a name, it will be labeled "Unnamed" in the region overview.

Figure 3.2: Optional step of giving a name to a region

Adding regions using the "Instructions" task card

Follow these steps to add a region to your application code using the "Instructions" task card:

  1. Set the cursor where you wish to add an empty region or choose the program code you want to enclose in a region.
  2. Open the task card labeled "Instructions."
  3. Go to "Program control operations > REGION".
  4. Drag the REGION to the location in your application code where you wish to introduce a region, or double-click to insert the REGION directive.
Figure 4.1: Adding regions through Instructions task card

As a result, an empty region or a region enclosing the chosen program code is added. The placeholder "_name_" is used to name the new region, shown in the region overview.

  1. The desired name can be substituted for the placeholder "_name_," either as a standard or as a multilingual comment. If you do not wish to provide a name, remove the placeholder.
Figure 4.2: Providing a normal name or a multilingual comment as a region name

Region Navigation

The region overview can help you browse quickly through the regions. Every region present in your application code is shown in the region overview. Additionally, it performs the following duties:

  • Synchronizing the presentation of the regions in the programming window and the region overview: The programming window, the region overview, or both may be affected by expanding and collapsing regions, depending on the chosen settings. Follow these steps to specify the synchronization:
  • Get the region overview open.
  • To enable and disable display synchronization, click "Synchronization on/off" in the region overview toolbar. The synchronization button is marked as active and inactive, respectively.
Figure 5.1: Activating and deactivating the synchronization button
  • Individual region expansion and collapse: Individual regions can be expanded and collapsed in the programming window or the region overview. If synchronization is enabled, the region expands or collapses in both windows. To expand or collapse a specific region, perform the following steps:
  • Navigate to the region overview.
  • Select your desired region and then to expand or collapse, use the keyboard shortcuts <Ctrl+Shift+Num+> and <Ctrl+Shift+Num->, respectively.
Figure 5.2: Expanding and collapsing an individual region - The first method

Another option is in the region overview, right-click over your desired region that you want to expand or collapse and choose "Expand" or "Collapse" from the pop-up menu to expand or collapse the targeted region, respectively.

Figure 5.3: Expanding and collapsing an individual region - The second method
  • All regions' expansion and collapse: In the region overview or the programming window, you may expand or collapse all regions at once. To do so, take the following procedures:
  • Put the mouse pointer in the programming window.
  • To expand or collapse all regions, use the keyboard shortcuts <Ctrl+Shift+Num*> and <Ctrl+Shift+Num/>, respectively.
Figure 5.4: Expanding and collapsing all regions - The first method

Or right-click over a region in the region overview and choose "Expand all regions" or "Collapse all regions" from the pop-up menu to expand or collapse all regions simultaneously, respectively.

Figure 5.5: Expanding and collapsing all regions - The second method

Conclusion

This tutorial discussed organizing your program code in regions. You learned how to use region overview for quick navigation within the regions, and it helps you to find the regions with syntax mistakes to solve the issue.

You learned how to use the "REGION" and "END_REGION" keywords to summarize your program code for a region. You also learned how to name each region and the benefits that come after this action.

You got familiar with the details when employing regions and how to nest regions inside another region. You understood how to add regions to your application code using the keyboard or through the "Instructions" task card.

Finally, you learned how to utilize region navigation to synchronize the presentation of the regions in the programming window and the region overview, and individual regions and all regions’ expansion and collapse.