Table and Field passing

Touf

New Member
hi
I hope someone can help me I want to pass through the table and field name from 1 program to another
but I seem to constantly get the error "Unknown or ambiguous table lvtable"

below is the programs I created

Prog1:
def var lvtable as char.
def var lvfield as char.

for each _file
,
first _field of fifaman._file
where _field._field-name matches "*company"
:

assign lvtable = _file._file-name
lvfield = _field._field-name.
{tables.p lvtable lvfield }

end.

Prog2:
for each {1}:
display {1}.{2} .
end.

What am I doing wrong?
 
Your are mixing the concept of variables with the concept of pre-processor directives.
  1. Pre-processor directives get resolved at compile time _NOT_ at run time!
  2. Pre-processor arguments are always literal text not variables that get resolved. That means at compile time the arguments get replaced with the variable name and not the content of the variable.
IMHO, you should use dynamic objects to achieve your goal instead of fiddling with include file technique. But as you don't say anything about your Progress version it could be possible that you are working with one that does not support dynamic queries.

Regards, RealHeavyDude.
 
You need to be aware: In order for your clients to be able to run this they need to purchase development licenses instead of runtime linceses. There is no way this "compile-on-the-fly" approach will work with a runtime license as it does not contain the compiler ...

Regards, RealHeavyDude.
 
As RHD stated, you need to have development licenses for clients in order to do this as you wish... but just in case they do have the development license, here is how you can easily do it using that development license by having one piece of code write the other for you:

Code:
def var lvtable as char.
def var lvfield as char.
def stream a.
output stream a to value("my.p").

for each _file NO-LOCK,
    first _field of fifaman._file NO-LOCK
    where _field._field-name matches "*company":
    
    assign lvtable = _file._file-name
                     lvfield = _field._field-name.
    put stream a unformatted
      "for each " lvtable " NO-LOCK:" skip
      "display " lvtable "." lvfield "." skip
      "end."
output stream a close.
run my.p.
end.
If nothing else, you could generate the .p in a directory changing the name to something unique, then xcode and compile them on the run-time environments, then create a .p that runs the correct .p based on the field you want to display or whatever.

But to reiterate RHD's advice.... you cannot run generated source code without the correct license.

As a side note/caveat/best practice: unless you plan on updating, always make sure to use NO-LOCK on tables. If you plan on updating, use EXCLUSIVE-LOCK. Progress default is shared locking, which can cause all sorts of bad things to happen.
 
But, as noted, the right answer here, with any version of Progress from 9.0 and above, is to use dynamic queries. That's what they are there for.
 
Back
Top