I happen to have a debugging procedure that can receive the handle of a query, buffer or temp-table and spit out its contents to a log file. Recently, I added support for datasets ( which was actually around 5 lines of code), but how am I supposed to call this procedure?
My procedure requires a parameter of type HANDLE and is normally called via a publish statement like:
PUBLISH 'publishTable' (INPUT TEMP-TABLE ttCustomer:HANDLE ). /* fixed after remark */
But for a dataset, this does not work. I do have 2 workarounds though:
/* Does not work */ PUBLISH 'publishTable' (INPUT DATASET dsData:HANDLE ). /* Works */ DEFINE VARIABLE h AS HANDLE NO-UNDO. h = DATASET dsData:HANDLE. PUBLISH 'publishTable' (INPUT h ). /* Works */ PUBLISH 'publishTable' (INPUT HANDLE(STRING(DATASET dsData:HANDLE)) ).
But the latter two seem a bit clumsy. Is is possible to do it in one step, elegantly?
First I am assuming the temp-table example above is actually INPUT TEMP-TABLE ttCustomer:HANDLE.
The syntax for INPUT DATASET is expecting a dataset name. Jut add parenthesis around what in your case is an expression. This should give you what you want.
(INPUT (DATASET dsData:HANDLE))
/* Does not work */
PUBLISH 'publishTable' (INPUT DATASET dsData:HANDLE ).
First I am assuming the temp-table example above is actually INPUT TEMP-TABLE ttCustomer:HANDLE.
The syntax for INPUT DATASET is expecting a dataset name. Jut add parenthesis around what in your case is an expression. This should give you what you want.
(INPUT (DATASET dsData:HANDLE))
Just use the suggestion of Fernando
DEFINE TEMP-TABLE tt NO-UNDO
FIELD a AS CHARACTER.
DEFINE DATASET dsData FOR tt.
PROCEDURE publishTable :
DEFINE INPUT PARAMETER iph AS HANDLE NO-UNDO.
END PROCEDURE.
RUN publishTable(INPUT (DATASET dsData:HANDLE)).
Thanks, it works like a charm!
Although it works, I agree with Peter that it smells like a bug.
Stronger: I think it /is/ a bug and I have logged case #00356867 with progress for this.
This is not entirely true and I beg to differ :)
If you look at
RUN foo (INPUT DATASET myDataset:HANDLE ).
It is perfectly clear for the compiler that it is a HANDLE that is passed to the procedure. That is because the word 'HANDLE' is added. There is a difference in passing the table as a whole or the handle and we are doing the latter here. Stronger, if you try to pass the handle when the procedure is expecting the table, you will get a runtime error.
Try this:
DEFINE TEMP-TABLE ttData FIELD cField AS CHARACTER. CREATE ttData. ttData.cField = 'Hello world'. RUN bar(INPUT TEMP-TABLE ttData:HANDLE). PROCEDURE bar: DEFINE INPUT PARAMETER TABLE FOR ttData. FIND FIRST ttData. MESSAGE ttData.cField VIEW-AS ALERT-BOX INFO BUTTONS OK. END PROCEDURE.