Strange Behaviour with XREF

Hi Everybody,
Am not sure if it is a strange behavior of XREF when temp-table & buffers are used. Below is a sample code snippet with its xref details.

DEFINE TEMP-TABLE ttminstore NO-UNDO LIKE minstore
FIELD cEr-id AS CHARACTER
FIELD iBillcode AS INTEGER
FIELD cStatus AS CHARACTER
INDEX idx_prim_uniq IS PRIMARY UNIQUE cs-id dv-id cd-id ms-mintype
INDEX idx_sort cStatus cEr-id iBillcode.

DEFINE BUFFER bfttminstore FOR ttminstore.

FOR EACH ttminstore BREAK BY ttminstore.cs-id
BY ttminstore.dv-id
BY ttminstore.cd-id:
END.


FOR FIRST bfttminstore NO-LOCK WHERE bfttminstore.cs-id = ttminstore.cs-id
AND bfttminstore.ms-mintype = ttminstore.ms-mintype
AND bfttminstore.ms-levelind = ttminstore.ms-levelind
AND bfttminstore.ms-amount <> ttminstore.ms-amount
:
END.
XREF Details:
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 COMPILE "C:\saravanakumarb\bufferTest.p"
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 CPINTERNAL ISO8859-1
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 CPSTREAM ISO8859-1
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 STRING "ttminstore" 10 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 STRING "CS-ID" 5 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 STRING "CD-ID" 5 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 STRING "ms-amount" 9 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 STRING "ms-autobill" 11 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 STRING "ms-levelind" 11 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 STRING "ms-trcndate" 11 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 STRING "ms-trcntime" 11 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 STRING "ms-userid" 9 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 STRING "dv-id" 5 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 STRING "ms-mintype" 10 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 STRING "cEr-id" 6 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 STRING "iBillcode" 9 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 STRING "cStatus" 7 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 1 REFERENCE master.minstore
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 8 STRING "bfttminstore" 12 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 21 STRING "idx_prim_uniq" 13 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 21 STRING "idx_sort" 8 NONE UNTRANSLATABLE
"C:\saravanakumarb\bufferTest.p" "C:\saravanakumarb\bufferTest.p" 21 STRING "idx_prim_uniq" 13 NONE UNTRANSLATABLE

Note:
Xref Details are different for temp tables (& its buffer) depending on where its buffer was defined
1. Program level Buffer & program level Query -> No Xref Info on Temp table and buffer
2. Program level buffer & procedure level Query -> Xref Info Returned for both temp table and buffer
3. Procedure level buffer and Procedure level query -> No Xref Info for Buffers

Thanks in advance..!
 

RealHeavyDude

Well-Known Member
I don't have a detailed comment on your XREF output in particular ...

But, the buffer scope of the default buffer that comes with the Temp-Table will always be the procedure or class in which the Temp-Table is defined. Note that you can't define a Temp-Table within an internal procedure or function - for that reason. Therefore you can reference the default buffer of that Temp-Table everywhere in your procedure or class. A defined buffer for the Temp-Table is always scoped to the next outer block with scoping capabilities. Therefore, if you define the buffer in an internal procedure or function it's scoped to the internal procedure or function. And, IMHO of course, it is good practice to use defined buffers when accessing the contents of a Temp-Table, especially when you update its contents. Otherwise you will experience - in your opinion - strange behavior. I think that is, in a nutshell, what should be read out of XREF - but it's not so obvious if you not familiar with buffer scope.

Heavy Regards, RealHeavyDude.
 
I agree... The intent of posting this question is, whenever we get something different we used to try and play with different combination to find how exactly it works and it doesn't mean we don't know to use that functionality.

The question was "Why it behaves so" and not "How to use it"? I am familiar with the second one but don't have a clue on the first one. Hope you agree...
 
Top