Top
NetCOBOL V11.0 Syntax Samples
FUJITSU Software

1.40 UNSTRING Statement

The UNSTRING statement is used to split character string data using an arbitrary delimiter and store the split character string data in individual data items.

000010 @OPTIONS MAIN
000020*----------------------------------------------------------------------
000030* The UNSTRING statement is used to split a character string using an 
000035* arbitrary delimiter.
000040*----------------------------------------------------------------------
000050 IDENTIFICATION   DIVISION.
000060 PROGRAM-ID.      SAMPLE.
000070 DATA             DIVISION.
000080 WORKING-STORAGE  SECTION.
000090 01 .
000100    02 WORD       OCCURS 10 TIMES PIC X(10).
000110 01 COUNTER       PIC 9(4) BINARY.
000120 01 SRCH-POS      PIC 9(4) BINARY VALUE 1.
000130 01 WORD-NUM      PIC 9(4) BINARY VALUE 0.
000140 CONSTANT         SECTION.
000150 77 STR-DATA      PIC X(25) VALUE "Are you hungry? Yes,I am.".
000160 PROCEDURE        DIVISION.
000170      DISPLAY "String: " STR-DATA.
000180      DISPLAY " ".
000190      PERFORM TEST BEFORE
000200              VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER > 10
000210*----------------------------------------------------------------------
000220* The UNSTRING statement can specify the following items:
000230* -  Delimiter (DELIMITED BY)
000240* -  Storage area (INTO)
000250* -  Search starting position (WITH POINTER)
000260* -  Storage area of split count (TALLYING IN)
000270* 
000280*----------------------------------------------------------------------
000290       UNSTRING STR-DATA
000300                DELIMITED BY ALL SPACE OR "," OR "."
000310                INTO WORD(COUNTER)
000320                WITH POINTER SRCH-POS
000330                TALLYING IN  WORD-NUM
000340       END-UNSTRING
000350*----------------------------------------------------------------------
000360     END-PERFORM.
000370     PERFORM TEST BEFORE
000380             VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER > WORD-NUM
000390       DISPLAY COUNTER "." WORD(COUNTER)
000400     END-PERFORM.
000410 END PROGRAM SAMPLE.