The following example illustrates some of the considerations that apply to the UNSTRING statement.
In the Data Division, the user has defined the following input record to be acted upon by the UNSTRING statement:
01 INV-RCD. 05 CONTROL-CHARS PIC XX. 05 ITEM-INDENT PIC X(20). 05 FILLER PIC X. 05 INV-CODE PIC X(10). 05 FILLER PIC X. 05 NO-UNITS PIC 9(6). 05 FILLER PIC X. 05 PRICE-PER-M PIC 99999. 05 FILLER PIC X. 05 RTL-AMT PIC 9(6).99.
The next two records are defined as receiving fields for the UNSTRING statement. DISPLAY-REC is to be used for printed output. WORK-REC is to be used for further internal processing.
01 DISPLAY-REC
05 INV-NO PIC X(6).
05 FILLER PIC X VALUE SPACE
05 ITEM-NAME PIC X(20).
05 FILLER PIC X VALUE SPACE
05 DISPLAY-DOLS PIC 9(6).
01 WORK-REC
05 M-UNITS PIC 9(6).
05 FIELD-A PIC 9(6).
05 WK-PRICE
REDEFINES
FIELD-A PIC 9999V99.
05 INV-CLASS PIC X(3).
The user has also defined the following fields for use as control fields in the UNSTRING statement.
01 DBY-1 PIC X, VALUE IS ".". 01 CTR-1 PIC 99, VALUE IS ZERO. 01 CTR-2 PIC 99, VALUE IS ZERO. 01 CTR-3 PIC 99, VALUE IS ZERO. 01 CTR-4 PIC 99, VALUE IS ZERO. 01 DLTR-1 PIC X. 01 DLTR-2 PIC X. 01 CHAR-CT PIC 99, VALUE IS 3. 01 FLDS-FILLED PIC 99, VALUE IS ZERO.
In the Procedure Division, the user writes the following UNSTRING statement to move subfields of INV-RCD to the subfields of DISPLAY-REC and WORK-REC:
UNSTRING INV-RCD DELIMITED BY ALL SPACES OR "/" OR DBY-1 INTO ITEM-NAME COUNT IN CTR-1, INV-NO DELIMITER IN DLTR-1 COUNT IN CTR-2, INV-CLASS, M-UNITS COUNT IN CTR-3, DISPLAY-DOLS DELIMITER IN DLTR-2 COUNT IN CTR-4 WITH POINTER CHAR-CT TALLYING IN FLDS-FILLED ON OVERFLOW GO TO UNSTRING-COMPLETE.
Before the UNSTRING statement is issued, the user places the value 3 in the CHAR-CT (the pointer item), so as not to work with the two control characters at the beginning of INV-RCD. In DBY-1, a period is placed for use as a delimiter, and in FLDS-FILLED (the tallying item) the value 0 is placed. The following data is then read into INV-RCD as shown in Figure 26.
Figure 26. UNSTRING Statement Example-Input Data

When the UNSTRING statement is executed, the following actions take place:
At the end of execution of the UNSTRING statement, DISPLAY-REC contains the following data:
707890 FOUR-PENNY-NAILS 000379
WORK-REC contains the following data:
475120000122BBA
CHAR-CT (the pointer field) contains the value 55, and FLD-FILLED (the tallying field) contains the value 6.
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.