COBOLintermediate

STRING and UNSTRING Verbs

Understand how COBOL concatenates and splits alphanumeric fields without dynamic string types.

COBOL has no native dynamic string class, so building composite messages or parsing delimited data relies on two dedicated verbs: STRING for concatenation and UNSTRING for splitting. These come up constantly in interviews about report generation, file parsing, and interfacing with delimited feeds (like CSV extracts from open systems).

STRING and UNSTRING are like a luggage packing strip with a fixed number of marked slots — you can pack items end to end or unpack them back out, but the strip never gets longer no matter how much you try to stuff into it.

Key Concepts

1
STRING combines multiple source fields into a single receiving field, optionally inserting delimiters, and tracks the current write position with a POINTER clause so successive STRING statements can append rather than overwrite. Without care, STRING can silently truncate if the receiving field is too short, or leave trailing garbage from a previous value if the field wasn't cleared first — both classic interview gotchas.
2
UNSTRING does the reverse: it splits one field into multiple targets based on a DELIMITED BY clause, which can be a literal character, a data-item, or ALL to treat repeated delimiters as one. It also supports a POINTER and a TALLYING clause to count how many fields were extracted, which matters when the number of delimited tokens is variable.
3
Because neither verb resizes its target, and both work on fixed-length PIC X fields, most real bugs in interview scenarios revolve around field-length mismatches, un-cleared receiving fields, and forgetting to reset the POINTER between STRING/UNSTRING calls in a loop.