I was wondering if anyone had any code samples of generating a dynamic temp-table from an imported csv file?
I was using a sample from the KB but i keep getting a buffer-field erorr and plus i don't know how to set it up when i am creating a dynamic temp table that is unlike any other table in the database.
This example uses the create-like and uses customer. Is there a way i can just create one that isn't like any other table.
I was using a sample from the KB but i keep getting a buffer-field erorr and plus i don't know how to set it up when i am creating a dynamic temp table that is unlike any other table in the database.
This example uses the create-like and uses customer. Is there a way i can just create one that isn't like any other table.
Code:
DEFINE VARIABLE hDynamicTempTable AS HANDLE NO-UNDO.
DEFINE VARIABLE hRecordBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hFieldBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE iConter AS INTEGER NO-UNDO.
DEFINE VARIABLE cRecord AS CHARACTER NO-UNDO.
DEFINE VARIABLE cDelimiter AS CHARACTER NO-UNDO INITIAL ",".
DEFINE VARIABLE cTrimCharacter AS CHARACTER NO-UNDO INITIAL " ".
ASSIGN
cDelimiter = CHR(44) /* comma */
cTrimCharacter = CHR(32). /* Space */
CREATE TEMP-TABLE hDynamicTempTable.
hDynamicTempTable:CREATE-LIKE("customer").
hDynamicTempTable:TEMP-TABLE-PREPARE("hDynTTName").
hRecordBuffer = hDynamicTempTable:DEFAULT-BUFFER-HANDLE.
INPUT FROM Customer.csv.
OuterRepeat:
REPEAT:
IMPORT UNFORMATTED cRecord.
DO TRANSACTION:
hRecordBuffer:BUFFER-CREATE().
REPEAT iConter = 1 TO NUM-ENTRIES(cRecord, cDelimiter) ON ERROR UNDO, LEAVE OuterRepeat:
ASSIGN
hFieldBuffer = hRecordBuffer:BUFFER-FIELD(iConter)
hFieldBuffer:BUFFER-VALUE = TRIM(ENTRY(iConter, cRecord, cDelimiter), cTrimCharacter).
END.
END.
END.