global_userid within session trigger

Sonja

New Member
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 global_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



Thanks, i've tried it this way which is very similar to that of Bulkload but i still get the message Duplicate variable name--global_userid.
mfdeclre.i is contained in rwromt.p which i am not allowed to change.

code of mfdeclre.i is:
define {1} shared variable global_userid as character.
 
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 "|"
ro_det.ro_routing "|"
ro_det.ro_op "|"
ro_det.ro_start "|"
......................
................
put skip.
output close.
end.
{rwromt.p}

Any more ideas ?

and ...
Thanks, i've tried it this way which is very similar to that of Bulkload but i still get the message Duplicate variable name--global_userid.
mfdeclre.i is contained in rwromt.p which i am not allowed to change.

code of mfdeclre.i is:
define {1} shared variable global_userid as character.

So, you have an include file mfdeclre.i that defines the variable and is used in a file rwromt.p which you are using as an include file.

What else is in rwromt.p? Should this be an include file or should you be running it as a program? It makes a huge difference.

What is the line containing mfdeclre.i? Is it something like
{mfdeclre.i new} or is it just {mfdeclre.i} ?
Do you want the functionaility of rwromt.p with the trigger added or are you looking at something else?

Have you tried putting the rwromt.p include before the trigger? I don't think it matters where the trigger is in the code, it will still fire (?)

Simon
 

bulklodd

Member
define {1} shared variable global_userid as character.

At last i know all i wanted to :)

As I've already said in that thread http://www.progresstalk.com/showthread.php?t=101527

You can have several global shared variables in the single scope thus all you need to do is to define global_userid before your trigger as new global shared.

Code:
define new global shared variable global_userid as character.
on write of ro_det old buffer bu-ro_det do:
...
end.

HTH
 

Casper

ProgressTalk.com Moderator
Staff member
Sorry to bud in (again), but I don't understand why this is such a problem. Bulklodd (and I) already mentioned preprocessing the program and look where the variables are defined. Just review your code carefully and you will find what causes the error.
 

Sonja

New Member
At last i know all i wanted to :)

As I've already said in that thread http://www.progresstalk.com/showthread.php?t=101527

You can have several global shared variables in the single scope thus all you need to do is to define global_userid before your trigger as new global shared.

Code:
define new global shared variable global_userid as character.
on write of ro_det old buffer bu-ro_det do:
...
end.

HTH

Thanks a lot for your help - bulklodd - it's working now .
Maybe you also have a programming code example which shows me how i can put deleted records into my file ?
 

bulklodd

Member
Maybe you also have a programming code example which shows me how i can put deleted records into my file ?

Maybe I misunderstood your question but nevertheless I'll try

Code:
ON DELETE OF ro_det 
DO:
   OUTPUT TO <filename> APPEND.
   EXPORT ro_det.
   OUTPUT CLOSE.
END.

Thus you need to define the schema trigger where you can keep a deleted record in a file.
 

Sonja

New Member
Maybe I misunderstood your question but nevertheless I'll try

Code:
ON DELETE OF ro_det 
DO:
   OUTPUT TO <filename> APPEND.
   EXPORT ro_det.
   OUTPUT CLOSE.
END.

Thus you need to define the schema trigger where you can keep a deleted record in a file.

Hello,

i am not allowed to use schema triggers. Therefore i try to put the record which was deleted into a file (same as i do for the records which were changed) :

on write of ro_det old buffer bu-ro_det do:
output to value (filename) append.
if bu-ro_det.ro_desc <> ro_det.ro_desc then
put
..... (that's a record which was changed)

???????? (that should be a record which was deleted)

output close.
end.
{rwromt.p}
 

bulklodd

Member
In that case my snippet above will suit. More detailed:

Code:
on delete of ro_det do:
output to value (filename) append.
put 
..... (that's a record which was changed) 
 
???????? (that should be a record which was deleted) 
output close. 
end.
{rwromt.p}

HTH
 

Sonja

New Member
In that case my snippet above will suit. More detailed:

Code:
on delete of ro_det do:
output to value (filename) append.
put 
..... (that's a record which was changed) 
 
???????? (that should be a record which was deleted) 
output close. 
end.
{rwromt.p}

HTH

thanks a lot for your help !! :blush:
 
Top