dynamic temp-table evaluating an expression

terry9636

New Member
I am looking to write code that generates output based on user-define values and formatting. I am using a dynamic query with dynamic temp-tables. I will be storing format statements, fill() expressions, if..then..else, etc as it is user defined. I am having difficulty getting the code to evaluate the expression before writing the output.

In the following code, I want to export the value of "1" or "2" for field "Y" rather than exporting the if/then. Any help would be appreciated. Also attached procedure.

/* handle for dynamic temp-table */
DEF VARIABLE hTTCheck AS HANDLE NO-UNDO.
CREATE TEMP-TABLE httCheck.
httCheck:ADD-NEW-FIELD ("x", "logical").
httCheck:ADD-NEW-FIELD ("y", "character").
hTTCheck:TEMP-TABLE-PREPARE("ttCheck").
DEFINE VARIABLE hTTBuf AS HANDLE NO-UNDO.
hTTBuf = hTTCheck:DEFAULT-BUFFER-HANDLE.


hTTBuf:BUFFER-CREATE().
hTTBuf:BUFFER-FIELD("x"):BUFFER-VALUE = TRUE.
hTTBuf:BUFFER-FIELD("y"):BUFFER-VALUE = "(if x = true then 1 else 2)".
hTTBuf:BUFFER-CREATE().
hTTBuf:BUFFER-FIELD("x"):BUFFER-VALUE = FALSE.
hTTBuf:BUFFER-FIELD("y"):BUFFER-VALUE = "(if x = true then 1 else 2)".
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
CREATE QUERY hQuery.
hQuery:SET-BUFFERS(hTTBuf).
hQuery:QUERY-PREPARE("FOR EACH ttCheck").
hQuery:QUERY-OPEN().
hQuery:GET-FIRST().
REPEAT WHILE NOT hQuery:QUERY-OFF-END:

PUT UNFORMATTED httBuf:BUFFER-FIELD("x"):BUFFER-VALUE
httBuf:BUFFER-FIELD("y"):BUFFER-VALUE.
hQuery:GET-NEXT().
END.
httBuf:buffer-release().
hquery:query-close().

/* clean up objects to free resources */
delete object hquery.
delete object httCheck.
 

Attachments

Change
Code:
"(if x = true then 1 else 2)".
and
"(if x = false then 1 else 2)".
for

Code:
string(hTTBuf:BUFFER-FIELD("x"):BUFFER-VALUE,'1/2')

Casper.
 
I need to be liittle more explicit in what I am trying to accomplish.
I would like to store tt.y = "string(month(today)) + string(day(today))" or
i might want tt.y = "<dbtable.fieldname> format "99999""
or tt.y might need to be "space(40) + <dbfield> format "X"".

So it needs to evaluate the expression at run-time to make the logic flexible.

Unless someone has a better way of doing all this. What am trying accomplish is we would like to develope one report/process that is capable of producing output in an infinitite number of ways to support different formats for different vendors. Rather than modifying the code each we add a vendor, we just need to modify the table storing the values.

-- Hope this helps
 
You mean you need something like the eval(function)...

Hmm, that is going to be a problem I'm afraid....

We use javascript to do logical evalutions. Our customers have the possibility to make there own set of conditions to perfrom actions on some parts of the database. We store this stuff in the database as string values. When we process these so called conditions, which can be anything from values of fields to mathematical calculations (total > somelimit in db) we feed these strings to javascript which returns true or false. And depending on the outcome some actions are taking/or not or a new condition is being processed.

Regards,

Casper.
 
Back
Top