上面的代码在 _connect 和 _UserTableStat 之间的连接存在问题:
WHERE _Connect._Connect-Id = _UserTableStat._UserTableStat-Conn
你必须改用这个:
WHERE _Connect._Connect-Usr = _UserTableStat._UserTableStat-Conn
hint: _Connect-Usr = _Connect-Id + 1
接下来,以下代码给出了一个按 _UserTableStat-read 降序排序的列表:
DEFAULT-WINDOW:WIDTH-CHARS = 240.
DEFINE VARIABLE dmon AS DATETIME NO-UNDO.
DEFINE VARIABLE dstart AS DATETIME NO-UNDO.
DEFINE VARIABLE iusertablestat AS INTEGER NO-UNDO.
DEFINE VARIABLE lfirstview AS LOGICAL INITIAL TRUE NO-UNDO.
DEFINE TEMP-TABLE ttuts LIKE _UserTableStat
FIELD _Connect-Type AS CHARACTER INITIAL ?
FIELD _Connect-Name AS CHARACTER INITIAL ? FORMAT "X(15)"
FIELD _Connect-Time AS CHARACTER INITIAL ? FORMAT "X(25)"
FIELD _Connect-ClientType AS CHARACTER INITIAL ?
INDEX _UserTableStat-read _UserTableStat-read
INDEX _UserTableStat-update _UserTableStat-update
INDEX _UserTableStat-create _UserTableStat-create
INDEX _UserTableStat-delete _UserTableStat-delete.
dstart = NOW.
dmon = NOW.
DEFAULT-WINDOW:TITLE = SUBSTITUTE("starting scan of _UserTableStat at &1", dstart).
FOR EACH _UserTableStat NO-LOCK:
iusertablestat = iusertablestat + 1.
IF iusertablestat MODULO 10000 = 0
OR INTERVAL(NOW, dmon, "milliseconds") > 1000 THEN
DO:
dmon = NOW.
IF lfirstview THEN
DO:
DISPLAY "scanning in process" WITH FRAME fviewit.
lfirstview = FALSE.
END.
DEFAULT-WINDOW:TITLE = SUBSTITUTE("&1 - Scanning since &2 ms - &3 _UserTableStat records (started at &4)"
, NOW, INTERVAL(NOW, dstart, "milliseconds"), iusertablestat, dstart).
DEFAULT-WINDOW:TITLE = SUBSTITUTE("starting scan of _UserTableStat at &1 scanned &2 records", dstart, iusertablestat).
PROCESS EVENTS.
END.
/* if you are interested in updates or delte, then adapath this next line */
IF _UserTableStat._UserTableStat-read = 0
THEN NEXT.
IF _UserTableStat._UserTableStat-Conn <> ?
THEN FIND _Connect NO-LOCK WHERE _Connect._Connect-Usr = _UserTableStat._UserTableStat-Conn NO-ERROR. /* beware: you may use _UserTableStat-id + 1 too but do not miss the + 1*/
ELSE RELEASE _Connect.
CREATE ttuts.
BUFFER-COPY _UserTableStat TO ttuts.
IF AVAIL _Connect
THEN BUFFER-COPY _Connect TO ttuts.
END.
DEFAULT-WINDOW:TITLE = SUBSTITUTE("&1 - Scan completed in &2 ms through &3 _UserTableStat records (started at &4)"
, NOW, INTERVAL(NOW, dstart, "milliseconds"), iusertablestat, dstart).
FOR EACH ttuts
, FIRST _File NO-LOCK WHERE _File._File-Number = ttuts._UserTableStat-Num
BY ttuts._UserTableStat-read DESCENDING:
DISPLAY
ttuts._UserTableStat-Num
_File._File-Name
ttuts._Connect-Name
ttuts._UserTableStat-Conn /* = _Connect._Connect-Usr */
ttuts._Connect-Type
ttuts._Connect-Time
ttuts._Connect-ClientType
ttuts._UserTableStat-read FORMAT ">>>,>>>,>>>,>>>,>>9"
ttuts._UserTableStat-update FORMAT ">>>,>>>,>>>,>>>,>>9"
ttuts._UserTableStat-create FORMAT ">>>,>>>,>>>,>>>,>>9"
ttuts._UserTableStat-delete FORMAT ">>>,>>>,>>>,>>>,>>9"
WITH WIDTH 240 FRAME fttuts 17 DOWN.
END.