CURRENTSTORAGE Function

Purpose

Returns a Fixed Bin(15) value that is the number of bytes of storage used by the current value of the referenced variable.

Syntax

CURRENTSTORAGE(reference)

Abbreviation(s): CSTG for CURRENTSTORAGE.

Parameters

reference is a variable.

Description

For constant-length strings and other fixed-size variables, the CURRENTSTORAGE function returns a Fixed Bin(15) integer that is the number of bytes allocated for the referenced variable.

A variable-length string consists of two parts: the text field and the length field. CURRENTSTORAGE returns the number of bytes of the text field currently in use plus two, since the length field always uses two bytes.

For a scalar area or an element of an array of areas, the CURRENTSTORAGE function returns the sum of the current extent of the area plus the size of the area header. Any bytes at the end of the area that have not been allocated are not included in the area extent value. Note, however, that the extent does include the size of any holes in the area that have developed as a result of ALLOCATE and FREE operations. For an array of areas, the CURRENTSTORAGE function returns the maximum size of the array, including the header bytes for each area element of the array.

Examples

DCL A FIXED BIN(15) INIT (1);   /* CSTG (A) = 2 */ 
DCL B CHAR(5) INIT ('XY');          /* CSTG (B) = 5 */
DCL C CHAR(5) VARYING INIT ('XY');  /* CSTG ©) = 4 */
DCL D BIT(4) INIT ('1010'B);        /* CSTG (D) = 1 */

Restrictions

None.