SubProcedure (Subroutines) within Stored Procedure

  • Is it possible to write the Sub Routine inside the Stored Procedure like below ?

    The reason I would like the SubRoutines is I need to use the same Variables , temp tables between these procedures.

    /*Main Procedure */

    SubRoutineOrders :

    input parameters

    output parameters

    end

    SubRoutineOrderLine :

    input parameters

    output parameters

    end

    SubRoutinePurchaseOrders :

    input parameters

    output parameters

    end

    SubRoutinePurchaseOrderLines :

    input parameters

    output parameters

    end

    .....

  • Yes you can - stored procedures with input and output parameters can be nested within a calling stored procedure. Do you really need the code blocks configured as "subroutines"?

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Do you have an example ? I don't necessarily want different Stored Procedures.

    I need multiple SubRoutines within One Stored Procedure, so that they can share the Variables and Temp Tables.

  • I don't really need the code blocks configured as "subroutines". But there is no easy way to share the variables and Temp Tables between SP's.

  • skb 44459 (1/7/2014)


    Do you have an example ? I don't necessarily want different Stored Procedures.

    I need multiple SubRoutines within One Stored Procedure, so that they can share the Variables and Temp Tables.

    Can you post up one such "subroutine"? It would help folks to visualise what you are trying to do.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Its not a SQL Program , it is a Progress Program.

    DEFINE INPUT PARAMETER IpModule AS CHAR NO-UNDO.

    DEFINE INPUT PARAMETER IpKeyValue AS CHAR NO-UNDO.

    IF IpModule = "Order" then

    do :

    /* Create an TempTable Record */

    Run GetOrder (IpKeyValue).

    end.

    Procedure getOrder :

    Define input parameter IpOrder as char .

    /* Insert into #temp (Parent, Child, Decription) */

    for each OrderLine where Order = IpOrder :

    Run GetOrderLine (inpur Order, Input Line) .

    end.

    end procedure.

    Procedure getOrderLine :

    Define input parameter IpOrder as char .

    Define input parameter IpLine as int .

    /* Insert into #temp (Parent, Child, Decription) */

    end.

    end procedure.

    Procedure getShipments :

    Define input parameter IpOrder as char .

    Define input parameter IpLine as int .

    /* Insert into #temp (Parent, Child, Decription) */

    end.

    end procedure.

    Procedure getInvoices:

    Define input parameter IpOrder as char .

    Define input parameter IpLine as int .

    /* Insert into #temp (Parent, Child, Decription) */

    end procedure.

  • skb 44459 (1/7/2014)


    Its not a SQL Program , it is a Progress Program.

    ...

    What make of car do you drive?


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply