Skip to main content

This article explains how to use the ANY LENGTH clause to define the incoming string in the sub program.

Problem:

Is it possible to to pass strings to a sub-program without the sub-program knowing the length of the passed string?

Resolution:

Use the ANY LENGTH clause to define the incoming string in the sub program. The attached example defines a user function, MyFunc, which receives strings of any length and calculates the length based on the position of the last non-space alphanumeric character in the string.

The MyMain.cbl program uses two different variables, one defined as a PIC X(20) and the other PIC X(378). These variables are assigned string values and the MyFunc function is called twice, once for each variable. Myfunc defines the incoming linkage item as PIC X ANY LENGTH, allowing it to receive varying length strings.

Incident Number: 2266912

Old KB# 14479