The LENGTH OF special register contains the number of bytes used by an identifier. It returns a value of 16 for a pointer data item or procedure-pointer data item.
You can use LENGTH OF in the Procedure Division anywhere a numeric data item having the same definition as the implied definition of the LENGTH OF special register is used; however, LENGTH OF cannot be used as a subscript or a receiving data item. LENGTH OF has the implicit definition:
USAGE IS BINARY, PICTURE 9(9)
The following example shows how you can use LENGTH OF with pointers:
WORKING-STORAGE SECTION. 77 APTR USAGE POINTER. 01 AB. 05 BPTR USAGE PROCEDURE-POINTER. 05 BVAR PIC S9(3) PACKED-DECIMAL. 05 CVAR PIC S9(3) PACKED-DECIMAL. PROCEDURE DIVISION. MOVE LENGTH OF AB TO BVAR. MOVE LENGTH OF BPTR TO CVAR.
In the above example, the length of group item AB is moved to variable BVAR. BVAR has a value of 20 because BPTR is 16 bytes long, and both variables BVAR and CVAR are 2 bytes long. CVAR receives a value of 16.
You can also use the LENGTH OF special register to set up data structures within user spaces, or to increment addresses received from another program. To see an example of a program that uses the LENGTH OF special register to define data structures within user spaces, refer to Figure 82.
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.