morpheus
28th February 2003, 08:08
Hello,
From my program script, I am passing a value into a customized include function. The function in which I am passing the value, contains "n" functions, and further these functions contain more functions. Now, the value being passed is only available in the first function, whereas I need that variable in all the functions, i.e., I want it to be a global variable.
One way is to keep on passing the variable in every function call, but I do not want that.
Any solutions...!?

NPRao
28th February 2003, 08:39
You must declare a variable with the keyword EXTERN if that variable is used within other programs, within forms (field names and variables within expressions), or within the function expr.compile(). If the functions get.var() and put.var() are used within the program, the variables in the other program must be declared as EXTERN.


Refer to - Declarations (http://www.baanboard.com/programmers_manual_baanerp_help_functions_expressions_runtime_expr_compile)

morpheus
28th February 2003, 09:04
Dear NPR,
Thanks for the reply.
The variable is defined as an EXTERN. The argument I am passing from the program script into the include function, is item code. In function A, it is working as local variable.

function A(domain tcitem item)
{
function B()
function C()
...
...
}

Now, when the control goes to function B, then this local variable "item" is not available, whereas the global variable "item" is available, and that is blank!!

I hope it is much clear now.

RobertB
28th February 2003, 09:38
Hi,

You have two options: pass the variable as function arguments between the various functions - but you're not keen on that - or declare a global variable somewhere in your include script and set the value of that variable equal to the incoming item argument in your functionA().

I'm sure you're aware that simple variable declaration (domain tcitem my.global.item) outside of a function block makes that variable global to all functions following the declaration, whereas declaring it as external anywhere in your script makes it global to the whole script.An external variable is declared outside the function blocks. You can use them in all functions that occur after the variable declaration, and also in other programs (for example, forms, reports, and runtime expressions). It is possible to declare external variables within a function block but this is not recommended.Have a good one!

morpheus
28th February 2003, 11:17
Second option makes sense!!
;)