Informix

 View Only
  • 1.  SPL was called by another SPL

    Posted Wed May 11, 2022 05:52 AM
    is there a way to know if an SPL was called by another SPL?

    Thanks.

    ------------------------------
    Antonio Ferrara
    ------------------------------

    #Informix


  • 2.  RE: SPL was called by another SPL

    IBM Champion
    Posted Wed May 11, 2022 06:38 AM

    Antonio:

    I cannot think of any way for an SPL routine to know if it was called by another SPL, no.

    You could create a Global variable and set it before calling another routine then clear it after the routine returns. When the other routine checks the value of the global, if it was called directly by a client the global will not have been set. Other than that, dunno.

    Art



    ------------------------------
    Art S. Kagel, President and Principal Consultant
    ASK Database Management Corp.
    www.askdbmgt.com
    ------------------------------



  • 3.  RE: SPL was called by another SPL

    Posted Wed May 11, 2022 06:58 AM
    Thanks for the reply.
    Excuse my ignorance, but how do you declare a global variable to the two routines?

    ------------------------------
    Antonio Ferrara
    ------------------------------



  • 4.  RE: SPL was called by another SPL
    Best Answer

    IBM Champion
    Posted Wed May 11, 2022 08:39 AM
    Check the Guide to SQL Syntax manual or equivalent online manual page for the SPL DEFINE statement. The description is: 

    Use the DEFINE statement to declare local variables that an SPL routine uses, or to
    declare global variables that can be shared by several SPL routines.

    So:
    DEFINE GLOBAL is_subcall INT DEFAULT 0;
    DEFILE GLOBAL in_transaction INT DEFAULT 0;  -- This may be what you really want, considering your other question.

    You would define that same variable in each routine that needs to know whether it was called from another routine. The caller or the routine that issues the BEGIN WORK would then set the appropriate variable to '1'. On returning from the called routine the caller would clear is_subcall back to 0. Or whichever routine in the process tree issues a COMMIT WORK or ROLLBACK WORK would clear the in_transaction variable.

    Here's the link to the online manual page:
    Declare global variables



    ------------------------------
    Art S. Kagel, President and Principal Consultant
    ASK Database Management Corp.
    www.askdbmgt.com
    ------------------------------



  • 5.  RE: SPL was called by another SPL

    Posted Wed May 11, 2022 09:13 AM
    Now it is clear to me. Thanks

    ------------------------------
    Antonio Ferrara
    ------------------------------