Top
NetCOBOL V11.0 Syntax Samples
FUJITSU Software

1.39 STRING Statement

The STRING statement is used to connect several character data items.

Character data items can be connected up to an arbitrary delimiter and an arbitrary length.

000010 @OPTIONS MAIN
000020*----------------------------------------------------------------------
000030* The STRING statement is used to connect character data items.
000040*----------------------------------------------------------------------
000050 IDENTIFICATION   DIVISION.
000060 PROGRAM-ID.      SAMPLE.
000070 DATA             DIVISION.
000080 WORKING-STORAGE  SECTION.
000090 01 LISTING       PIC X(30) VALUE SPACE.
000100 01 COUNTER       PIC 9(4)  BINARY.
000110 CONSTANT         SECTION.
000120 01 SHOPPING-LIST.
000130    02              PIC X(15) VALUE "Apple,10,$10".
000140    02              PIC X(15) VALUE "Bread,5,$20".
000150    02              PIC X(15) VALUE "Eggs,10,$2".
000160    02              PIC X(15) VALUE "Tomato,5,$5".
000170    02              PIC X(15) VALUE "Milk,5,$8".
000180 01               REDEFINES SHOPPING-LIST.
000190    02 ELM          OCCURS 5 TIMES PIC X(15).
000200 PROCEDURE        DIVISION.
000210     PERFORM TEST BEFORE
000220             VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER > 5
000230*----------------------------------------------------------------------
000240* The data items to be connected are specified in the STRING statement.
000250* In this example, only the names of products are fetched from a 
000255* shopping list and listed.
000260*----------------------------------------------------------------------
000270       STRING LISTING      DELIMITED BY SPACE
000280              ELM(COUNTER) DELIMITED BY ","
000290              ","          DELIMITED BY SIZE  INTO LISTING
000300*----------------------------------------------------------------------
000310     END-PERFORM.
000320     DISPLAY "Shopping list: " LISTING.
000330 END PROGRAM SAMPLE.