I think one way of doing it is to define global_userid as a shared variable in some global include file, then make sure the include file is included at the start of all your programs. That way, it is defined once per program and is always available.
Then, your trigger code can access the variable from the code.
So, from my system, I have two include files globuser.i and globusrv.i, with the following code in globuser.i:
&if defined (global_userid) &then
{globusrv.i &new=""}
&else
{globusrv.i &new="new global"}
if global_userid = "" then do:
run uuserid.p (
output global_userid,
output global_username,
output this_dummy,
output this_dummy,
output this_dummy).
if global_username = "" or global_username = "NOT KNOWN" then global_username = global_userid.
end.
Disregarding what uuserid.p does (it takes the username from the O/S), globusrv.i is a small include file that contains definitions of the shared variables:
define {&new} shared variable global_userid as character label "User" no-undo.
define {&new} shared variable global_username as character label "Name" no-undo.
/* etc. */
So, you would put the include file at the start of the program, before the trigger section, that way the variable is always defined, and defined only once in the program so it shouldn't fall over. Something like this:
/* Defines the global_userid */
{globuser.i}
define var filename as char format "x(50)".
filename = "/spool/gac/rout/routtrack" + string(month(today))
+ string(year(today)) + ".txt".
on write of ro_det old buffer bu-ro_det do:
output to value (filename) append.
if bu-ro_det.ro_mch_op <> ro_det.ro_mch_op then
put
global_userid "|"
/* global_userid is already defined above so it should work */
ro_det.ro_routing "|"
ro_det.ro_op "|"
ro_det.ro_start "|"
......................
................
put skip.
output close.
end.
/* End of example */
> I can do a compile without any error message, but when i start my program now, it doesn't come up within
> MFGPRO
> Following error comes up:
> Conflict in extent, datatype, or undo status for shared [23;1Hglobal_userid.
> Same problem when i remove the undo.
That's probably because global_userid is defined somewhere else slightly differently. That's why it is a good idea to store the definition in an include file and call the include file from many programs - the definition does not change. Of course, it means that you have to recompile a lot of programs if you change the include file.
Hope that helps.
Simon