The Reason
The Reason

Reputation: 7973

How to execute procedure from List with parameters in Progress 4gl?

I have some list like this

DEFINE VARIABLE procedurelist AS CHARACTER EXTENT 5
    INITIAL [ "1.p", "2.p", "3.p", "4.p", "5.p"].

but this all procedures with input-output parameters and i want to execute this procedure, How can i do this? I have no idea how to do this.

Upvotes: 1

Views: 2015

Answers (1)

Jensd
Jensd

Reputation: 8011

The base of your solution is the RUN VALUE statement.

The manual states.

VALUE( extern-expression ) An expression that returns the name of the (local or remote) external procedure you want to run....

This basically means that you can input a string with the value of a program (or procedure) into your RUN statement.

If all input-output parameters are exactly the same you can do like this:

DEFINE VARIABLE procedurelist AS CHARACTER EXTENT 5 INITIAL [ "1.p", "2.p", "3.p", "4.p", "5.p"].

DEFINE VARIABLE iExtent   AS INTEGER     NO-UNDO.
DEFINE VARIABLE cVariable AS CHARACTER   NO-UNDO.

DO iExtent = 1 TO EXTENT(procedurelist):
    RUN VALUE(procedurelist[iExtent]) (INPUT-OUTPUT cVariable).
END.

If the parameters are different it gets trickier (but not impossible). The CREATE CALL and the Call Object can help you there. In this case you would need some kind of way to keep track of the different parameters as well.

Here's a basic example taken directly from the online help:

DEFINE VARIABLE hCall AS HANDLE NO-UNDO. 

CREATE CALL hCall. 
/* Invoke hello.p non-persistently */
hCall:CALL-NAME      = "hello.p".

/* Sets CALL-TYPE to the default */
hCall:CALL-TYPE  = PROCEDURE-CALL-TYPE.
hCall:NUM-PARAMETERS = 1.
hCall:SET-PARAMETER(1, "CHARACTER", "INPUT", "HELLO WORLD").
hCall:INVOKE. 

/* Clean up */
DELETE OBJECT hCall.

Upvotes: 6

Related Questions