Data flow

The data flow for the UNSTRING statement is based on certain rules.

When the UNSTRING statement is initiated, data is transferred from the sending field to the current data receiving field, according to the following rules:

  1. Examine
    • If the POINTER phrase is specified, the field is examined, beginning at the relative character position specified by the value in the pointer field.

      If the POINTER phrase is not specified, the sending field character-string is examined, beginning with the leftmost character position.

    • If the DELIMITED BY phrase is specified, the examination proceeds from left to right, examining character positions one-by-one until a delimiter is encountered. If the end of the sending field is reached before a delimiter is found, the examination ends with the last character position in the sending field. If there are more receiving fields, the next one is selected; otherwise, an overflow condition occurs.

      If the DELIMITED BY phrase is not specified, the number of character positions examined is equal to the size of the current data receiving field, as described in the table below. The size depends on the category treatment of the receiving field, as shown in Table 1.

      If the DELIMITED BY phrase is not specified and the receiver is a dynamic-length elementary item, the number of character positions examined is equal to the length of the sender. All identifiers cannot be dynamic-length group items.

      Table 1. Character positions examined when DELIMITED BY is not specified
      If the receiving field is ... The number of character positions examined is ...
      Alphanumeric or alphabetic Equal to the number of alphanumeric character positions in the current receiving field
      DBCS Equal to the number of DBCS character positions in the current receiving field
      National Equal to the number of national character positions in the current receiving field
      Numeric Equal to the number of character positions in the integer portion of the current receiving field
      UTF-8 Equal to the number of UTF-8 character positions in the current receiving field
      Described with the SIGN IS SEPARATE clause 1 less than the size of the current receiving field
      Described as a variable-length data item Determined by the size of the current receiving field at the beginning of the UNSTRING operation
  2. Move
    • The examined character positions (excluding any delimiter characters) are treated as an elementary data item of the same data category as the sending field except for the cases shown in the table below.

      Category of identifier-1 (sending-field) Category of elementary data item
      Alphanumeric-edited Alphanumeric
      National-edited National
      That elementary data item is moved to the current data receiving field according to the rules for the MOVE statement for the categories of the sending and receiving fields as described in MOVE statement.
    • If the DELIMITER IN phrase is specified, the delimiting characters in the sending field are treated as an elementary alphanumeric item and are moved to the current delimiter receiving field, according to the rules for the MOVE statement. If the delimiting condition is the end of the sending field, the current delimiter receiving field is filled with spaces.
    • If the COUNT IN phrase is specified, a value equal to the number of examined character positions (excluding any delimiters) is moved into the data count field, according to the rules for an elementary move.
  3. Successive iterations
    • If the DELIMITED BY phrase is specified, the sending field is further examined, beginning with the first character position to the right of the delimiter.

      If the DELIMITED BY phrase is not specified, the sending field is further examined, beginning with the first character position to the right of the last character position examined.

    • For each succeeding data receiving field, this process of examining and moving is repeated until either of the following conditions occurs:
      • All the characters in the sending field have been transferred.
      • There are no more unfilled data receiving fields.