About using by-reference

Posted by aspotti on 13-Jun-2012 02:43

Hi all,

   I got a question from a customer about the use of By-Reference option in parameters.

"There is a way to know in a procedure to know if a temp-table, prodataset (and their handles) is passed by-reference/bind?"

As far as I know there is not a function/method or property that allows this, also because when passing appServer boundry an object like a temp-table is always passed BY VALUE.

Am I right? Is there something?

thanks

   Alex

All Replies

Posted by Peter Judge on 13-Jun-2012 07:41

I believe there's no way of knowing.

Do you know why it's important to the customer?

-- peter

Posted by aspotti on 13-Jun-2012 07:54

well... they have seen something in other languages,trying to do the same with OE. They were shocked this was not possible!! (I leave you out their reaction when I explained why).

By the way...the reason is because each time they delete passed parameter temp-table and since BY-REF and DELETE object does not match properly, they look for a quick workaround to know which need to be deleted and which not.

Thanks,

   Alex

Posted by Thomas Mercer-Hursh on 13-Jun-2012 13:32

I.e., a brute force programmatic solution to avoid proper analysis ...

Posted by Admin on 18-Jun-2012 02:01

in  situations where you use either a class or a stored procedure - when  the TT is being initialized before the IP is being called - you can save  the unique identifier of the TT and then in IP you can compare that  with the identifier of the TT being passed at call time, if different  then was by-reference.

guess  accessing the identifier for the TT will count as a reference in the  content of delayed instantiation added in the latest version... just in  case you might not want that.

/* tt.i */

def temp-table tt field a as char.

/* pp.p */

{tt.i}

def var i as integer.
i = temp-table tt:unique-id.

procedure test:
  define input parameter table for tt.
  message i skip temp-table tt:unique-id view-as alert-box.
end.

/* test pp.p */

{tt.i}

def var h as handle.

run pp.p persistent set h.

run test in h (table tt).

run test in h (table tt by-reference).

delete object h.

Posted by Sasha Kraljevic on 18-Jun-2012 05:19

As far as I know, there is no direct attribute that would give information if a certain parameter
has been passed by-reference, but in their case num-references might be useful as it should always return non zero value
in case by-reference has been used to pass it to the calling procedure.
From online help:
NUM-REFERENCES attribute
The number of references to a buffer,  ProDataSet, or temp-table object that is defined as a parameter to which  reference-only objects are bound.
Data type:
INTEGER
Access:
Readable
Applies to:
Buffer object handle, ProDataSet object handleTemp-table object  handle
Use this attribute to determine whether a  buffer, ProDataSet, or temp-table object is referenced by another procedure  before you delete the defining procedure or the referenced object itself (if it  is a dynamic object).
If the buffer, ProDataSet, or temp-table  object is not referenced by any other procedure (or other such object), this  attribute returns 0. Otherwise, this attribute returns the number of procedures  (or other such objects) currently referencing the object.
This attribute applies to objects defined  as reference-only parameters, not shared objects.
Sasha

Posted by aspotti on 18-Jun-2012 06:58

I did a mix of brute force programming and use temp-table attributes/handles to check if it is referenced.

Thanks to all !!!!

Alex

This thread is closed