To pass a TABLE-HANDLE by binding, you must specify the BIND keyword in both the calling and the called routines to tell the AVM to use the same temp-table instance for both routines. If the temp-table that will be used as a pointer is static, use the REFERENCE-ONLY keyword when you define the temp-table.

For example, use this syntax in the calling routine:
( { [INPUT] | OUTPUT | INPUT-OUTPUT } TABLE-HANDLE tt-handle BIND ).
In the called routine, use one of these forms, depending on whether the callee's temp-table is dynamic or static. Use the first form when the callee references the temp-table dynamically through a handle; use the second form when the callee has a matching static definition (typically declared REFERENCE-ONLY):
DEFINE [ INPUT | OUTPUT | INPUT-OUTPUT ]
    PARAMETER TABLE-HANDLE tt-handle BIND.
DEFINE [ INPUT | OUTPUT | INPUT-OUTPUT ]
    PARAMETER TABLE FOR temp-table-name BIND.
In whichever routine that contains the temp-table that is not being used, you should define that temp-table as REFERENCE-ONLY if it is static:
DEFINE TEMP-TABLE temp-table-name REFERENCE-ONLY ...

For example, if you are using the called routine’s temp-table data, you define the calling routine’s static temp-table as REFERENCE-ONLY. If you are using the calling routine’s temp-table data, you define the called routine’s static temp-table as REFERENCE-ONLY.

Alternately, if the unused temp-table is dynamic, you should set the TABLE-HANDLE parameter to UNKNOWN.

Example

In the following sample code, ProcA.p builds a dynamic temp-table at run time and runs ProcB.p persistently. It then calls ProcB's bindTable internal procedure once, passing the temp-table handle with the BIND keyword. This binds the temp-table to ProcB.p for the life of the persistent procedure.

ProcB.p declares a static REFERENCE-ONLY temp-table whose definition matches the caller's dynamic table. The REFERENCE-ONLY keyword tells the AVM not to allocate storage for ProcB.p's definition, because at run time it shares the storage allocated by ProcA.p. Because ProcB.p uses a static REFERENCE-ONLY definition, its parameter is declared with the TABLE FOR ttShared BIND form rather than TABLE-HANDLE. After the initial bind, ProcA.p calls ProcB.p's addRecords internal procedure with no parameters. The binding established earlier means ProcB.p still operates on ProcA.p's temp-table instance. ProcA.p then reads the records back through the same instance.

Note: Unlike BY-REFERENCE, the BIND keyword must appear on both the calling RUN statement and the corresponding parameter definition in the called routine. Once the bind is established with a persistent procedure, you do not need to pass the temp-table again on subsequent calls.
ProcA.p (caller)
/* ProcA.p */
DEFINE VARIABLE hTT    AS HANDLE NO-UNDO.
DEFINE VARIABLE hBuf   AS HANDLE NO-UNDO.
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hProc  AS HANDLE NO-UNDO.

/* Build a dynamic temp-table with a single field. */
CREATE TEMP-TABLE hTT.
hTT:ADD-NEW-FIELD("Field1", "CHARACTER").
hTT:TEMP-TABLE-PREPARE("ttShared").
hBuf = hTT:DEFAULT-BUFFER-HANDLE.

/* Run ProcB.p persistently and bind the temp-table once. */
RUN ProcB.p PERSISTENT SET hProc.
RUN bindTable IN hProc (INPUT-OUTPUT TABLE-HANDLE hTT BIND).

/* No need to pass the temp-table again — ProcB.p is still bound to it. */
RUN addRecords IN hProc.

/* Display the records that ProcB.p added. */
CREATE QUERY hQuery.
hQuery:SET-BUFFERS(hBuf).
hQuery:QUERY-PREPARE("FOR EACH ttShared").
hQuery:QUERY-OPEN().
hQuery:GET-FIRST().

REPEAT WHILE NOT hQuery:QUERY-OFF-END:
  DISPLAY hBuf:BUFFER-FIELD("Field1"):BUFFER-VALUE FORMAT "X(20)".
  hQuery:GET-NEXT().
END.

DELETE OBJECT hQuery.
DELETE OBJECT hProc.   /* unload ProcB.p */
DELETE OBJECT hTT.
ProcB.p (callee)
/* ProcB.p */
DEFINE TEMP-TABLE ttShared NO-UNDO REFERENCE-ONLY
  FIELD Field1 AS CHARACTER.

PROCEDURE bindTable:
  DEFINE INPUT-OUTPUT PARAMETER TABLE FOR ttShared BIND.
END PROCEDURE.

PROCEDURE addRecords:
  CREATE ttShared.
  ASSIGN ttShared.Field1 = "Record1".

  CREATE ttShared.
  ASSIGN ttShared.Field1 = "Record2".

  CREATE ttShared.
  ASSIGN ttShared.Field1 = "Record3".
END PROCEDURE.