codegurukool.com · Free coding tutorials & online compiler

Home › COBOL Tutorial › COBOL UNSTRING

COBOL UNSTRING

Split text into fields.

UNSTRING is the opposite of STRING: it splits a field at a delimiter, such as a comma, into several receiving fields.

Example code

       IDENTIFICATION DIVISION.
       PROGRAM-ID. SPLIT.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 LINE-IN PIC X(20) VALUE "Ada,36,Delhi".
       01 PART-1  PIC X(10).
       01 PART-2  PIC X(10).
       01 PART-3  PIC X(10).
       PROCEDURE DIVISION.
           UNSTRING LINE-IN DELIMITED BY ","
               INTO PART-1 PART-2 PART-3.
           DISPLAY FUNCTION TRIM(PART-1).
           DISPLAY FUNCTION TRIM(PART-2).
           DISPLAY FUNCTION TRIM(PART-3).
           STOP RUN.

Run this code in the online editor

← COBOL strings: STRING, INSPECT and slicesCOBOL arithmetic →