ILE COBOL Language Reference

STRING Statement Example

The following example illustrates some of the considerations that apply to the STRING statement.

In the Data Division, the programmer has defined the following fields:

   01 RPT-LINE     PICTURE X(120).
   01 LINE-POS     PICTURE 99.
   01 LINE-NO      PICTURE 9(5) VALUE 1.
   01 DEC-POINT    PICTURE X VALUE ".".

In the File Section, he or she has defined the following input record:

01 RCD-01.
   05 CUST-INFO.
      10 CUST-NAME  PICTURE X(15).
      10 CUST-ADDR  PICTURE X(34).
   05 BILL-INFO.
      10 INV-NO     PICTURE X(6).
      10 INV-AMT    PICTURE $$,$$$.99.
      10 AMT-PAID   PICTURE $$,$$$.99.
      10 DATE-PAID  PICTURE X(8).
      10 BAL-DUE    PICTURE $$,$$$.99.
      10 DATE-DUE   PICTURE X(8).

The programmer wants to construct an output line consisting of portions of the information from RCD-01. The line is to consist of a line number, customer name and address, invoice number, date due, and balance due, truncated to the dollar figure shown.

The record as read in contains the following information:
J.B. SMITH     
444 SPRING ST., CHICAGO, ILL.     
A14275
$4,736.85
$2,400.00
09/22/76
$2,336.85
09/09/94

In the Procedure Division, the programmer initializes RPT-LINE to SPACES and sets LINE-POS (which is to be used as the pointer field) to 4. Then he issues this STRING statement:

   STRING LINE-NO SPACE
       CUST-INFO SPACE
       INV-NO SPACE
       DATE-DUE SPACE
     DELIMITED BY SIZE,
       BAL-DUE
     DELIMITED BY DEC-POINT
     INTO RPT-LINE
     WITH POINTER LINE-POS.

When the statement is executed, the following actions take place:

  1. The field LINE-NO is moved into positions 4 through 8 of RPT-LINE.
  2. A space is moved into position 9.
  3. The group item CUST-INFO is moved into positions 10 through 58.
  4. A space is moved into position 59.
  5. INV-NO is moved into positions 60 through 65.
  6. A space is moved into position 66.
  7. DATE-DUE is moved into positions 67 through 74.
  8. A space is moved into position 75.
  9. The portion of BAL-DUE that precedes the decimal point is moved into positions 76 through 81.

After the STRING statement has been executed:

Note:
One STRING statement can be written instead of a series of MOVE statements.

Figure 24. STRING Statement Example Output Data

REQTEXT


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]