Example: STRING statement
The following example shows the STRING
statement
selecting and formatting information from a record into an output
line.
The FILE SECTION
defines the following
record:
01 RCD-01.
05 CUST-INFO.
10 CUST-NAME PIC X(15).
10 CUST-ADDR PIC X(35).
05 BILL-INFO.
10 INV-NO PIC X(6).
10 INV-AMT PIC $$,$$$.99.
10 AMT-PAID PIC $$,$$$.99.
10 DATE-PAID PIC X(8).
10 BAL-DUE PIC $$,$$$.99.
10 DATE-DUE PIC X(8).
The WORKING-STORAGE SECTION
defines
the following fields:
77 RPT-LINE PIC X(120).
77 LINE-POS PIC S9(3).
77 LINE-NO PIC 9(5) VALUE 1.
77 DEC-POINT PIC X VALUE ".".
The record RCD-01
contains the following
information (the symbol b
indicates
a blank space):
J.B.bSMITHbbbbb
444bSPRINGbST.,bCHICAGO,bILL.bbbbbb
A14275
$4,736.85
$2,400.00
09/22/76
$2,336.85
10/22/76
In the PROCEDURE DIVISION
, these
settings occur before the STRING
statement:
RPT-LINE
is set toSPACES
.LINE-POS
, the data item to be used as thePOINTER
field, is set to 4.
Here is the STRING
statement:
STRING
LINE-NO SPACE CUST-INFO INV-NO SPACE DATE-DUE SPACE
DELIMITED BY SIZE
BAL-DUE
DELIMITED BY DEC-POINT
INTO RPT-LINE
WITH POINTER LINE-POS.
Because the POINTER
field LINE-POS
has
value 4 before the STRING
statement is performed,
data is moved into the receiving field RPT-LINE
beginning
at character position 4. Characters in positions 1 through 3 are unchanged.
The sending items that specify DELIMITED BY SIZE
are
moved in their entirety to the receiving field. Because BAL-DUE
is
delimited by DEC-POINT
, the moving of BAL-DUE
to
the receiving field stops when a decimal point (the value of DEC-POINT
)
is encountered.
STRING results
When the STRING
statement is performed,
items are moved into RPT-LINE
as shown in the table
below.
Item | Positions |
---|---|
LINE-NO |
4 - 8 |
Space | 9 |
CUST-INFO |
10 - 59 |
INV-NO |
60 - 65 |
Space | 66 |
DATE-DUE |
67 - 74 |
Space | 75 |
Portion of BAL-DUE that precedes the decimal
point |
76 - 81 |
After the STRING
statement is performed,
the value of LINE-POS
is 82, and RPT-LINE
has
the values shown below.