-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_string2array.cob
More file actions
43 lines (33 loc) · 1.45 KB
/
Copy pathutils_string2array.cob
File metadata and controls
43 lines (33 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
IDENTIFICATION DIVISION.
PROGRAM-ID. utils_string2array.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-STRING-LEN PIC 9(4).
01 WS-MAX-ELEMENTS PIC 9(4) VALUE 10.
01 WS-COUNT PIC 9(4) VALUE 0.
01 WS-POINTER PIC 9(4) VALUE 1.
01 WS-IDX PIC 9(4).
linkage section.
01 INPUT-STRING PIC X(255).
01 SPLITTER PIC X(1).
01 TABLE-GROUP.
05 ELEMENT PIC X(10) OCCURS 10 TIMES.
PROCEDURE DIVISION USING INPUT-STRING SPLITTER TABLE-GROUP.
MOVE 0 TO WS-COUNT.
MOVE 1 TO WS-POINTER.
MOVE low-value TO TABLE-GROUP.
* Calculate actual length of the input string
CALL "utils_storedCharLength" USING BY REFERENCE INPUT-STRING
WS-STRING-LEN.
* Loop until we run out of string or fill the table
PERFORM UNTIL WS-POINTER > WS-STRING-LEN
OR WS-COUNT = WS-MAX-ELEMENTS
* Increment count to point to the next table slot
ADD 1 TO WS-COUNT
* Extract one element delimited by comma
UNSTRING INPUT-STRING
DELIMITED BY SPLITTER
INTO ELEMENT(WS-COUNT)
WITH POINTER WS-POINTER
END-UNSTRING
END-PERFORM.