Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 15

Procedure Oriented Programming

1
 Overview
 Subroutines
 Includes
 Function Groups and
Function Modules

2
Overview
Modularization Techniques allows to break the program into multiple smaller block and call them whenever necessary.

Following are the Techniques


 Subroutines
 Includes
 Function Groups and Function Modules

Block Block

Program Flow
Block
Block

3
Subroutines
Subroutines help to modularize the program. Logic is
implemented between FORM..ENDFORM and can be called
using PERFORM statement. But should no longer be created
Main Program
in new program …
“Data Declaration FORM Form1 <Params>
… “ Application Logic
Syntax: Defining Subroutine
ENDFORM.
FORM <Form Name> < Formal Interface Parameters>
“ Application Logic PERFORM form1
….
ENDFORM.
PERFORM form2 FORM Form2 <Params>
…. “ Application Logic
Syntax: Calling Sub Routine
ENDFORM
PERFORM <Form Name> < Actual Parameters Mapping>

4
Subroutines and Parameter Passing
Parameter Passing: Parameters can be passed to the Subroutines from the Caller Program

Syntax
FORM <Subroutine> TABLES <Table Parameter> USING <Parameters> CHANGING <Parameters> RAISING <Exceptions>.
“ Application Logic
ENDFORM.

Create a Subroutine for fetching list of materials for the given


material Type Create a Subroutine for displaying given Material Details

Calling Subroutine by passing the values Calling Subroutine by passing the values

5
Parameter Passing: Pass By Value and Pass By Value
Data flow
Program Flow

Data for the Main Program


Pass By Value is parameter passing mechanism from Calling Data in the Subroutine
Data from Caller Program
program to Sub routine. Data Declare inside routine

In this scenario, system creates a separate copy of the data Main Program

which is passed from the Caller Program. “Data Declaration FORM Form1 <Params>
… “ Application Logic

ENDFORM.
Sub routine will work on Copied data. Data in the Caller program
will not be updated. PERFORM form1
….

PERFORM form2 FORM Form2 <Params>


VALUE Addition should be specified for each parameter to make it …. “ Application Logic
Pass By Value
ENDFORM

6
Parameter Passing: Pass By Value and Pass By Reference
Data flow
Program Flow

Data for the Main Program


Pass By Value is parameter passing mechanism from Calling Data for the Subroutine
Data declared inside the
program to Sub routine. Subroutine

In this scenario, system creates a separate copy of the data Main Program

which is passed from the Caller Program. “Data Declaration FORM Form1 <Params>
… “ Application Logic

ENDFORM.
Sub routine will work on Copied data. Data in the Caller program
will not be updated. PERFORM form1
….

PERFORM form2 FORM Form2 <Params>


…. “ Application Logic

ENDFORM

7
Subroutines: Example

Main Program flow Subroutines

8
Subroutines: Reason for Obsolete
 Positional parameters instead of keyword parameters
 No genuine input parameters in pass by reference
 Typing is optional
 No optional parameters
 Every subroutine belongs implicitly to the public interface of its program, which is generally not wanted.
 Calling subroutines externally is critical with respect to the assignment of the container program to a program group in the internal
session. This assignment cannot generally be defined statically.

9
Includes
Include programs are used to split ABAP source code into individual repository objects. Include programs are not callable blocks.
These are just replaceable blocks. Include program having Program type ‘I’
Runtime
Main Program
Development Time …
“Data Declaration

Main Program Include Program#1


Include Program#1
… … …
“Data Declaration “Data Declaration “Data Declaration

… … .. Processing Blocks
INCUDE <Include#1> .. Processing Blocks ….
….

PERFORM form1 PERFORM form1


…. ….

Include Program#2 PERFORM form2


PERFORM form2 … ….
…. “Data Declaration
INCUDE <Include#2> … Include Program#2

.. Processing Blocks “Data Declaration
…. …
.. Processing Blocks
….

10
Include: An Example

11
Function Group and Function Modules
Function modules are cross-program reusable procedures that are organized into function groups.

Syntax: Declare and Implement function Modules


FUNCTION <function Modules Name>
“ Application Logic
ENDFUNCTION

Syntax: Calling Function Module


CALL FUNCTION <Function Module Name> <Interface Parameters>

Function Group is collection of Function Modules. Function modules can be created within the Function Group only. Function Group
contains TOP include where we can declare all the global parameters. So that all the function module can access those parameters

Function Group and Function Module can be created from SE37 Transaction Code or SE80 Transaction Code

12
Function Group and Function Modules

Interface Parameters

Source Code

13
Function Modules: Interface Parameters

Importing Parameters

Exporting Parameters

14
Call Function Module: An Example

Calling Function Module by supplying all the interface


parameters

15

You might also like