Hi,
I am new with table handles and I am trying to write a procedure which will generate a dump of a temp table as a csv file, passed into it as a parameter.
The above code obviously dumps the first record of the temp-table. I am unable to loop over each record of the temp-table and dump the complete table. Please help.
Thanks in advance!
I am new with table handles and I am trying to write a procedure which will generate a dump of a temp table as a csv file, passed into it as a parameter.
Code:
Define Temp-table TT_1
Fields f1 As Char
Fields f2 As Char
.
Define Variable i As Integer No-undo.
Do i = 1 To 2:
Create TT_1.
Assign TT_1.f1 = "test1"
TT_1.f2 = "test2"
.
End.
Run GenerateReport (Input Temp-table TT_1:Handle).
Procedure GenerateReport:
Define Input Parameter hTable As Handle No-undo.
Define Variable hBuffer As Handle No-undo.
Define Variable i As Integer No-undo.
hBuffer = hTable:default-buffer-handle No-error.
If Not Valid-handle (hBuffer) Then Return Error.
Output To "C:\Test.csv".
/*--Creating Report Header--*/
Repeat i = 1 To hbuffer:Num-fields:
Put Unformatted Trim (hBuffer:Buffer-field(i):Name) ",".
End.
Put Skip.
/*--Creating Report Body--*/
hbuffer:Find-first ('', No-lock) No-error.
Repeat i = 1 To hbuffer:Num-fields:
If Not hBuffer:Available Then Return.
Put Unformatted hBuffer:Buffer-field(i):Buffer-value.
If i = hbuffer:Num-fields Then
Do:
Put Skip.
End.
Else
Do:
Put Unformatted ",".
End.
End.
Output Close.
End Procedure.
The above code obviously dumps the first record of the temp-table. I am unable to loop over each record of the temp-table and dump the complete table. Please help.
Thanks in advance!