4

I'm trying to write some testing programs and I have an idea to run a procedure, and have the procedure call internal functions and procedures in the calling program. As I understand it, you can use RUN x IN y where y is any procedure in the calling stack.

However, I can't seem to find any way of getting the handle for the calling procedure. There doesn't seem to be a means of moving up the call stack.

The only way I can think of doing it is by passing the calling procedure's THIS-PROCEDURE handle as a parameter. It would work, but seems rather inelegant.

Screwtape
  • 1,337
  • 2
  • 12
  • 27

2 Answers2

2

You are almost there. Take a look at the example below utilizing the THIS-PROCEDURE:INSTANTIATING-PROCEDURE handle.

INSTANTIATING-PROCEDURE attribute

Returns the handle to the procedure in which an object was instantiated.

parentProgram.p

RUN childProgram.p.

PROCEDURE hello:
    DEFINE INPUT  PARAMETER pcMessage AS CHARACTER   NO-UNDO.
    MESSAGE "Child says:" pcMessage VIEW-AS ALERT-BOX INFORMATION.
END.

childProgram.p

MESSAGE "Calling parent. Anybody home?" VIEW-AS ALERT-BOX.

IF VALID-HANDLE(THIS-PROCEDURE:INSTANTIATING-PROCEDURE) THEN
    RUN hello IN THIS-PROCEDURE:INSTANTIATING-PROCEDURE (INPUT "I am your child") NO-ERROR.
IF ERROR-STATUS:ERROR THEN DO:
    MESSAGE "That didn't work" VIEW-AS ALERT-BOX ERROR.
END.
Community
  • 1
  • 1
Jensd
  • 7,886
  • 2
  • 28
  • 37
  • That was just what I was looking for, and I would have found it if I had the right version of the documentation. Turns out I've been using the Openedge 10 docs rather then the current ones. – Screwtape Apr 30 '15 at 12:27
1

To get the handle of the calling procedure, use the SOURCE-PROCEDURE handle. It has the handle for the last procedure call. If another procedure is run, then it will change to match that procedure instance's handle, so if you need your program to remember who called it, your code'll need to store that value immediately when it's called.

Tim Kuehn
  • 3,201
  • 1
  • 17
  • 23