DATASET-HANDLE Guru Needed

rich22

New Member
The code in the two programs below doesn't work like I would expect. I was hoping I could add a temp-table to the dataset, then later add another, etc. I've tried alot of different things but can't seem to get this to work the way I want. I can get the first iteration to add, but 2+ don't take (although I don't get an error). I'm on version 10.2a01. Does input-output dataset-handle really work? Thanks in advance for any ideas.... Rich
*
/* ztestcmd1.p ************************/
def var hdsinout1 as handle no-undo .
RUN ztestsub.p ( INPUT 1, INPUT-OUTPUT DATASET-HANDLE hdsinout1 ).
RUN ztestsub.p ( INPUT 2, INPUT-OUTPUT DATASET-HANDLE hdsinout1 ).
RUN ztestsub.p ( INPUT 3, INPUT-OUTPUT DATASET-HANDLE hdsinout1 ).
def var ibuffer as int no-undo.
def var hbuffer as handle no-undo.
DO iBuffer = 1 TO hdsinout1:NUM-BUFFERS:
hBuffer = hdsinout1:GET-BUFFER-HANDLE(iBuffer).
MESSAGE "In ztestcmd1.p - buffer number:" ibuffer
skip "Valid-Handle?" VALID-HANDLE (hBuffer) view-as alert-box.

IF valid-handle(hbuffer) then do:
message "Buffer Name:" hBuffer:NAME view-as alert-box.
end.

END.

/* program ztestsub.p ***************************/
DEF INPUT PARAMETER pseq AS INT NO-UNDO.
DEF INPUT-OUTPUT PARAMETER DATASET-HANDLE phdsinout1.
DEF TEMP-TABLE ttable1 NO-UNDO
FIELD somefield1 AS CHAR
INDEX i1 somefield1 .
DEF TEMP-TABLE ttable2 NO-UNDO
FIELD somefield2 AS CHAR
INDEX i2 somefield2 .
DEF TEMP-TABLE ttable3 NO-UNDO
FIELD somefield3 AS CHAR
INDEX i3 somefield3 .
IF VALID-HANDLE ( phdsinout1 ) EQ FALSE THEN DO:
CREATE DATASET phdsinout1 .
END.
DEF VAR w_addok AS LOGI INIT FALSE NO-UNDO.
IF pseq EQ 1 THEN DO:
w_addok = phdsinout1:ADD-BUFFER ( "ttable1" ).
END.
IF pseq EQ 2 THEN DO:
w_addok = phdsinout1:ADD-BUFFER ( "ttable2" ).
END.
IF pseq EQ 3 THEN DO:
w_addok = phdsinout1:ADD-BUFFER ( "ttable3" ).
END.
def var ibuffer as int no-undo.
def var hbuffer as handle no-undo.
DO iBuffer = 1 TO phdsinout1:NUM-BUFFERS:
hBuffer = phdsinout1:GET-BUFFER-HANDLE(iBuffer).
MESSAGE "In ztestsub.p - call sequence:" pseq
skip "total num-buffers:" phdsinout1:NUM-BUFFERS
skip "Buffer number:" ibuffer
skip "w_addok?" w_addok
skip "Valid-Handle?" VALID-HANDLE (hBuffer)
view-as alert-box.
END.
/*********************************/
 

FrancoisL

Member
He is not adding the same temp table 3 times. Each time he calls his procedure , he passes the pseq parameter and depending on that value he adds ttable1 , ttable2 and ttable3 ... It weird code but it should work.

Code:
IF pseq EQ 1 THEN DO:
    w_addok = phdsinout1:ADD-BUFFER ( "ttable1" ). 
END.
IF pseq EQ 2 THEN DO:
    w_addok = phdsinout1:ADD-BUFFER ( "ttable2" ). 
END. 
IF pseq EQ 3 THEN DO:
    w_addok = phdsinout1:ADD-BUFFER ( "ttable3" ). 
END.
 
anyway there is a scope where temp-teble lives.
It is subprocedure.
So it should be destoyed on subprocedure exit. Progress delays it and program works random.

it will live if create temptable
add-fields
temp-table-prepare
add to dataset will be used.
 
Top