Quick Contact

    SAP Tutorial

    Re-use Subroutines

    Here we will be able to learn using tables in performs and re-usability of performs in different ABAP programs.

    Step 1:

    Create a program ZSAPN_SUBROUTINE_REUSE1 and create a perform to get material details for a material type.

    REPORT ZSAPN_SUBROTINE_REUSE1.
    DATA : IT_MARA TYPE TABLE OF MARA.
    DATA : WA_MARA TYPE MARA.
    CONSTANTS: C_MTART TYPE MARA-MTART VALUE 'FERT'. "Constant declaration
    
    PERFORM GET_MATDATA TABLES IT_MARA USING C_MTART. "Perform to get material data by passing material type
    
    LOOP AT IT_MARA INTO WA_MARA . "Display material
      WRITE: / WA_MARA-MATNR, WA_MARA-MTART.
    ENDLOOP.
    FORM GET_MATDATA  TABLES   P_IT_MARA TYPE STANDARD TABLE "perform implementation
                                 "Insert correct name for <...>
                      USING    P_C_MTART.
      SELECT * FROM MARA INTO TABLE P_IT_MARA UP TO 50 ROWS WHERE MTART = P_C_MTART.
    ENDFORM.                    " GET_MATDATA
    
    Step 2:

    Create another program ZSAPN_SUBROUTINE_REUSE2 and call perform external program ZSAPN_SUBROUTINE_REUSE1.

    The syntax for calling external subroutine is:

    PERFORM < PERFORM NAME>(< PROGRAM NAME>) TABLES < TABLES> USING < PARAMS> CHANGING < PARAMS>.

    Example program 2:
    REPORT ZSAPN_SUBROTINE_REUSE2.
    
    DATA : IT_MARA TYPE TABLE OF MARA, "material internal table
           WA_MARA TYPE MARA. "Work area
    
    CONSTANTS: C_MTART TYPE MARA-MTART VALUE 'HALB'. "Constant
    
    PERFORM GET_MATDATA(ZSAPN_SUBROTINE_REUSE1) TABLES IT_MARA USING C_MTART. "Calling external subroutine
    
    LOOP AT IT_MARA INTO WA_MARA. "Display data
      WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MEINS.
    ENDLOOP.
    


    Copyright 1999- Ducat Creative, All rights reserved.