MakamArun
6th March 2002, 13:25
Hi

I have two variables x = "tiitm001.citg" and y = some value.
I want to know whether i can update tiitm001.citg with the value stored in y.

Some languates allow to do this using some special characters like &&(x) = y which in turn executes as tiitm001.citg = y.

Does baan support something like this??

evesely
6th March 2002, 16:17
You can do this using the expr.compile function. The documentation says this taxes resources, but if you need it, you need it.

You could try something like:

extern long expr_id
extern string x(13), ret_val(20)
extern string y(20)
...
expr_id = expr.compile(x & ":= y")
...
x = "tiitm001.citg"
ret_val = s.expr$(expr_id)
...
expr.free(expr_id)

You must make sure that any variables you use in the expr.compile call are declared as externs. I made some of my variable declarations very general. You can tinker with them as needed. There are also l.expr and d.expr calls for returning longs and doubles.

KlayVessel
7th March 2002, 00:29
An easy way is to use the get.var/put.var functions.

string x(30)
...
x = "tiitm001.citg"
y = some_value
put.var(pid, x, y)

Edited to add...

Remember, all table fields are automatically declared as externs. This solution works for non-table fields that are extens as well.

MakamArun
13th March 2002, 13:58
Hi,
thanks for the code. But, i have some errors.

My code :
extern long expr_id
extern string x(1024), ret_val(1024)
extern string y(1024)
...
y = "ret_val := sprintf$("%s|%s|",tiitm001.item,tiitm001.dsca)"
|above line is build at run time.
expr_id = expr.compile("y")
...
ret_val = s.expr$(expr_id)
|this line is giving ret_val and sprintf$ as unknown expression
...
expr.free(expr_id)

any idea what could be the problem.

evesely
13th March 2002, 16:26
A question and some comments.

Why do you need the expr.compile in this case? If you are just executing the sprintf$() function, you could just code that in a normal statement.

It also looks like you have confused a couple of things. You shouldn't put ret_val in the expression and assign it the value of the s.expr$() function. Perhaps you meant y="x:=...".

expr.compile limits the functions that can be used. sprintf$() is not one of them. If you still want to use expr.compile, try:


x=(some table field; e.g., "tcmcs003.dsca")
y = x & ":=z"
expr_id = expr.compile(y)
...
z = sprintf$(...)
ret_val = s.expr$(expr_id)

Of course, you could use the put.var() method as previously discussed. This seems more elegant (and probably more efficient).