2

I have found an article, about accessing temp-table that is declared inside the class, from outside the class. I'm trying to use 2nd solution(using handles and buffer). And while it works(i can get 1st or last element from it), i can't find a way to iterate through full temp-table.

Thank you.

Deniss
  • 317
  • 2
  • 12
  • You should post your code! That will make it easier for people to help! – Jensd Mar 31 '16 at 08:54
  • @Jensd, i'm using the same code as in the article i have posted(2nd solution), just trying to modify it so it would show me the whole temp-table. – Deniss Mar 31 '16 at 09:39

1 Answers1

3

You could do it by creating a dynamic query and attaching it to the buffer handle:

Class2.cls looks exactly the same, if added it below for reference.

Test2.p is changed:

DEF VAR c-class2 AS Class2.

DEF VAR local-ttbuf-hdl AS HANDLE.
DEF VAR tt-def-buff AS HANDLE.

c-class2 = NEW Class2().
local-ttbuf-hdl = c-class2:GetTempTableHandle().
tt-def-buff = local-ttbuf-hdl:DEFAULT-BUFFER-HANDLE.


/*
/* Find last is commented out */
tt-def-buff:FIND-LAST().

MESSAGE tt-def-buff:BUFFER-FIELD(1):buffer-value SKIP
        tt-def-buff:BUFFER-FIELD(2):buffer-value
        VIEW-AS ALERT-BOX.

*/

/**** New code here ****/
/* Define and create a dynamic query */
DEFINE VARIABLE hQuery AS HANDLE      NO-UNDO.
CREATE QUERY hQuery.

/* Set the buffer */
hQuery:SET-BUFFERS(tt-def-buff).

/* Create a query-string */
hQuery:QUERY-PREPARE("FOR EACH " + tt-def-buff:NAME).

/* Open the query */
hQuery:QUERY-OPEN.


REPEAT :

    /* Get the next record, for the first run it will be the first record */
    hQuery:GET-NEXT().

    /* Leave the repeat if there are no more records */
    IF hQuery:QUERY-OFF-END THEN LEAVE.

    /* Display */
    MESSAGE tt-def-buff:BUFFER-FIELD(1):buffer-value SKIP
            tt-def-buff:BUFFER-FIELD(2):buffer-value
            VIEW-AS ALERT-BOX.

END.

/* All created objects should be deleted */
DELETE OBJECT hQuery.

Class2.cls:

CLASS class2:
   DEF VAR i AS INTEGER.
   DEF TEMP-TABLE tt
          FIELD i1 AS INTEGER
          FIELD c1 AS CHARACTER.

   CONSTRUCTOR class2():
        DO i = 1 TO 10:
             CREATE tt.
             ASSIGN
                 tt.i1 = i
                 tt.c1 = STRING(i).
        END.
   END CONSTRUCTOR.

   METHOD PUBLIC HANDLE GetTempTableHandle():
        RETURN TEMP-TABLE tt:HANDLE.
   END.
END CLASS.
Jensd
  • 7,886
  • 2
  • 28
  • 37