Skip to main content

Problem:

The ANY LENGTH Clause --- extract of Netx DOCumentation:

The ANY LENGTH clause specifies that the length of a linkage section item may vary at runtime and is determined by the length of the argument.

General Format

  ANY LENGTH

Syntax Rules

The ANY LENGTH clause must be specified only in an elementary level 1 entry in the Linkage Section of a function, of a contained program, or of a method that is not a property method.

Note: The ANY LENGTH clause is not permitted to be specified in an outermost program. This is because an outermost program can be called with or without a program-prototype format CALL statement. For calls without a program-prototype, the implementation is not able to determine whether an argument corresponds to a formal parameter described with ANY LENGTH.

If the source element containing the ANY LENGTH clause is a contained program or is a method, the subject of the entry must be referenced in its PROCEDURE DIVISION header as either

A formal parameter with the BY REFERENCE phrase, or

The returning item.

If the source element containing the ANY LENGTH clause is a function, the subject of the entry must be referenced in its PROCEDURE DIVISION header as a formal parameter with the BY REFERENCE phrase.

A PICTURE clause must be specified for the subject of the entry, and the character-string specified in the PICTURE clause must be one instance of the picture symbols 'N' or 'X'.

General Rules

The ANY LENGTH clause specifies that the subject of the entry must be:

A zero-length item when the corresponding argument or returning item of the activating runtime element is a zero-length item, or

Treated as though there were n repetitions of the picture symbol in the character-string in its PICTURE clause, where n is the length of the corresponding argument or returning item of the activating runtime element.

Resolution:

'STDOUT' of sample pasted below:

Micro Focus Net Express V4.0.38                             

RUN TIME ENVIRONMENT Copyright (C) 1984-2005 Micro Focus International Ltd.    

URN AXCGG/AA0/00000                                                            

*--> call SUB-PROGRAM passing 20  characters  

*--> SUB-PROGRAM: / Length: 0000000020 > xxxxxxxxxxxxxxxxxxxx

*--> call SUB-PROGRAM passing 30  characters  

*--> SUB-PROGRAM: / Length: 0000000030 > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

*--> call SUB-PROGRAM passing 40  characters  

*--> SUB-PROGRAM: / Length: 0000000040 > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

sample:

       working-storage section.

       01 p20  pic x(20).

       01 p30  pic x(30).

       01 p40  pic x(40).

       78 pfx  value "*--> ".

       78 SPG  value "SUB-PROGRAM".

       local-storage section.

       linkage section.

       01 lkPn pic x  ANY LENGTH.

       procedure division.

           display pfx "call " SPG " passing "

                   function LENGTH(p20) "  characters  "

           move all "x" to   p20

           call SPG   using p20

           display pfx "call " SPG " passing "

                   function LENGTH(p30) "  characters  "

           move all "x" to   p30

           call SPG   using p30

           display pfx "call " SPG " passing "

                   function LENGTH(p40) "  characters  "

           move all "x" to   p40

           call SPG   using p40

           exit program.

           stop run.

       entry SPG  using by reference lkPn.

           display pfx SPG

                   ": "

                   "/ Length: " function LENGTH(lkpn)

                   " > "

                   LkPn(1:function LENGTH(lkpn))

           move all "y" to lkPn

           exit program.

Old KB# 3819