Skip to Content
author's profile photo Former Member
Former Member

subroutine

How to access a subroutine in the program which is declared in subroutine pool.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Feb 27, 2007 at 05:21 AM

    Just double click on the routine name.... and it will take you to the routine code...

    hope it helps.

    Thanks

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 27, 2007 at 05:28 AM

    hi vamsi,

    check it out u will find lot of info....

    1) Subroutines are programming modules which can be called from ABAP/4 programs.

    Frequently used parts of program can be put into subroutines and these subroutines can be called explicitly from the program.

    We use subroutines mainly to modularize and structure our program.

    2) A subroutine is a block of code introduced by ‘FORM’ and concluded by ‘ENDFORM’.

    FORM <name> <parameters.

    ><……..>

    ENDFORM.

    3) PERFORM form. [USING p1 p2 p3]

    [CHANGING p1 p2 p3] [TABLES itab1 itab2] Calls the subroutine form defined using a FORM statement. After the subroutine has finished, processing continues after the PERFORM statement. The parameters of the subroutine are position parameters, and must be passed in the call according to the definition of the formal parameters in the corresponding FORM statement.

    4) You list these parameters after USING or CHANGING without the VALUE addition:

    FORM <subr> USING ... <pi> [TYPE <t>|LIKE <f>] ... CHANGING ... <pi> [TYPE <t>|LIKE <f>] ...

    The formal parameter occupies no memory of its own. During a subroutine call, only the address of the actual parameter is transferred to the formal parameter. The subroutine works with the field from the calling program. If the value of the formal parameter changes, the contents of the actual parameter in the calling program also change.

    5) For calling by reference, USING and CHANGING are equivalent. For documentation purposes, you should use USING for input parameters which are not changed in the subroutine, and CHANGING for output parameters which are changed in the subroutine.

    To avoid the value of an actual parameter being changed automatically, you must pass it by value.

    6) FORM <subr> USING ... VALUE(<pi>) [TYPE <t>|

    LIKE <f>] ...

    The formal parameter occupies its own memory space. When you call the subroutine, the value of the actual parameter is passed to the formal parameter. If the value of the formal parameter changes, this has no effect on the actual parameter.

    7) FORM <subr> TABLES .. <itabi> [TYPE <t>|LIKE <f>] ..

    The formal parameters <itabi> are defined as standard internal tables with header lines. If you use an internal table without header line as the corresponding actual parameter for a formal parameter of this type, the system creates a local header line in the subroutine for the formal parameter. If you pass an internal table with a header line, the table body and the table work area are passed to the subroutine. Formal parameters defined using TABLES cannot be passed by reference. If you want to address the components of structured lines, you must specify the type of the TABLES parameter accordingly.

    8) DATA:A1 TYPE P DECIMALS 3, A2 TYPE I,A3 TYPE D, A4 TYPE SPFLI-CARRID,

    A5 TYPE C.

    PERFORM SUBR USING A1 A2 A3 A4 A5.

    <CODE>

    PERFORM SUBR CHANGING A1 A2 A3 A4 A5.

    <CODE>

    PERFORM SUBR USING A1 A2 A3 CHANGING A4 A5.

    <CODE>

    FORM SUBR USING VALUE(F1) TYPE P VALUE(F2) TYPE I F3 LIKE A3 CHANGING VALUE(F4) TYPE SPFLI-CARRID F5. <CODE>

    ENDFORM.

    9) TYPES: BEGIN OF STR,

    TEXT(50), NUMBER TYPE I, END OF STR. DATA: ITAB_LINE TYPE STR OCCURS 0

    WITH HEADER LINE. PERFORM DISPLAY TABLES ITAB_LINE. FORM DISPLAY TABLES PAR_ITAB

    STRUCTURE STR. <CODE>

    ENDFORM.

    ~~Guduri

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 27, 2007 at 05:28 AM

    Hi,

    keep cursor on the name and use where used list

    or doble click and then it will take you to the specified

    Regards

    SHiva

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 27, 2007 at 05:37 AM

    <b>Definition in the SAPscript form:

    /: PERFORM GET_BARCODE IN PROGRAM QCJPERFO

    /: USING &PAGE&

    /: USING &NEXTPAGE&

    /: CHANGING &BARCODE&

    /: ENDPERFORM

    / &BARCODE&</b>

    In the textelement of sapscript i am calling subroutine GET_BARCODE present in program QCJPERFO and passing PAGE , NEXTPAGE as input parameters and Barcode as changing parameter (output)

    <b>Coding of the calling ABAP program ( Subroutine pool ):</b>

    REPORT QCJPERFO.

    FORM GET_BARCODE TABLES IN_PAR STUCTURE ITCSY

    OUT_PAR STRUCTURE ITCSY.

    DATA: PAGNUM LIKE SY-TABIX, "page number

    NEXTPAGE LIKE SY-TABIX. "number of next page

    // Here in_par is table for input parameters is of type itcsy , so contains name and value as fields.

    // 1st record of in_par in_par-name = PAGE in_par-value = the current page number

    // (eq. 1 or 2 etc ... )

    // 2nd record of in_par in_par-name = NEXTPAGE in_par-value = the Next page //number (eq. if page = 1 then next page = 2 etc ... )

    // Here out_par is table for changing parameters ( output ) is of type itcsy .

    // since i am passing only one changing parameter it contains only one record

    // 1st record of out_par out_par-name = BARCODE out_par-value = ...(some value)

    READ TABLE IN_PAR WITH KEY ‘PAGE’.

    // reading the records from in_par where field name is PAGE , so first record is selected from our table

    CHECK SY-SUBRC = 0.

    PAGNUM = IN_PAR-VALUE.

    // Page number is stored in variable PAGNUM

    READ TABLE IN_PAR WITH KEY ‘NEXTPAGE’.

    // reading the records from in_par where field name is NEXTPAGE , so second record is selected from our table

    CHECK SY-SUBRC = 0.

    NEXTPAGE = IN_PAR-VALUE.

    // Next Page number is stored in variable NEXTPAGE

    READ TABLE OUT_PAR WITH KEY ‘BARCODE’.

    // reading the records from out_par where field name is BARCODE , so first record is selected from our table

    CHECK SY-SUBRC = 0.

    IF PAGNUM = 1.

    OUT_PAR-VALUE = ‘|’. "First page

    // if the variable PAGNUM value is one then i am storing | in OUT_PAR-VALUE ie, BARCODE

    ELSE.

    OUT_PAR-VALUE = ‘||’. "Next page

    // if the variable PAGNUM value is not one then i am storing || in OUT_PAR-VALUE ie, BARCODE

    ENDIF.

    IF NEXTPAGE = 0.

    // if the variable NEXTPAGE value is Zero then i am storing L in OUT_PAR-VALUE ie, BARCODE

    OUT_PAR-VALUE+2 = ‘L’. "Flag: last page

    ENDIF.

    MODIFY OUT_PAR INDEX SY-TABIX.

    // After changing the field value of output table , i am modifying to reflect the changes.

    // Now barcode contains the changed value ie, either | or || or L depending on the condition satified

    ENDFORM.

    That changed value i am printing in sapscript

    / &BARCODE&

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 27, 2007 at 05:38 AM

    Vamsi,

    Here is the solution to ur Query,

    First create a subroutine pool, and u may write the number of subroutines u require.

    Now u want to call those subroutines from an executable program right?

    Suppose 'add' is the subroutine that resides in subroutine pool, and u can call it with the following statement.

    PERFORM add IN PROGRAM zsubr USING a b.

    it will definetly solve ur problem, incase of further queries... reply me

    Regards,

    Sujatha.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.