export table name to internal procedure

BelaB

New Member
Hi!

I want to export a table name to an internal procedure.
S.th. like this:


RUN test ({&table.field}).

PROCEDURE test.

FIND FIRST table WHERE {&table.field} = "progress" NO-LOCK NO-ERROR.
/* etc. */

END PROCEDURE.

And I don't want to create an include. :confused:

Thanks!
 
You can do that using run-time arguments, although you will never be able to precompile the 'test' procedure. Does that matter?

Using the FIND statement means that the DB access is statically defined, and all DB table names and column names are resolved at compile-time.

If you really want to pass any table.field combination as a parameter then your 'test' procedure will need to use dynamic queries.
 

jongpau

Member
Hi,

What version of Progress are you using?

Version 9 allows you dynamic queries, which should solve your problem! See below for some example... not tested ;)
Code:
RUN test (INPUT BUFFER customer:HANDLE,
          INPUT "cust-no":U,
          INPUT "PROGRESS":U).

PROCEDURE test:
  DEF INPUT PARAMETER IPhBuffer AS HANDLE NO-UNDO.
  DEF INPUT PARAMETER IPField   AS CHAR   NO-UNDO.
  DEF INPUT PARAMETER IPValue   AS CHAR   NO-UNDO.

  DEF VAR lhQuery AS HANDLE NO-UNDO.

  IF NOT VALID-HANDLE(IPhBuffer) THEN RETURN.

  CREATE QUERY lhQuery.
  lhQuery:ADD-BUFFER(IPhBuffer).
  lhQuery:QUERY-PREPARE("FOR EACH ":U + IPhBuffer:NAME + " NO-LOCK WHERE ":U + IPField + " EQ '" IPValue + "'":U).
  lhQuery:QUERY-OPEN.
  lhQuery:GET-FIRST(NO-LOCK).
  IF NOT lhQuery:QUERY-OFF-END THEN DO:
    MESSAGE "RECORD FOUND":L VIEW-AS ALERT-BOX.
  END. /* not query-off-end */
  ELSE DO:
    MESSAGE "NO RECORD FOUND":L VIEW-AS ALERT-BOX.
  END. /* query-off-end */
  lhQuery:QUERY-CLOSE.
  DELETE OBJECT lhQuery.
END PROCEDURE.
HTH
 
Top