Scope of Shared Temp Table Referenced by Two or More Logic Blocks

I have one question on using the same shared temp table in two logic blocks. Would this work?

Scope of the Shared Temp Table used in Logic blocks

LB 1
begin
Call LB2
Call LB3
end

LB2
begin
Create shared temp table 1 with DSN MyTemp
Insert records into MyTemp
end

LB3
begin
Create shared temp table 1 with DSN MyTemp
Fetch records from MyTemp
end

LB1 is the top-level logic block calling LB2 and LB3.
LB2 creates a shared temp table with DSN MyTemp.
LB3 creates a shared temp table with DSN MyTemp (same name as the one created in LB2).

Question: Would LB1 and LB2 be using the same temp table?

Hi David!

Yes, that would work! LB2 and LB3 would be using the same temp table.

The only exception is if LB2 or LB3 is called in a New Database Transaction. In that case, the new transaction will not share any temp tables with the originating transaction. Otherwise, shared temp tables are accessible by all logic blocks within the transaction.

2 Likes