Wednesday, 29 June 2016

Internal Subroutines without passing parameters


  • Syntax :



  • Defining Subroutines.
                             FORM <subroutine> [<parameters>].
                                    <statements>
                             ENDFORM.

  • Calling Subroutines. 
  • Internal subroutines have the source code in the calling ABAP/4 program:  
                                 PERFORM <subroutine> .


Steps:

  • Go to transaction code SE38.
  • Enter the program name start's with Y or Z<program name > and click on create button.



  • Enter the Title.
  • Select Attribute Type as Executable Program.
  • Click on save button.
  • Either save it in Package or Local Package.
  • Write the code,
  • Source code,
TYPES BEGIN OF TY_VBRP,
        VBELN TYPE VBRP-VBELN,
        POSNR TYPE VBRP-POSNR,
        MATNR TYPE VBRP-MATNR,
        ARKTX TYPE VBRP-ARKTX,
       END OF TY_VBRP.
    
DATA WA_VBRP TYPE TY_VBRP,
       IT_VBRP TYPE TABLE OF TY_VBRP.
    
SELECT-OPTIONS S_VBELN FOR WA_VBRP-VBELN.
    
PERFORM FETCH_DATA" TO FETCH DATA


  • Double click on Subroutine name i.e FETCH_DATA .
  • Click on Yes.
  • Select the include and click on continue.
  • A subroutine name introduced by FORM and concluded by ENDFORM will appear.
  • Enter the source code.
form FETCH_DATA .

SELECT  VBELN POSNR MATNR ARKTX FROM VBRP INTO TABLE IT_VBRP WHERE
  VBELN IN S_VBELN.
endform.                    " FETCH_DATA

  • Create one more subroutine to display output.
  • Double click on subroutine name i.e DISPLAY .
  • Select the include and click on continue.

  • Enter the code.
LOOP AT IT_VBRP INTO WA_VBRP.

WRITE / WA_VBRP-VBELN WA_VBRP-POSNR WA_VBRP-MATNR WA_VBRP-ARKTX.
ENDLOOP.




  • Save -> Check -> Activate.
  • Click on Execute (F8).

Input

Output


No comments:

Post a Comment