Too many indexes defined.

Posted by stedyer on 22-Jul-2010 06:00

I have a routine which is calling a second procedure which returns a temp-table, by handle.  After a few thousands runs in one go, I get the too many indexes errror.  A few weeks ago I had managed to fix this......but the code has gone missing and I cant for life of me remember it!

From memory basically what was happening was that everytime the second procedure ran it would do CREATE TEMP-TABLE, which would put an instance in the session.  Now despite doing DELETE OBJECT on these, they still remain in the SESSION, and what I need to do is a check before I do that CREATE TEMP-TABLE of all the buffers in the current session.  If I find one that matches the one I am about to create I need to remove it from the SESSION.

So if I run my routine 10 times and then I run this code:

DO WHILE VALID-HANDLE(hBuffer):
   
    IF VALID-HANDLE((hBuffer:TABLE-HANDLE)) THEN DO:
      
        OUTPUT TO VALUE('C:\session.txt') APPEND.
        PUT UNFORMATTED hBuffer:TABLE-HANDLE:NAME SKIP.
        OUTPUT CLOSE.

    END.
   
    IF VALID-HANDLE(hBuffer) THEN
    hBuffer = hBuffer:NEXT-SIBLING.
END.

then in my file I will get:

tt-OptIncome

tt-OptIncome

tt-OptIncome

tt-OptIncome

tt-OptIncome

tt-OptIncome

tt-OptIncome

tt-OptIncome

tt-OptIncome

tt-OptIncome

If i then run my routine again for another 10 records, that list from the session will then have 20 items in it.  What I need to do, and had done before, was each time the procedure ran I looped through the session, as I have in that output code, and removed the objects from the session.  Does anyone know how to do this?

Thanks

Steve

All Replies

Posted by Admin on 22-Jul-2010 06:09

I have a routine which is calling a second procedure which returns a temp-table, by handle.  After a few thousands runs in one go, I get the too many indexes errror.  A few weeks ago I had managed to fix this......but the code has gone missing and I cant for life of me remember it!

 

When the program creating the temp-table has an OUTPUT PARAMETER TABLE-HANDLE it's creating a copy of the temp-table for the receiving procedure. You'll have two temp-tables active instead of one!

So either do a DELETE OBJECT hTempTable in the called program (last statement) AND the calling program (after the TT is no longer needed) or switch to BY-REFERENCE passing the temp-tables/table-handle parameters in which case you'd not create a copy of the temp-table.

In the first case, the DEELETE OBJECT hTempTable is delayed until after the called procedure is completed and the temp-table has returned.

It's a common misunderstanding, that TABLE-HANDLE parameters do not create a deep copy of the temp-table. In fact they DO create a copy. It's just the schema which is dynamic. So when you don't need dynamic temp-table, don't use them, don't use TABLE-HANDLE parameters! Use static temp-tables and pass them BY-REFERENCE.

This thread is closed