Delete dynamic tablename

m.hansler

New Member
I have several different temp-tables and at some point after some operation I need to empty those tables so I can start all over again.

So I want to do something like this:

DEF TEMP-TABLE LabelData
FIELD... ...

DEF TEMP-TABLE AddressData
FIELD... ...

[...some procedure to fill the table of choice...]
and after that procedure is done I want to empty the tt that was used.

RUN EmptyTT(LabelData).

PROCEDURE EmptyTT:
DEFINE INPUT PARAMETER TABLE FOR {1}.
FOR EACH {1}:
DELETE {1}.
END.
END PROCEDURE.

This obviously doesn't work, but you get the idea.
 
why don't you simply use the EMPTY TEMP-TABLE statement?

Code:
EMPTY TEMP-TABLE LabelData.
instead of...
Code:
 RUN EmptyTT(LabelData).
 
:brick:I obviously wanted to do it the hard way :blush1:

There is no mention of EMPTY TEMP-TABLE in my Progress Online reference chm. I guess it's either incomplete or really old. I now have a 4GL reference pdf and there it is...

Thanks for your help.

ps: I'll just go crawl in a little corner now
 
why don't you simply use the EMPTY TEMP-TABLE statement?

Empty Temp-Table statement is sometimes troublesome especially if you try to empty that in the middle of a transaction.

The better way is to delete records using for each statement. However, there may be second opinions. ;)
 
Aha.

In the above case I want to empty after a previous transaction is closed. And the 4GL reference indeed mentions a warning about active transactions.

But still, If I do want to do that during an active transaction, how do I pass a temp-table name to that procedure that does the for each.
 
if you really need you temp-table to be 'undo' then you can use that since the empty temp-table will indeed fail for 'undo' tables in a middle of a transaction.

Code:
def temp-table tt
    field a as inte.

def var i as inte no-undo.
def var c as char.


do  i = 1 to 10:
    create tt.
    tt.a = i.
end.

do transaction:
    c = 'test'.
    run empty_temp_table(temp-table tt:handle).
end.

for each tt:
    display tt.
end.

procedure empty_temp_table:
    define input parameter htt as handle no-undo.

    define variable hbuf as handle no-undo.

    hbuf = htt:default-buffer-handle no-error.
    if not valid-handle(hbuf) then return error.

    do while true:
        hbuf:find-first('', exclusive-lock) no-error.
        if not hBuf:available then return.
        hbuf:buffer-delete().
    end.
end procedure.
 
Back
Top