Entry type: FAQ, Entry ID: 51783575, Entry date: 08/29/2011
(0)
Rate

What properties do you have to watch out for in STEP 7 V11 when you are inserting characters into a string with the "INSERT" statement?

  • Entry
  • Associated product(s)

Description
You use the "INSERT" statement to insert characters or character strings at input parameter "IN2" into the character string at input parameter "IN1". The results character string is displayed at the "OUT" output parameter in string format. You have to specify a value at parameter "P" to indicate the position of the character in the string from which you wish to insert the characters.


Fig. 01

You must watch out for the following conditions during the parameterization of the "INSERT" statement.

  • If the value at parameter "P" is greater than the character string at input parameter "IN1", the characters of input parameter "IN2" are appended after the last character of the character string of input parameter "IN1".


Fig. 02

  • If the value at parameter "P" is zero, the characters of the input parameter "IN2" are placed before the first character of the input parameter "IN1".


Fig. 03

  • If there is a negative value at parameter "P", a blank character string is also displayed at the "OUT" output parameter.


Fig. 04

  • If the results string is longer than the length of the string variable defined at the "OUT" output parameter, the string is limited to the available length.


Fig. 05

Example
You can also use the "INSERT" statement to copy string variables. Fig. 06 illustrates an example for transferring a five-character string in which one of the characters changes ("abcde" => "abxde").

  • Adapt the length of the string variable precisely to the length of the character string which you wish to transfer (for example, String[5]).
  • The character string at parameter "IN2" must be identical to the character string at parameter "IN1".
    • Delete the first character in the string at parameter "IN2" and
    • Change the character that you wish to exchange for the character string to be transferred (for example, "x").


Fig. 06

With the definition "P=1", the character string at parameter "IN2" is inserted behind the first character of the string at parameter "IN1", which would give the string the pattern "abxdebcde". However, as the string at the "OUT" parameter is defined as five characters in length, the string is limited to "abxde".


Fig. 07

Note
You can enter the character strings in the SIMATIC S7-1200 directly at the inputs "IN1" and "IN2" of the "INSERT" function. In the SIMATIC S7-300, you must parameterize the inputs with DB variables of the String data type.