skip to main content

Procedure Division Statements : UNSTRING

UNSTRING
General Format
UNSTRING Identifier-1
  [ DELIMITED BY [ALL] {Identifier-2} { [ OR [ALL] {Identifier-3} ] } ... ]
  INTO { Identifier-4 [ DELIMITER IN Identifier-5 ] [ COUNT IN Identifier-6 ] } ...
  [ WITH POINTER Pointer-Var-1 ] 
  [ TALLYING IN Identifier-7 ] 
  [ ON OVERFLOW Imperative-Statement-1 ] 
  [ NOT ON OVERFLOW Imperative-Statement-2 ] 
  [END-UNSTRING]
Syntax rules
1.
2.
3.
4.
Identifier-4 shall be described implicitly or explicitly as usage display and category alphabetic, alphanumeric, or numeric; or as usage national and category national or numeric. The -cm option removes this restriction. Numeric items shall not be specified with the symbol 'P' in their picture character-string.
5.
6.
7.
8.
9.
General rules
1.
2.
3.
4.
 
This value does not include a count of the delimiter character(s).
5.
6.
7.
 
When the ALL phrase is specified, one occurrence or two or more contiguous occurrences of literal-1 (figurative constant or not) or the content of the data item referenced by identifier-2 are treated as if they were only one occurrence, and one occurrence of literal-1 or the data item referenced by identifier-2 is moved to the receiving data item according to the rules in general rule 11d.
8.
9.
10.
 
Each delimiter is applied to the sending field in the sequence specified in the UNSTRING statement.
11.
A.
B.
 
If the end of the data item referenced by identifier-1 is encountered before the delimiting condition is met, the examination terminates with the last character examined.
C.
D.
E.
F.
G.
12.
13.
14.
15.
A.
B.
16.
A.
B.
C.
D.
17.
18.
Examples
Get words from a full string and put them into an array, words are separated by "," or "|"
working-storage section.
01 ws-str     pic x(50).
01 words      pic x(10occurs 10 times.
01 str-idx    pic 9(3).
01 word-idx   pic 9(3).
01 word-count pic 9(3).
procedure division.
   move "one|two,apple,pear|peach|last" to ws-str
   move 0 to word-count
   move 1 to str-idx word-idx
   perform until str-idx > 50
     unstring ws-str delimited by "|" or ","
         into words(word-idx)
      pointer str-idx
      tallying word-count
     end-unstring
     add 1 to word-idx
   end-perform.
   perform varying word-idx from 1 by 1 until word-idx > word-count
     display words(word-idx)
   end-perform
   display word-count.

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left