temp-table handles

whwar9739

Member
Let's see if I can make this 'as clear as mud'.

I have a temp-table with a structure similar to the following:

Code:
def temp-table tt-table no-undo
   field name1 as char
   field addr1   as char
   field city1     as char
   field state1   as char
   field zip1      as char
   field name2  as char
   field addr2    as char
   field city2      as char
   field state2    as char
   field zip2       as char.

What I am trying to do, is set name, addr, city, state, zip, in a loop of sorts. But since they are not, and for this application, cannot, have extents, the best possible solution I have come up with is to use handles.

Code:
def var name as handle no-undo.
def var addr as handle no-undo.
def var city as handle no-undo.
def var state as handle no-undo.
def var zip as handle no-undo.

Then while in my loop I was hoping to use a procedure to set the handles dynamically.

Code:
procecure set_handle:
   name = tt-table:BUFFER-FIELD("name" + STRING(l-idx))
   etc....
end procedure.

I have created tt-table as a variable of type, handle. Currently I am getting the following 2 errors:
"Invalid handle. Not Initialized or points to a deleted object. (3135)"
"Cannot access the BUFFER-FIELD attribute because the widgest does not exist. (3140)"

Let me know if you need more information.
Any help would be greatly appreciated.
 
You need to define a handle for your table tt-table.

def var hTT as handle no-undo.

Initialize the handle.

hTT = buffer tt-table:handle.

Access your fields:

def var hName as handle no-undo.

hName = hTT:buffer-field(substitute("&1&2","name",l-idx)):handle.

I suggest that you change your handle variable names to be better defined. For example: variable "name" should be "hName". A variable with "name" is very confusing. Try indicating the data-type as the first character (i = integer, c = character, d = decimal, etc).

This should get you started.

Later
 
Fully intend on better variables, this was just quick code for example purposes, but thanks for the tip.

I will give this a try, i tried something similar but it didn't seem to work.
 
BUFFER-FIELD is not table Object method, it is Buffer Object Method.

Here is example a little harder than you need, maybe it helps.

define variable sQuery as character.
DEFINE VARIABLE hQueryData AS HANDLE NO-UNDO.
DEFINE VARIABLE hbuf AS HANDLE NO-UNDO.

define buffer document2 for system.document.
define buffer typedoc2 for system.typedoc.
define buffer applicat2 for system.applicat.
define buffer ctg-division2 for system.ctg-division.
define buffer vis-divisions2 for vis-divisions.

DocumentData:TEMP-TABLE-PREPARE ("DocumentData").
CREATE BUFFER hBuffer FOR TABLE DocumentData:DEFAULT-BUFFER-HANDLE.
CREATE QUERY hQuery.
hQuery:SET-BUFFERS(hBuffer).
fieldcount = hBuffer:NUM-FIELDS.

sQuery = "FOR EACH document2 use-index i-id NO-LOCK where ".
sQuery = sQuery + " document2.put-off = " + STRING (PutOff).
sQuery = sQuery + " AND document2.rid-ent = " + STRING (rid-ent).
IF RidTypedoc <> ? THEN
sQuery = sQuery + " AND document2.rid-typedoc = " + STRING (RidTypedoc).
IF RidApp <> ? THEN
sQuery = sQuery + " AND document2.rid-app = " + STRING (RidApp).
sQuery = sQuery + " AND document2.date-doc > DATE('" + STRING (DateFrom, "99/99/9999") + "')" +
" AND document2.date-doc < DATE('" + STRING (DateTo, "99/99/9999") + "')".
IF RecID-user <> ? THEN
sQuery = sQuery + " AND document2.close-doc = " + STRING (RecID-user).
sQuery = sQuery + ", EACH applicat2 OF document2 NO-LOCK, " +
" EACH ctg-division2 OF document2 NO-LOCK, " +
" EACH typedoc2 OF document2 NO-LOCK, " +
" EACH vis-divisions2 WHERE document2.rid-division = vis-divisions2.rid-div".

CREATE QUERY hQueryData.
hQueryData:FORWARD-ONLY = true.
hQueryData:SET-BUFFERS (BUFFER document2:HANDLE,
BUFFER applicat2:HANDLE,
BUFFER ctg-division2:HANDLE,
BUFFER typedoc2:HANDLE,
BUFFER vis-divisions2:HANDLE).
hQueryData:QUERY-PREPARE(sQuery).
hQueryData:QUERY-OPEN.
hQueryData:GET-FIRST ().

repeat:
if hQueryData:QUERY-OFF-END then leave.

MaxRecCount = MaxRecCount - 1.
if MaxRecCount < 0 then leave.

run AddRecord2.

hQueryData:GET-NEXT ().
END.

PROCEDURE AddRecord2:
hBuffer:BUFFER-CREATE().

hBuffer:BUFFER-FIELD("IdDoc"):BUFFER-VALUE = document2.id-document.
hBuffer:BUFFER-FIELD("DateDoc"):BUFFER-VALUE = STRING(document2.date-doc, "99/99/9999").
hBuffer:BUFFER-FIELD("DateDoc1"):BUFFER-VALUE = document2.date-doc.
hBuffer:BUFFER-FIELD("SumDoc"):BUFFER-VALUE = STRING(document2.sum-doc, "->>>,>>>,>>>,>>9.99").
hBuffer:BUFFER-FIELD("Error"):BUFFER-VALUE = document2.error.
hBuffer:BUFFER-FIELD("KeepDoc"):BUFFER-VALUE = document2.keep-doc.
hBuffer:BUFFER-FIELD("NeedToCalc"):BUFFER-VALUE = document2.NeedToCalc.
hBuffer:BUFFER-FIELD("Exect"):BUFFER-VALUE = document2.exect.
hBuffer:BUFFER-FIELD("filled"):BUFFER-VALUE = document2.filled.
hBuffer:BUFFER-FIELD("Descr"):BUFFER-VALUE = document2.descr-opr.
hBuffer:BUFFER-FIELD("App"):BUFFER-VALUE = applicat2.compres-name.
hBuffer:BUFFER-FIELD("Division"):BUFFER-VALUE = ctg-division2.code-division.
hBuffer:BUFFER-FIELD("RidDocument"):BUFFER-VALUE = document2.rid-document.
hBuffer:BUFFER-FIELD("RidTypedoc"):BUFFER-VALUE = document2.rid-typedoc.
hBuffer:BUFFER-FIELD("TypedocName"):BUFFER-VALUE = "(" + STRING(typedoc2.id-typedoc) + ") " + typedoc2.name-typedoc.

numfiles = 0.
for each system.doc-files NO-LOCK WHERE system.doc-files.rid-file-list = document2.rid-file-list:
numfiles = numfiles + 1.
end.
hBuffer:BUFFER-FIELD("DocFiles"):BUFFER-VALUE = numfiles.

if RidTypedoc <> ? then
do:
DO j = 1 TO fieldcount:
hBufferField = hBuffer:BUFFER-FIELD(j).
if hBufferField:Name begins "Field" then
do:
rid-ff = integer(substring (hBufferField:Name,6)).
FIND system.doc-field-data WHERE system.doc-field-data.rid-document = document2.rid-document
AND system.doc-field-data.rid-ff = rid-ff NO-LOCK NO-ERROR.
IF AVAILABLE system.doc-field-data then
do:
run src/kernel/strtofrm.p ( rid-ff, system.doc-field-data.field-value, "" ).
hBufferField:BUFFER-VALUE = RETURN-VALUE.
end.
else
hBufferField:BUFFER-VALUE = "".
end.
END.
end.
END.
 
Back
Top