Access parameter values by variable name or handle

Posted by hayesbrad on 02-Aug-2010 07:33

I'm attempting to create code that can be insterted at the top of a procedure to output the contents of the procedure's parameters.  I'd like to keep from hard coding the parameter names each time I do this.

I can access the list of parameter names as follows, is it possible to get the parameter values using those names?

RUN InternalProcedure
  ( INPUT "ParameterValue" ).

PROCEDURE InternalProcedure:
  DEFINE INPUT  PARAMETER ipcParameter AS CHARACTER   NO-UNDO.

  DEFINE VARIABLE cSignature AS CHARACTER   NO-UNDO INIT "".
  DEFINE VARIABLE cParameter AS CHARACTER   NO-UNDO INIT "".
  DEFINE VARIABLE cParamName AS CHARACTER   NO-UNDO INIT "".

  cSignature = THIS-PROCEDURE:GET-SIGNATURE(ENTRY(1,PROGRAM-NAME(1)," ")).
  cParameter = ENTRY(3,cSignature).
  cParamName = ENTRY(2,cParameter," ").

/* Displays "ipcParameter" */
  MESSAGE cParamName
    VIEW-AS ALERT-BOX INFO BUTTONS OK.

END.

Is it possible to get the value by some runtime function or handle?

Brad

All Replies

Posted by Peter Judge on 02-Aug-2010 07:45

hayesbrad wrote:

I'm attempting to create code that can be insterted at the top of a procedure to output the contents of the procedure's parameters.  I'd like to keep from hard coding the parameter names each time I do this.

If you're doing this for debug purposes, you could use ProSpy (run protools/_psplus.w, if you're in Architect or run it from ProTools in Studio). This logs the calls and I believe the input parameters. Can't remember if it logs the output parameters too.

As an alternative, the easiest way might be to write an include that prints out the parameter values, so that it doesn't impact performance at runtime.

Something like the below might work. 

{show_param.i pcparametervalue}

  display "&1=" string(&2).

Usage:

{show_param "ipcParameter" ipcParameter }

Or you could use a static method (DebugUtil:LogParameter(pcName, pcValue).

Extracting the actual display from the procedure/method means you can change how it is displayed or logged easily, and in the latter case, without recompiling the entire application.

-- peter

Posted by hayesbrad on 02-Aug-2010 11:56

Thank you for your response.

An include file is definitely my aim.  My intent though is to have the include file determine the parameter list to output from GET-SIGNATURE(), not have a parameter name passed into it with a hard coded value.  That way the include file can be inserted into a procedure and automatically dump the parameter signature/values at runtime.

I'm able to iterate through the parameter names dynamically, and even output the parameter variable names, I just can't find a way to access the contents of them by the parameter name value.  In my example, I've tried STRING(cParamName) and VALUE(cParamName), none of which will compile.

Posted by Peter Judge on 02-Aug-2010 12:35

I'm able to iterate through the parameter names dynamically, and even output

the parameter variable names, I just can't find a way to access the contents

of them by the parameter name value. In my example, I've tried

STRING(cParamName) and VALUE(cParamName), none of which will compile.

To the best of my knowledge, this is not possible.

-- peter

Posted by hayesbrad on 02-Aug-2010 12:38

I was afraid of that.  Thanks for your input.

Posted by Admin on 03-Aug-2010 00:25

Probably the most reliable method - without touching any line of code would be the LOG-MANAGER option 4GLTrace (like 4GLTrace:4).

You'll receive a line in the client log file for any procedure entry including the parameters and procedure exit including output parameters, return-value and error-status.

This thread is closed