for each _field of _file

Hi all
I have used the "for each _file , each _field of _file" to retrieve field names from dbs many times in the past but have now struck a small problem that has me scratching my head... The "for each _file" returns tables in the current working database only so the question is, if I have multiple databases connected, how do I programatically switch working databases before running the "for each"?
Thanks in advance.
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
In one procedure you can assign the "dictdb" alias to each connected database in turn, and then within your loop (e.g. DO i = 1 to NUM-DBS) call a second procedure that queries the metaschema. The constraint is that you can't assign the alias and reference it within a single procedure.

Example:
Code:
/* dbselect.p */
def var i as int no-undo.

do i = 1 to num-dbs:
  create alias "dictdb" for database value(ldbname(i)).
  run dbinspect.p.
end.


Code:
/* dbinspect.p */
display "database: " ldbname("dictdb").

for each _file no-lock,
    each _field of _file no-lock:
  /* do whatever, for example: */
  display _file._file-name 
          _field._field-name skip.
end.

Is this what you're looking for?
 

Stefan

Well-Known Member
Or (even simpler *) use dynamic queries and qualify the create buffer statements with the database name you want to have.



* assuming this is not your first dynamic query
 
Top