Previous Topic Next topic Print topic


OFFSET Function

Purpose

Returns an offset value relative to an area and derived from a pointer.

Syntax

OFFSET(p,a)

Parameters

p is a pointer reference identifying a based variable; a is the area containing the based variable.

Description

The OFFSET function returns an offset value that is the relative byte offset of a based variable stored within an area variable.

If p is the null pointer value, the OFFSET function returns the null offset value.

Examples

DECLARE (A, B) AREA;
DECLARE (A1, A2) CHAR(20) BASED; 
DECLARE (P1, P2) POINTER; 
DECLARE (01, 02) OFFSET(A); 
DECLARE (03, 04) OFFSET(B);

ALLOCATE A1 IN(A) SET(01);
ALLOCATE A2 IN(A) SET(02);

B = A;                /* assign area */

P1 = ADDR(01->A1);    /* address of A1 in A */
P2 = POINTER(02, B);  /* address of A2 in B */

03 = OFFSET(P1, A);   /* offset value of A1 - 
                         same in A and B */
04 = OFFSET(P2, B);   /* offset value of A2 - 
                         same in A and B */

Restrictions

None.

Previous Topic Next topic Print topic