passing temp tables in a generic way

Suppose program.p has a temp-table foo defined in it, and I want to use it by sending the data to a myclass.cls in the constructor?

Can this be accomplished in a generic way using handles or something else? (NOT defining temp-table foo in myclass.cls)

This sounds to me like it is something that should be simple, but I have failed to find any examples of this.

Thanks in advance!
 

tamhas

ProgressTalk.com Sponsor
For starters, I would recommend that you *not* do big complicated things in constructors. If they fail, you are left with a class that doesn't exist and the error handling is consequently more complicated. Better to initialize the class with a minimal constructor and then use an Initialize method or some such to get everything set up.

That aside, I think you should say more about what you want to do. Sure, you can pass a handle, but if the class has no clue what the structure of the temp-table is, what can it possibly do with it? Or, if any given instance is one of a limited set of possibilities, then you can easily structure the Initialize method(s) to handle each type and set up appropriately. You can always pass in JSON. I.e., there are a bunch of options and the best one depends on what you are actually trying to do.
 
Are you suggesting I send the table structure using JSON (and building a dynamic temp-table in the class?) and then sending the actual data as JSON?

This sounds absurd.

There has GOT to be a better way. I don't want to have "includes" in my class, so that it can be generic.

I think we are misunderstanding each other?

Thanks.
Tom
 

TomBascom

Curmudgeon
Since you have a handle you would typically work with the fields in the TT dynamically. That would keep things nice and generic.

Something like this should do the trick:

Code:
do i = 1 to b:num-fields:

  if b:buffer-field( i ):extent = 0 then
    display
      b:buffer-field( i ):name
      b:buffer-field( i ):buffer-value
    .
   else
    do:
      // handle array fields - left as an exercise ;)
    end.

end.
A bit depends on what sort of a handle you have passed. This code assumes that it is a buffer handle obtained from some sort of a query. If you are "just" sending the table handle then you also need to think about how you want to manage querying the table.
 

tamhas

ProgressTalk.com Sponsor
Are you suggesting I send the table structure using JSON
No, I was only listing JSON as one of many ways to pass data. In order to make a recommendation of the preferable way to exchange the data, I would have to know more about your actual requirements.

I might note that I tend to frown on passing temp-tables regardless. Better to encapsulate them in an object and pass the object. That keeps you very generic and hides the implementation details.
 

Cringer

ProgressTalk.com Moderator
Staff member
The advantage of sending the data as JSON is that it's serialized data that can go across the AppServer boundary. I don't believe you can send temp-table data across that, although I may be wrong. In any case, sending JSON is likely to be future proof and easier to maintain.
As Tom says, you can pass the handle and deal with the data using handles and dynamic queries. It works fine, but it can be very hard to come up with a generic solution.
TMH's question about what you're trying to achieve is likely to be a big factor in designing a solution.
 
Top