Thread: COBOL

Unstring

Started by carl • user2 replies7 viewsLast activity 1 week ago
Post #1
0 votes
carl
Reputation
0
Posts: 1
Joined: Feb 16, 2026, 4:18 PM
Posted: Feb 16, 2026, 4:24 PM
0

Hi,

I would like to unstring a text file,but there is one problem on my side.
There are no delimiters on the file, the fields are continuous
ex:
202510152352000015465652
first 8 bytes - date
second 4 bytes - time
last 12 bytes are the size

thank you, best regards

Post #2
0 votes
stagarono
Reputation
0
Posts: 0
Joined: Dec 5, 2025, 4:18 PM
Posted: Feb 28, 2026, 1:54 PM
0

Hi Carl

If the input record has a fixed layout then you don't need to use Unstring.
Instead you can just use a basic variable declaration to split them up:


IDENTIFICATION DIVISION.
PROGRAM-ID. "DATA".

DATA DIVISION.
  WORKING-STORAGE SECTION.
    01  WS-INP         PIC X(24) value "202510152352000015465652".
    01  WS-OUT-REC.
       05  WS-OUT-DATE       PIC X(8).
       05  WS-OUT-TIME        PIC X(4).
       05  WS-OUT-SIZE        PIC X(12).

PROCEDURE DIVISION.

     MOVE WS-INP TO WS-OUT-REC
     DISPLAY "WS-OUT-DATE: " WS-OUT-DATE
     DISPLAY "WS-OUT-TIME: " WS-OUT-TIME
     DISPLAY "WS-OUT-SIZE: " WS-OUT-SIZE

STOP RUN.

Output:
WS-OUT-DATE: 20251015
WS-OUT-TIME: 2352
WS-OUT-SIZE: 000015465652

This is just an example to show it being split up into the individual fields.

You must be signed in to reply to this thread