The UNSTRING verb is used to divide a string into sub-strings
The UNSTRING copies characters from the source string, to the destination strings,
until a delimiter encountered that terminates data transfer. When data transfer
ends for a particular destination string, the next destination string will become
the receiving area.
The following example shows how UNSTRING is used.
UNSTRING ‘firstname.lastname@example.org’ DELIMITED BY ‘@’ OR ‘.’
In this example unstrings the literal ‘email@example.com’ into different strings
WS-USER-ID, WS-COMPANY and WS-DOMAIN based on delimiters (i.e. ‘@’ and ‘.’).
Characters from source string (i.e. ‘firstname.lastname@example.org’) until delimiter ‘@’ will
be moved to WS-USER-ID, after that characters until delimiter ‘.’ will be moved to
WS-COMPANY, remaining characters in source string will be moved to WS-DOMAIN.
Delimiter - Character or set of characters in the source string that terminates
data transfer to a particular string. We can specify one or more
delimiters if anyone delimiter encountered in source string, the
data will be transferred to next destination string.
Hold-delimiter – Holds the delimiter that caused the termination of data transfer
to associated destination string.
Char-counter – Holds the no of characters transferred into associated destination
Pointer-integer – Points to the position in the source string from which the next
character will be taken.
Destination-counter – Holds the count of no of destination strings affected by
- If the DELIMITED BY phrase is not used, then DELIMITER IN and COUNT IN phrases
must not be specified.
- When the ALL phrase is used, contiguous delimiters are treated as one delimiter.
If the ALL is not used, contiguous delimiters will act as separate delimiters and
result in spaces being sent to some of the destination strings.
UNSTRING source-string DELIMITED BY ‘/’
Input: Source-string = “19/11/2010”
Output: Destination-string1 –> “19”
Destination-string2 -> “11”
Destination-String3 -> “2010”
Above UNSTRING example moves source data into destination delimited by / accordingly.
Example -2 :
UNSTRING source-string DELIMITED BY ‘/’ OR ‘#’ OR ALL SPACES
INTO destination-string1 DELIMITER IN hold-delimiter1 COUNT IN char-counter1
destination-string2 DELIMITER IN hold-delimiter2 COUNT IN char-counter2
destination-string3 DELIMITER IN hold-delimiter3 COUNT IN char-counter3
destination-string4 DELIMITER IN hold-delimiter4 COUNT IN char-counter4
WITH POINTER pointer-integer
TALLYING IN destination-count
ON OVERFLOW DISPLAY “Overflow occurred”
NOT ON OVERFLOW DISPLAY “No overflow”
Input: Source-string = “+TODAYSDATEIS 19//11-2010”
Pointer-integer = 02
Output: Once the above statement executed destination variables hold these values.
Destination-string1 -> “TODAYSDATEIS”
Destination-string2 -> "19”
Destination-string3 -> (Spaces)
Destination-string4 -> "11-2010”
Unstring will start from position 2 in source-string because of value in
WITH POINTER option.