COBOL: All About Null-terminated Strings

Even though I was busy in my work, I decided to spend some time for our readers on technical help.  COBOL strings is a key subject  and across all the big mainframe projects (Finance, Insurance and Manufacture) without strings there is no COBOL code.

The below codes helps to implement in your projects:

Working storage variables

01 L pic X(20) value z'ab'.
01 M pic X(20) value z'cd'.
01 N pic X(20).
01 N-Length pic 99 value zero.
01 Y pic X(13) value 'Hello, World!'.

To determine the length of a null-terminated string, and display the value of the string and its length, code:

Inspect N tallying N-length for characters before initial X'00'
Display 'N: ' N(1:N-length) ' Length: ' N-length

To move a null-terminated string to an alphanumeric string, but delete the null, code:

Unstring N delimited by X'00' into X

To create a null-terminated string, code:

String Y delimited by size
X'00' delimited by size
into N.

To concatenate two null-terminated strings, code:

String L delimited by x'00'
M delimited by x'00'
X'00' delimited by size
into N.

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.