I'm using Progress 12.8 to create a custom class that will work as an object to communicate our system into some APIs for another web system.
The program itself is already working, but now I'm doing some work to optimize the code.
My questions is: Is possible to iterate thru all temp-tables inside the class without having to call each one individually?
I know that from a regular table, we can consume _FILE table
For example, this is what I'm doing:
// ----- TEMP TABLES
DEFINE TEMP-TABLE TT-PartNumber NO-UNDO SERIALIZE-NAME "2"
FIELD TT-Code AS CHARACTER SERIALIZE-NAME "code"
FIELD TT-Name AS CHARACTER SERIALIZE-NAME "name".
DEFINE TEMP-TABLE TT-DownTime NO-UNDO SERIALIZE-NAME "3"
FIELD TT-Cell AS CHARACTER SERIALIZE-NAME "cell"
FIELD TT-InitialDate AS CHARACTER SERIALIZE-NAME "initialDate"
FIELD TT-EndDate AS CHARACTER SERIALIZE-NAME "endDate".
// Function that gets each table
METHOD PUBLIC VOID UploadData():
FOR FIRST TT-PartNumber NO-LOCK:
LoadTableJSON(INPUT TEMP-TABLE TT-PartNumber:HANDLE,
INPUT TRUE).
END.
// -----
FOR FIRST TT-DownTime NO-LOCK:
LoadTableJSON(INPUT TEMP-TABLE TT-DownTime:HANDLE,
INPUT TRUE).
END.
END METHOD.
// -----
METHOD PRIVATE CHARACTER LoadTableJSON(INPUT hTable AS HANDLE,
INPUT lUpload AS LOGICAL):
DEFINE VARIABLE cTableName AS CHARACTER NO-UNDO.
DEFINE VARIABLE iTableID AS INTEGER NO-UNDO.
DEFINE VARIABLE lcJson AS LONGCHAR NO-UNDO.
DEFINE VARIABLE cResult AS CHARACTER NO-UNDO.
ASSIGN cTableName = hTable:NAME
iTableID = INT(hTable:SERIALIZE-NAME).
WriteLog(SUBSTITUTE("Processing &1", cTableName)).
hTable:WRITE-JSON("LONGCHAR", lcJson, TRUE).
ASSIGN cResult = TransformJSON(STRING(lcJson)).
WriteLog(SUBSTITUTE("JSON Loaded - &1", cResult)).
IF lUpload THEN
PostData(INPUT cResult, INPUT iTableID).
WriteLog("Processing Finished").
END METHOD.
The problem with this, is that for each new table I would need to modify the UploadData to include new ones.
Is there more of an automatic way to do this? Thanks!
I'm using Progress 12.8 to create a custom class that will work as an object to communicate our system into some APIs for another web system.
The program itself is already working, but now I'm doing some work to optimize the code.
My questions is: Is possible to iterate thru all temp-tables inside the class without having to call each one individually?
I know that from a regular table, we can consume _FILE table
For example, this is what I'm doing:
// ----- TEMP TABLES
DEFINE TEMP-TABLE TT-PartNumber NO-UNDO SERIALIZE-NAME "2"
FIELD TT-Code AS CHARACTER SERIALIZE-NAME "code"
FIELD TT-Name AS CHARACTER SERIALIZE-NAME "name".
DEFINE TEMP-TABLE TT-DownTime NO-UNDO SERIALIZE-NAME "3"
FIELD TT-Cell AS CHARACTER SERIALIZE-NAME "cell"
FIELD TT-InitialDate AS CHARACTER SERIALIZE-NAME "initialDate"
FIELD TT-EndDate AS CHARACTER SERIALIZE-NAME "endDate".
// Function that gets each table
METHOD PUBLIC VOID UploadData():
FOR FIRST TT-PartNumber NO-LOCK:
LoadTableJSON(INPUT TEMP-TABLE TT-PartNumber:HANDLE,
INPUT TRUE).
END.
// -----
FOR FIRST TT-DownTime NO-LOCK:
LoadTableJSON(INPUT TEMP-TABLE TT-DownTime:HANDLE,
INPUT TRUE).
END.
END METHOD.
// -----
METHOD PRIVATE CHARACTER LoadTableJSON(INPUT hTable AS HANDLE,
INPUT lUpload AS LOGICAL):
DEFINE VARIABLE cTableName AS CHARACTER NO-UNDO.
DEFINE VARIABLE iTableID AS INTEGER NO-UNDO.
DEFINE VARIABLE lcJson AS LONGCHAR NO-UNDO.
DEFINE VARIABLE cResult AS CHARACTER NO-UNDO.
ASSIGN cTableName = hTable:NAME
iTableID = INT(hTable:SERIALIZE-NAME).
WriteLog(SUBSTITUTE("Processing &1", cTableName)).
hTable:WRITE-JSON("LONGCHAR", lcJson, TRUE).
ASSIGN cResult = TransformJSON(STRING(lcJson)).
WriteLog(SUBSTITUTE("JSON Loaded - &1", cResult)).
IF lUpload THEN
PostData(INPUT cResult, INPUT iTableID).
WriteLog("Processing Finished").
END METHOD.
The problem with this, is that for each new table I would need to modify the UploadData to include new ones.
Is there more of an automatic way to do this? Thanks!
Share Improve this question asked Mar 12 at 16:53 Raphael FreiRaphael Frei 4382 silver badges14 bronze badges1 Answer
Reset to default 3Unfortunately not. OpenEdge does not provide a way to reflect through temp-tables defined in a class as runtime.
But inside the classes constructor or elsewhere, you could build an array (extent) of the temp-table handles and iterate over that.
DEFINE VARIABLE hTempTables AS HANDLE EXTENT NO-UNDO.
EXTENT (hTempTables) = 2.
ASSIGN hTempTables[1] = TEMP-TABLE TT-PartNumber:HANDLE
hTempTables[2] = TEMP-TABLE TT-DownTime:HANDLE.
From there on you should be able to code everything dynamically, including the queries.