Jump to content
danielbighelini

PROBLEM declaring GLOBAL variables x triggers x SPELL

Recommended Posts

I made a customization in the SDM which included 12.5 Majic two files in the folder (z_functions.spl and z_chg.mod).

The MOD file defines a trigger that calls a function specifies the SPL file.

The file SPL contains GLOBAL variables declared outside of functions. When I run this file SPL through command BOP_CMD, works correctly. But when I call the function through the trigger, global variables are not declared and the function generates an error.

Does anyone have any tips to give me?

Thank you.

Share this post


Link to post
Share on other sites
Please post your code and the error you receive.

I have attached the SPL source files, MOD and error message.

The code is complex because it performs a tracking function relationship of CI's. The difficulty is to make some static variables declared globally work when called by the trigger.

If you can help, I will thank a lot.

err.txt

z_chg.mod.txt

z_identifica_relacionamentos_chg.spl.txt

Share this post


Link to post
Share on other sites

You seem to declare some functions - zs_ics_consultados is where the error is thrown with 'unknown', but you're trying to use the symbol as an attribute.

Functions are usually declared as

typespec func(...) { /* body */ }

so your code doesn't look correct to me (although by using SYNTAX LEGACY you might get away with the declaration).

If the variables are constants, you're better off using DEFINE.

DEFINE CONSTANT_VAR "content"

Do you need to also modify the variable ? Since you're only using a trigger I would advice you to put any modification of objects into the trigger only and have auxiliary methods that don't have side effects. This way the code is simpler to execute and debug.

Share this post


Link to post
Share on other sites
You seem to declare some functions - zs_ics_consultados is where the error is thrown with 'unknown', but you're trying to use the symbol as an attribute.

Functions are usually declared as

typespec func(...) { /* body */ }

so your code doesn't look correct to me (although by using SYNTAX LEGACY you might get away with the declaration).

If the variables are constants, you're better off using DEFINE.

DEFINE CONSTANT_VAR "content"

Do you need to also modify the variable ? Since you're only using a trigger I would advice you to put any modification of objects into the trigger only and have auxiliary methods that don't have side effects. This way the code is simpler to execute and debug.

Unfortunately I was forced to modularize some functions in the code SPELL because it is a recursive routine to control steps to avoid unnecessary duplicate query to the database.

Some variables declared in the code must necessarily be static content, must be within the auxiliary functions and must be declared publicly. This is my difficulty.

Anyway thank you very much your help.

PS.: I tried using constants in the code but they do not work when it is triggered by the trigger.

Edited by Bighelini

Share this post


Link to post
Share on other sites

There is no concept of "global" variables in spel. All spell files are shared for all threads. Imagine your trigger is fired twice at the same time, because two users are doing the same stuff. But you would only have one global variable? How should this work?

That said, in functions, you have to pass in all variables as arguments. Unfortunatley, a function can only have one return parameter. If a function needs to return more than one value, you should work with methods. Methods can be called by send_wait, and can return any number of paramneters by using set_return_data(). The calling method can access the returned parameters through the msg array.

Hope that helps.

Share this post


Link to post
Share on other sites
There is no concept of "global" variables in spel. All spell files are shared for all threads. Imagine your trigger is fired twice at the same time, because two users are doing the same stuff. But you would only have one global variable? How should this work?

That said, in functions, you have to pass in all variables as arguments. Unfortunatley, a function can only have one return parameter. If a function needs to return more than one value, you should work with methods. Methods can be called by send_wait, and can return any number of paramneters by using set_return_data(). The calling method can access the returned parameters through the msg array.

Hope that helps.

Thanks Mike. You give me a good ideia.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...