Topic
  • 5 replies
  • Latest Post - ‏2013-04-06T11:09:37Z by clogs
nick_tn
nick_tn
584 Posts

Pinned topic how to access functions in different packages

‏2013-04-02T13:34:59Z |
i have a service project that contains several packages
servicepkg (project)
  pkg1 (package)
    pgm1 (service pgm)
  pkg2
    pgm2 
  pkg3
    pgm3
  etc...


I want to create a "common" package that contains functions that can be used by other service programs.

Can this be done, and if so, how?
Updated on 2014-03-25T04:34:02Z at 2014-03-25T04:34:02Z by iron-man
  • markevans
    markevans
    2887 Posts

    Re: how to access functions in different packages

    ‏2013-04-02T15:37:19Z  
    Nick,

    I know you can do it with other logic parts (programs, etc).

    so, try by doing this:

    • create a .egl file or files that holds these functions
    • import that file (or package) (e.g. import pkg.common.*;)
    • use the "includeReferencedFunctions=yes" in the properties of the service

    I think that is all that is needed.
  • nick_tn
    nick_tn
    584 Posts

    Re: how to access functions in different packages

    ‏2013-04-02T15:52:34Z  
    • markevans
    • ‏2013-04-02T15:37:19Z
    Nick,

    I know you can do it with other logic parts (programs, etc).

    so, try by doing this:

    • create a .egl file or files that holds these functions
    • import that file (or package) (e.g. import pkg.common.*;)
    • use the "includeReferencedFunctions=yes" in the properties of the service

    I think that is all that is needed.
    I tried as you suggested, but getting cannot resolve error.

    Shared package serviceprj/sharedpkg/sharedpgm path
    
    
    
    package sharedpkg;   service sharedpgm
    {IncludeReferencedFunctions = yes
    } 
    //----------------------------------------- function genericmessage2(funcin string in, userin string in, values string in, exception anyexception in) 
    //-----------------------------------------                                     writeStderr(currenttimestamp()); writeStderr(
    "Function: " + funcin); writeStderr(
    "User: " + userin); writeStderr(
    "Values: " + values); writeStderr(exception.message); end
    


    usage service
    
    
    
    package reportingsvcpkg; 
    
    import sharedpkg.*;   service servicepgm
    {IncludeReferencedFunctions = yes
    } function test() 
    
    try onException(exception AnyException) genericmessage2(
    "a", 
    "b", 
    "c", exception); end end end
    


    I get the following errors:

    genericmessage2("a", "b", "c", exception);
    
    Multiple markers at 
    
    this line - IWN.VAL.6619.e 19/4 servicepgm - genericmessage2 cannot be resolved. At line 19 in file \servicesprj\EGLSource\reportingsvcpkg\servicepgm.egl - IWN.VAL.6619.e 19/24 servicepgm - sharedpkg.sharedpgm.genericmessage2 cannot be resolved. At line 19 in file \servicesprj\EGLSource\reportingsvcpkg \servicepgm.egl
    


    if i qualify it, it actually prompts the parms, but then give me an error.
    sharedpkg.sharedpgm.genericmessage2("a", "b", "c", exception);
    
    IWN.VAL.6619.e 19/24 servicepgm - sharedpkg.sharedpgm.genericmessage2 cannot be resolved. At line 19 in file \servicesprj\EGLSource\reportingsvcpkg\servicepgm.egl
    
  • markevans
    markevans
    2887 Posts

    Re: how to access functions in different packages

    ‏2013-04-03T14:46:19Z  
    • nick_tn
    • ‏2013-04-02T15:52:34Z
    I tried as you suggested, but getting cannot resolve error.

    Shared package serviceprj/sharedpkg/sharedpgm path
    <pre class="jive-pre"> package sharedpkg; service sharedpgm {IncludeReferencedFunctions = yes } //----------------------------------------- function genericmessage2(funcin string in, userin string in, values string in, exception anyexception in) //----------------------------------------- writeStderr(currenttimestamp()); writeStderr( "Function: " + funcin); writeStderr( "User: " + userin); writeStderr( "Values: " + values); writeStderr(exception.message); end </pre>

    usage service
    <pre class="jive-pre"> package reportingsvcpkg; import sharedpkg.*; service servicepgm {IncludeReferencedFunctions = yes } function test() try onException(exception AnyException) genericmessage2( "a", "b", "c", exception); end end end </pre>

    I get the following errors:

    genericmessage2("a", "b", "c", exception);
    <pre class="jive-pre"> Multiple markers at this line - IWN.VAL.6619.e 19/4 servicepgm - genericmessage2 cannot be resolved. At line 19 in file \servicesprj\EGLSource\reportingsvcpkg\servicepgm.egl - IWN.VAL.6619.e 19/24 servicepgm - sharedpkg.sharedpgm.genericmessage2 cannot be resolved. At line 19 in file \servicesprj\EGLSource\reportingsvcpkg \servicepgm.egl </pre>

    if i qualify it, it actually prompts the parms, but then give me an error.
    sharedpkg.sharedpgm.genericmessage2("a", "b", "c", exception);
    <pre class="jive-pre"> IWN.VAL.6619.e 19/24 servicepgm - sharedpkg.sharedpgm.genericmessage2 cannot be resolved. At line 19 in file \servicesprj\EGLSource\reportingsvcpkg\servicepgm.egl </pre>
    Nick,

    There are two ways to reuse a function:

    Invoke it in a common executable

    This means you have to put it inside of a library or service and then invoke that function by invoking it via the name of the library/service . In other words, as "mylib.function(parms);"

    This is the more modern way of doing it in that you create a utility library which is similar to methods within a utility Java class. In this way, if you change the function, only the utility library/service has to be regenerated.

    You also don't need the "includeReferencedFunctions" in this case.

    or

    "Include" it by referencing it

    This is more like an include in C or copy book in COBOL. In this case, by referencing the name, at generation time, the definition is "included" into the part being generated. Any part being generated gets a copy of it included within it and if you change the common function, all of those parts have to be regenerated to pick up the change.

    when you want to include a function, the function definitions are consider top-level functions and you do NOT put them within a generatable part like a service or library.

    In your example below, the function "genericMessage2" would not be within the service sharedPgm ... end, it would just be the source for the function only. You can have multiple functions that are "standalone" (i.e. not inside a library/service)

    Finally,

    a couple of other thoughts...

    • If this shared package is in a different project, remember you have to add this project to the EGL Build path.
    • Do you have build automatically turned off (under the menu item "project").
  • SystemAdmin
    SystemAdmin
    6195 Posts

    Re: how to access functions in different packages

    ‏2013-04-06T08:01:04Z  
    • nick_tn
    • ‏2013-04-02T15:52:34Z
    I tried as you suggested, but getting cannot resolve error.

    Shared package serviceprj/sharedpkg/sharedpgm path
    <pre class="jive-pre"> package sharedpkg; service sharedpgm {IncludeReferencedFunctions = yes } //----------------------------------------- function genericmessage2(funcin string in, userin string in, values string in, exception anyexception in) //----------------------------------------- writeStderr(currenttimestamp()); writeStderr( "Function: " + funcin); writeStderr( "User: " + userin); writeStderr( "Values: " + values); writeStderr(exception.message); end </pre>

    usage service
    <pre class="jive-pre"> package reportingsvcpkg; import sharedpkg.*; service servicepgm {IncludeReferencedFunctions = yes } function test() try onException(exception AnyException) genericmessage2( "a", "b", "c", exception); end end end </pre>

    I get the following errors:

    genericmessage2("a", "b", "c", exception);
    <pre class="jive-pre"> Multiple markers at this line - IWN.VAL.6619.e 19/4 servicepgm - genericmessage2 cannot be resolved. At line 19 in file \servicesprj\EGLSource\reportingsvcpkg\servicepgm.egl - IWN.VAL.6619.e 19/24 servicepgm - sharedpkg.sharedpgm.genericmessage2 cannot be resolved. At line 19 in file \servicesprj\EGLSource\reportingsvcpkg \servicepgm.egl </pre>

    if i qualify it, it actually prompts the parms, but then give me an error.
    sharedpkg.sharedpgm.genericmessage2("a", "b", "c", exception);
    <pre class="jive-pre"> IWN.VAL.6619.e 19/24 servicepgm - sharedpkg.sharedpgm.genericmessage2 cannot be resolved. At line 19 in file \servicesprj\EGLSource\reportingsvcpkg\servicepgm.egl </pre>
    Remove the "service sharedpgm{IncludeReferencedFunctions = yes}" line in your shared package like this:

    package sharedpkg;
     
     //-----------------------------------------
     function genericmessage2(funcin string in,
                            userin string in,
                            values string in,
                            exception anyexception in)
    //----------------------------------------- 
                writeStderr(currenttimestamp());
                writeStderr("Function: " + funcin);
                writeStderr("User: " + userin);
                writeStderr("Values: " + values);
                writeStderr(exception.message);
     end
    


    This will allow you to reference the function - I hope.
    Hope this helps

    Morten Hansen
    IBM Denmark
    Updated on 2014-03-25T04:35:00Z at 2014-03-25T04:35:00Z by iron-man
  • clogs
    clogs
    186 Posts

    Re: how to access functions in different packages

    ‏2013-04-06T11:09:37Z  
    • nick_tn
    • ‏2013-04-02T15:52:34Z
    I tried as you suggested, but getting cannot resolve error.

    Shared package serviceprj/sharedpkg/sharedpgm path
    <pre class="jive-pre"> package sharedpkg; service sharedpgm {IncludeReferencedFunctions = yes } //----------------------------------------- function genericmessage2(funcin string in, userin string in, values string in, exception anyexception in) //----------------------------------------- writeStderr(currenttimestamp()); writeStderr( "Function: " + funcin); writeStderr( "User: " + userin); writeStderr( "Values: " + values); writeStderr(exception.message); end </pre>

    usage service
    <pre class="jive-pre"> package reportingsvcpkg; import sharedpkg.*; service servicepgm {IncludeReferencedFunctions = yes } function test() try onException(exception AnyException) genericmessage2( "a", "b", "c", exception); end end end </pre>

    I get the following errors:

    genericmessage2("a", "b", "c", exception);
    <pre class="jive-pre"> Multiple markers at this line - IWN.VAL.6619.e 19/4 servicepgm - genericmessage2 cannot be resolved. At line 19 in file \servicesprj\EGLSource\reportingsvcpkg\servicepgm.egl - IWN.VAL.6619.e 19/24 servicepgm - sharedpkg.sharedpgm.genericmessage2 cannot be resolved. At line 19 in file \servicesprj\EGLSource\reportingsvcpkg \servicepgm.egl </pre>

    if i qualify it, it actually prompts the parms, but then give me an error.
    sharedpkg.sharedpgm.genericmessage2("a", "b", "c", exception);
    <pre class="jive-pre"> IWN.VAL.6619.e 19/24 servicepgm - sharedpkg.sharedpgm.genericmessage2 cannot be resolved. At line 19 in file \servicesprj\EGLSource\reportingsvcpkg\servicepgm.egl </pre>
    Hi Nick,

    I refactored your code a bit. The function you want to share is now in a library. This library can be placed anywhere; we tend to put shared functions in a 'commons' type project and then include that project on the EGL build path of the project that needs those functions. If you're generating to Java you may also need to place the 'commons' project on the Java build path of your project.

    So, here's the library:

    
    
    
    package sharedpkg;   
    // This library holds some commonly shared functions library MySharedFunctionsLib type BasicLibrary 
    {
    }   function genericmessage2(funcin string in, userin string in, values string in, exception anyexception in) writeStderr(currenttimestamp()); writeStderr(
    "Function: " + funcin); writeStderr(
    "User: " + userin); writeStderr(
    "Values: " + values); writeStderr(exception.message); end end
    


    The service can then use the function in the shared library as follows:

    
    
    
    package services;   
    
    import sharedpkg.MySharedFunctionsLib;   
    // service service MyService function test() 
    
    try onException(exception AnyException) MySharedFunctionsLib.genericmessage2(
    "a", 
    "b", 
    "c", exception); end end end
    


    Hope this helps.
    Willem.