Start of change

%ADDRESS built-in function

The address built-in function (%ADDRESS or %ADDR) can be used to change or test the memory address stored in a CL pointer variable and can only be used within a CL procedure.

In a CHGVAR command, you can specify the %ADDRESS function to change the value of a pointer variable. On the IF command, %ADDRESS function can be specified on the COND parameter to check the value stored in a pointer variable.

The format of the address built-in function is:
%ADDRESS(variable name)
or
%ADDR(variable name)

In the following example, pointer variable &P1 is initialized to the address of the first byte of character variable &C1. Later in the procedure, the pointer is checked using the %ADDRESS function to see if it still points to &C1 and, if not, resets &P1 to the first byte of CL variable &C1 using the %ADDRESS function.

PGM
DCL &C1  *CHAR  10
DCL &P1   *PTR  ADDRESS(&C1)
:
IF COND(&P1 *NE %ADDRESS(&C1))  +
   THEN(CHGVAR  &P1  %ADDRESS(&C1))
:
ENDPGM      
Note: The %ADDRESS function cannot be used to store the address offset stored in a pointer variable. To store the address offset in a pointer variable, you need to use the %OFFSET built-in function.
Related tasks
Change the value of a variable
Related reference
Built-in functions for CL
End of change