POINTER phrase
A data item defined with USAGE IS POINTER is a pointer data item or data-pointer. A pointer data item is a 4-byte elementary item or an 8-byte elementary item depending on whether the LP(32) or LP(64) is in effect. If LP(32) is in effect, 4 bytes are allocated for the item; otherwise, 8 bytes are allocated for the item.
You can use pointer data items to accomplish limited base addressing. Pointer data items can be compared for equality or moved to other pointer items.
A pointer data item can be used only:
- In an ALLOCATE statement
- In a FREE statement
- In a SET statement (format 5 only)
- In a relation condition
- In the USING phrase of a CALL statement, an ENTRY statement, or the PROCEDURE DIVISION header
- A POINTER data item can be SET to a value from a POINTER-32 data item. The high-order word of the POINTER data item is cleared to zero.
- Pointer data items can be part of an alphanumeric group that is referred to in a MOVE statement or an input/output statement. However, if a pointer data item is part of a group, there is no conversion of values when the statement is executed.
- A pointer data item can be the subject or object of a REDEFINES clause.
- SYNCHRONIZED can be used with USAGE IS POINTER to obtain efficient use of the pointer data item.
- A VALUE clause for a pointer data item can contain only NULL or NULLS.
- A pointer data item cannot be a conditional variable.
- A pointer data item does not belong to any class or category.
| Can be used with USAGE IS POINTER | Cannot be used with USAGE IS POINTER |
|---|---|
| GLOBAL clause
EXTERNAL clause OCCURS clause VOLATILE clause |
JUSTIFIED clause
PICTURE clause BLANK WHEN ZERO clause |
Pointer data items are ignored in the processing of a CORRESPONDING phrase.
A pointer data item can be written to a data set, but upon subsequent reading of the record that contains the pointer, the address contained might no longer represent a valid pointer.
USAGE IS POINTER is implicitly specified for the ADDRESS OF special register. For more information, see Using tables (arrays) and pointers in the Enterprise COBOL Programming Guide.