String Assignment

A string assignment assigns the string that results from evaluation of the string expression on the right side of the assignment operator (:=) to the string target on the left side.

<string assignment>

──┬─<string designator>───────────────┬─ := ───────────────────────────►
  └─<string-valued library attribute>─┘
►─┬───────────────────────────────┬────────────────────────────────────►
  │ ┌◄──────────────────────────┐ │
  └─┴─<string designator>── := ─┴─┘
►─┬──────────────────────────────────────┬─<string expression>─┬───────┤
  ├─ * ──<string concatenation operator>─┘                     │
  └─<string-valued library attribute>──────────────────────────┘

<string designator>

──┬─<string identifier>────────────────────────────────┬───────────────┤
  │                                ┌◄───── , ────┐     │
  ├─<string array identifier>── [ ─┴─<subscript>─┴─ ] ─┤
  └─<string procedure identifier>──────────────────────┘

The result of the expression on the right side of the assignment operator (:=) must be a string of the same character type as the declared type of the string designator on the left side.

Embedded assignment is not allowed. For example, the following is not allowed:

S1 := DROP(S2 := "ABC", 2)

Assignment can be made to a string procedure identifier only within the body of that string procedure.

String Concatenation Operator

The * <string concatenation operator> form is a shorthand form of assignment that can be used when the string designator on the left side of the assignment operator also appears in the expression on the right side of the operator. The asterisk (*) represents a duplication of the item to the left of the assignment operator.

For example, the following two assignments produce the same results:

S := * CAT "ABC"
S := S CAT "ABC"

Examples of String Assignments

The following example assigns the EBCDIC string ABCD123 to the string variable STRI.

STRI := 8"ABCD123"

The following example assigns the string 1234 (of the default character type) to both of the string variables S2 and S1.

S1 := S2 := "1234"

The following example concatenates the string INPUT onto the end of the string stored in SOUT1, and then assigns the result to both of the string variables SOUT1 and SOUT.

SOUT := SOUT1 := * CAT "INPUT"

The following example concatenates the string ABC onto the end of the string stored in SOUT, and this string is then concatenated onto the end of the string stored in SOUT. The resulting string is assigned to the string variable SOUT.

SOUT := * !! SOUT !! "ABC"