SlideShare a Scribd company logo
Modularisation Techniques
• modularization makes ABAP 
programs easier to read and 
maintain, as well as avoiding 
redundancy, increasing the 
reusability of source code, and 
encapsulating data.
Modularization Techniques 
• Macros 
• Include programs 
• Subroutine 
• Functional modules
• If you want to reuse the same set of 
statements more than once in a program, you 
can include them in a macro. 
• You can only use a macro within the program 
in which it is defined, and it can only be called 
in lines of the program following its definition. 
Macros can be useful for long calculations or 
complex WRITE statements.
• Syntax 
DEFINE <macro_name> 'Macro Statements 
END-OF-DEFINITION. 
Macros can use Parameters &N where N = 
1,2,3...
• DATA: number1 TYPE I VALUE 1. 
• DEFINE increment. 
• ADD 1 to &1. 
• WRITE &1. 
• END-OF-DEFINITION. 
• Increment number1. 
• WRITE number1. 
• Output: 2
Include Programs 
If you want to use the same sequence of statements in several 
programs, you can code them once in an include program. 
How to create include programs ? 
If you create an include program yourself, you must assign it the 
type I in its program attributes. You can also create or change an 
include program by double-clicking on the name of the program 
after the INCLUDE statement in your ABAP program. If the program 
exists, the ABAP Workbench navigates to it. If it does not exist, the 
system creates it for you. 
How to use Include programs ? 
An include program cannot run independently, but must be built 
into other programs. Include programs can contain other includes.
Example: 
Include Program 
***INCLUDE STARTTXT. 
WRITE: / 'Program started by', SY-UNAME, 
/ 'on host', SY-HOST, 
'date: ' , SY-DATUM, 
'time: ' , SY-UZEIT. 
ULINE. 
Main Program 
PROGRAM SAPMZTST. 
INCLUDE STARTTXT. 
This could produce the following output: 
Program started by SENTHIVEL 
on host ds0025 date: 09/07/2004 time: 03:15:40
Subroutines 
• Subroutines are principally for local 
modularization, that is, they are generally 
called from the program in which they are 
defined. You can use subroutines to write 
functions that are used repeatedly within a 
program. You can define subroutines in any 
ABAP program. 
• Subroutines: can be used locally and globally 
(external subroutine calls).
• . External Subroutines are subroutines that are 
called from another program. 
• There are two types of subroutines: 
• 
• 1) Internal subroutine: If the source code or body 
of the subroutine will be in the same ABAP/4 
program i.e. in the calling program which is called 
internal subroutine. 
• 
• 2) External subroutine: If the source code or body 
of the subroutine present other than the calling 
program which is called external subroutine. An 
external subroutine is one that resides in a 
different program that the perform statement 
that calls it.
• Report ztn1811 
• Perform (S1) (ztn1811) 
• 
• Report ztn1811 
• FORM s1 
• ----------- 
• ---------- 
• ENDFORM.
• Parameters 
• Parameters can be either local or reference to global 
variables. The memory for local parameters is allocated 
when the subroutine is called & freed when it ends. If 
we define variables on the form statement, the 
perform statement must pass a value to each of these 
variables. 
• 
• Global variables: A global variable is one that is defined 
outside of a subroutine by using the tables or data 
statement. It can be accessed from any point in the 
program be it inside an event or inside a subroutine. 
• 
• Local variables: A local variables is a variable that is 
defined inside a subroutine using local data or static’s 
statement. It is said to be local to subroutine.
• Formal parameters: Parameter names that 
appear on the form statements are called 
formal parameters. 
• Ex: FORM s1, using P1 changing P2, P3 
• Here P1, P2, P3 are called formal parameters. 
• Actual parameters: Parameter names that 
appears on the perform statement are called 
actual parameters. 
• Ex: PERFORM S1 using P1 changing P2, P3. 
• Here P1, P2, P3 are called actual parameters.
• There are three ways of passing parameters to a subroutine. 
• 1) Pass by reference 
• 2) Pass by value 
• 3) Pass by value & result 
• 1) Passing parameters by reference 
• During subroutine call, only the address of the actual 
parameter is transferred to the formal parameters i.e. pointer 
to the original memory or address location is passed. The 
formal parameter has no memory of its own & we work with 
the fields of the calling program with in a subroutine. So 
changes to the variable within the subroutine update the 
original memory location immediately i.e. the field contents in 
the calling program also changes.
• 2. Passing parameters by value : 
• 
• When you pass a parameters by value, new 
memory is allocated for the value i.e. the 
formal parameters are created as copies of the 
actual parameters, thus formal parameters 
have memory of their own i.e. the memory 
allocated when the subroutine is called and 
freed when the subroutine returns. Therefore 
changes to the formal parameters have no 
effect on the actual parameters.
• 3. Passing parameters by value & result: 
• 
• Pass by value & result is similar to pass by 
reference like Pass by value, a new memory 
area is allocated & it frees when the 
subroutine ends. When the end form 
statement executes, it copies the value of the 
local memory area back into the original 
memory area changes to the parameter with 
in the subroutine are reflected in the original 
but not until subroutine returns.
• Leaving subroutine 
• You can exit out of a subroutine at any time using the 
following statements. 
• 1) Stop: Immediately leaves the subroutine & goes 
directly to the end of selection event. 
• 2) Exit: It leaves the loop, subroutine or comes out of the 
program & display the result without any condition. 
• 3. Check: It also comes or immediately leaves the 
subroutine but it depends on logical expression. If it is 
false comes out of the loop or subroutine.
Function group and Function module 
• Function groups are created using transaction 
SE37 (function builder). A 
• Function Group is realized in the SAP Software 
system as a program, containing 
• a logically related set of function modules. 
• Create the function group by selecting the 
menu path Goto -> Function Groups 
• -> Create Group.
Function Module 
• Function modules are created using transaction SE37 
(function builder). The standard SAP system has a number 
of predefined function modules. Function Modules are 
Global ABAP programs created by SAP for reusable 
purpose. 
• Function modules are best used for carrying out database 
updates and communicating with different SAP systems. 
• 
• In contrast to subroutines, function modules do not need to 
be defined in the source of your ABAP program. Function 
modules may have both input and output parameters. The 
input parameters can be mandatory or optional.
• You can also assign default values to 
parameters. Function modules also provide 
the option of exception handling, which 
catches errors when the function 
• module executes. You may also test function 
modules from transaction SE37 before 
including them in your programs. 
• Function Modules must begin with a Z_ or a 
Y_, and can be created as follows:
• The Attributes of the function module should be 
reviewed first, as it controls the behavior of the overall 
function module. 
• The processing type controls the behavior of the 
function module. 
• Normal Function Module 
Used for modularizing code and is not externally visible 
to other systems, but globally visible within the same 
SAP software system. 
Remote Function Module 
Visible to external systems, and thus can be called via 
the RFC gateway.
• Update Function Module 
• Denotes the use of the function module for 
Asynchronous update purposes.
Interface of function module 
Import 
• Data to be received from the calling program 
export 
• Data to be returned to the calling program 
• Changing 
• Data to be received and returned using the 
same reference variable
• Tables 
• Obsolete interface for passing arrays of 
information 
• Exceptions 
• Exceptions , resulting in non zero values of the 
System variable SY-SUBRC 
• Exceptions are raised using the RAISING 
<exception> command in the source code of 
the function module.
• Note the use of the RAISE statement in the 
code above to trigger an exception. 
• When the RAISE statement occurs, the 
program processing jumps to the 
ENDFUNCTION, and the control is passed back 
to the calling application.
• Testing the Function Module 
• The Function Builder has its own test 
workbench, and can be accessed using the 
• TEST icon, the same one used in the ABAP 
Editor.

More Related Content

What's hot

1000 solved questions
1000 solved questions1000 solved questions
1000 solved questions
Kranthi Kumar
 
modularization-160202092213 (1).pdf
modularization-160202092213 (1).pdfmodularization-160202092213 (1).pdf
modularization-160202092213 (1).pdf
SreeramBaddila
 
Passing table to subroutine
Passing table to subroutinePassing table to subroutine
Passing table to subroutine
Rajee Chandru
 
Step by step procedure for loading of data from the flat file to the master d...
Step by step procedure for loading of data from the flat file to the master d...Step by step procedure for loading of data from the flat file to the master d...
Step by step procedure for loading of data from the flat file to the master d...
Prashant Tyagi
 

What's hot (20)

Smartforms interview questions with answers
Smartforms interview questions with answersSmartforms interview questions with answers
Smartforms interview questions with answers
 
Oops abap fundamental
Oops abap fundamentalOops abap fundamental
Oops abap fundamental
 
Abap reports
Abap reportsAbap reports
Abap reports
 
Alv theory
Alv theoryAlv theory
Alv theory
 
ABAP for Beginners - www.sapdocs.info
ABAP for Beginners - www.sapdocs.infoABAP for Beginners - www.sapdocs.info
ABAP for Beginners - www.sapdocs.info
 
1000 solved questions
1000 solved questions1000 solved questions
1000 solved questions
 
modularization-160202092213 (1).pdf
modularization-160202092213 (1).pdfmodularization-160202092213 (1).pdf
modularization-160202092213 (1).pdf
 
Badi document
Badi documentBadi document
Badi document
 
Field symbols
Field symbolsField symbols
Field symbols
 
Dialog programming ABAP
Dialog programming ABAPDialog programming ABAP
Dialog programming ABAP
 
Sap Abap Reports
Sap Abap ReportsSap Abap Reports
Sap Abap Reports
 
Passing table to subroutine
Passing table to subroutinePassing table to subroutine
Passing table to subroutine
 
SAP Adobe forms
SAP Adobe formsSAP Adobe forms
SAP Adobe forms
 
Step by step procedure for loading of data from the flat file to the master d...
Step by step procedure for loading of data from the flat file to the master d...Step by step procedure for loading of data from the flat file to the master d...
Step by step procedure for loading of data from the flat file to the master d...
 
05 internal tables
05 internal tables05 internal tables
05 internal tables
 
Sap User Exit for Functional Consultant
Sap User Exit for Functional ConsultantSap User Exit for Functional Consultant
Sap User Exit for Functional Consultant
 
Object oriented approach to ALV Lists in ABAP
Object oriented approach to ALV Lists in ABAPObject oriented approach to ALV Lists in ABAP
Object oriented approach to ALV Lists in ABAP
 
Abap Questions
Abap QuestionsAbap Questions
Abap Questions
 
Reports
ReportsReports
Reports
 
Sap abap material
Sap abap materialSap abap material
Sap abap material
 

Similar to Modularisation techniques new

Lecture11 abap on line
Lecture11 abap on lineLecture11 abap on line
Lecture11 abap on line
Milind Patil
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
Manoj Patil
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and import
iamluqman0403
 

Similar to Modularisation techniques new (20)

Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
 
Coding
CodingCoding
Coding
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem sloving
 
Sub-programs
Sub-programsSub-programs
Sub-programs
 
Lecture11 abap on line
Lecture11 abap on lineLecture11 abap on line
Lecture11 abap on line
 
10 implementing subprograms
10 implementing subprograms10 implementing subprograms
10 implementing subprograms
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
Monolithic and Procedural Programming
Monolithic and Procedural ProgrammingMonolithic and Procedural Programming
Monolithic and Procedural Programming
 
Functions
FunctionsFunctions
Functions
 
C programming
C programmingC programming
C programming
 
Introduction to problem solving in C
Introduction to problem solving in CIntroduction to problem solving in C
Introduction to problem solving in C
 
Testing Frameworks
Testing FrameworksTesting Frameworks
Testing Frameworks
 
Plc part 3
Plc  part 3Plc  part 3
Plc part 3
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and import
 
Using general sub procedures
Using general sub proceduresUsing general sub procedures
Using general sub procedures
 
Modular programming
Modular programmingModular programming
Modular programming
 
An intuitive guide to combining free monad and free applicative
An intuitive guide to combining free monad and free applicativeAn intuitive guide to combining free monad and free applicative
An intuitive guide to combining free monad and free applicative
 
C question
C questionC question
C question
 
user defined function
user defined functionuser defined function
user defined function
 

Recently uploaded

一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
ewymefz
 
一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单
ewymefz
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
nscud
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
benishzehra469
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
ewymefz
 
一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
enxupq
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
ukgaet
 
Professional Data Engineer Certification Exam Guide  _  Learn  _  Google Clou...
Professional Data Engineer Certification Exam Guide  _  Learn  _  Google Clou...Professional Data Engineer Certification Exam Guide  _  Learn  _  Google Clou...
Professional Data Engineer Certification Exam Guide  _  Learn  _  Google Clou...
Domenico Conte
 
standardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghhstandardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghh
ArpitMalhotra16
 
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
vcaxypu
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
ewymefz
 

Recently uploaded (20)

一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
 
一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
 
Q1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year ReboundQ1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year Rebound
 
2024-05-14 - Tableau User Group - TC24 Hot Topics - Tableau Pulse and Einstei...
2024-05-14 - Tableau User Group - TC24 Hot Topics - Tableau Pulse and Einstei...2024-05-14 - Tableau User Group - TC24 Hot Topics - Tableau Pulse and Einstei...
2024-05-14 - Tableau User Group - TC24 Hot Topics - Tableau Pulse and Einstei...
 
Using PDB Relocation to Move a Single PDB to Another Existing CDB
Using PDB Relocation to Move a Single PDB to Another Existing CDBUsing PDB Relocation to Move a Single PDB to Another Existing CDB
Using PDB Relocation to Move a Single PDB to Another Existing CDB
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
 
一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .
 
tapal brand analysis PPT slide for comptetive data
tapal brand analysis PPT slide for comptetive datatapal brand analysis PPT slide for comptetive data
tapal brand analysis PPT slide for comptetive data
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
 
Professional Data Engineer Certification Exam Guide  _  Learn  _  Google Clou...
Professional Data Engineer Certification Exam Guide  _  Learn  _  Google Clou...Professional Data Engineer Certification Exam Guide  _  Learn  _  Google Clou...
Professional Data Engineer Certification Exam Guide  _  Learn  _  Google Clou...
 
standardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghhstandardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghh
 
Uber Ride Supply Demand Gap Analysis Report
Uber Ride Supply Demand Gap Analysis ReportUber Ride Supply Demand Gap Analysis Report
Uber Ride Supply Demand Gap Analysis Report
 
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
 
How can I successfully sell my pi coins in Philippines?
How can I successfully sell my pi coins in Philippines?How can I successfully sell my pi coins in Philippines?
How can I successfully sell my pi coins in Philippines?
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
 

Modularisation techniques new

  • 2. • modularization makes ABAP programs easier to read and maintain, as well as avoiding redundancy, increasing the reusability of source code, and encapsulating data.
  • 3. Modularization Techniques • Macros • Include programs • Subroutine • Functional modules
  • 4. • If you want to reuse the same set of statements more than once in a program, you can include them in a macro. • You can only use a macro within the program in which it is defined, and it can only be called in lines of the program following its definition. Macros can be useful for long calculations or complex WRITE statements.
  • 5. • Syntax DEFINE <macro_name> 'Macro Statements END-OF-DEFINITION. Macros can use Parameters &N where N = 1,2,3...
  • 6. • DATA: number1 TYPE I VALUE 1. • DEFINE increment. • ADD 1 to &1. • WRITE &1. • END-OF-DEFINITION. • Increment number1. • WRITE number1. • Output: 2
  • 7. Include Programs If you want to use the same sequence of statements in several programs, you can code them once in an include program. How to create include programs ? If you create an include program yourself, you must assign it the type I in its program attributes. You can also create or change an include program by double-clicking on the name of the program after the INCLUDE statement in your ABAP program. If the program exists, the ABAP Workbench navigates to it. If it does not exist, the system creates it for you. How to use Include programs ? An include program cannot run independently, but must be built into other programs. Include programs can contain other includes.
  • 8. Example: Include Program ***INCLUDE STARTTXT. WRITE: / 'Program started by', SY-UNAME, / 'on host', SY-HOST, 'date: ' , SY-DATUM, 'time: ' , SY-UZEIT. ULINE. Main Program PROGRAM SAPMZTST. INCLUDE STARTTXT. This could produce the following output: Program started by SENTHIVEL on host ds0025 date: 09/07/2004 time: 03:15:40
  • 9. Subroutines • Subroutines are principally for local modularization, that is, they are generally called from the program in which they are defined. You can use subroutines to write functions that are used repeatedly within a program. You can define subroutines in any ABAP program. • Subroutines: can be used locally and globally (external subroutine calls).
  • 10. • . External Subroutines are subroutines that are called from another program. • There are two types of subroutines: • • 1) Internal subroutine: If the source code or body of the subroutine will be in the same ABAP/4 program i.e. in the calling program which is called internal subroutine. • • 2) External subroutine: If the source code or body of the subroutine present other than the calling program which is called external subroutine. An external subroutine is one that resides in a different program that the perform statement that calls it.
  • 11. • Report ztn1811 • Perform (S1) (ztn1811) • • Report ztn1811 • FORM s1 • ----------- • ---------- • ENDFORM.
  • 12. • Parameters • Parameters can be either local or reference to global variables. The memory for local parameters is allocated when the subroutine is called & freed when it ends. If we define variables on the form statement, the perform statement must pass a value to each of these variables. • • Global variables: A global variable is one that is defined outside of a subroutine by using the tables or data statement. It can be accessed from any point in the program be it inside an event or inside a subroutine. • • Local variables: A local variables is a variable that is defined inside a subroutine using local data or static’s statement. It is said to be local to subroutine.
  • 13. • Formal parameters: Parameter names that appear on the form statements are called formal parameters. • Ex: FORM s1, using P1 changing P2, P3 • Here P1, P2, P3 are called formal parameters. • Actual parameters: Parameter names that appears on the perform statement are called actual parameters. • Ex: PERFORM S1 using P1 changing P2, P3. • Here P1, P2, P3 are called actual parameters.
  • 14. • There are three ways of passing parameters to a subroutine. • 1) Pass by reference • 2) Pass by value • 3) Pass by value & result • 1) Passing parameters by reference • During subroutine call, only the address of the actual parameter is transferred to the formal parameters i.e. pointer to the original memory or address location is passed. The formal parameter has no memory of its own & we work with the fields of the calling program with in a subroutine. So changes to the variable within the subroutine update the original memory location immediately i.e. the field contents in the calling program also changes.
  • 15. • 2. Passing parameters by value : • • When you pass a parameters by value, new memory is allocated for the value i.e. the formal parameters are created as copies of the actual parameters, thus formal parameters have memory of their own i.e. the memory allocated when the subroutine is called and freed when the subroutine returns. Therefore changes to the formal parameters have no effect on the actual parameters.
  • 16. • 3. Passing parameters by value & result: • • Pass by value & result is similar to pass by reference like Pass by value, a new memory area is allocated & it frees when the subroutine ends. When the end form statement executes, it copies the value of the local memory area back into the original memory area changes to the parameter with in the subroutine are reflected in the original but not until subroutine returns.
  • 17. • Leaving subroutine • You can exit out of a subroutine at any time using the following statements. • 1) Stop: Immediately leaves the subroutine & goes directly to the end of selection event. • 2) Exit: It leaves the loop, subroutine or comes out of the program & display the result without any condition. • 3. Check: It also comes or immediately leaves the subroutine but it depends on logical expression. If it is false comes out of the loop or subroutine.
  • 18. Function group and Function module • Function groups are created using transaction SE37 (function builder). A • Function Group is realized in the SAP Software system as a program, containing • a logically related set of function modules. • Create the function group by selecting the menu path Goto -> Function Groups • -> Create Group.
  • 19. Function Module • Function modules are created using transaction SE37 (function builder). The standard SAP system has a number of predefined function modules. Function Modules are Global ABAP programs created by SAP for reusable purpose. • Function modules are best used for carrying out database updates and communicating with different SAP systems. • • In contrast to subroutines, function modules do not need to be defined in the source of your ABAP program. Function modules may have both input and output parameters. The input parameters can be mandatory or optional.
  • 20. • You can also assign default values to parameters. Function modules also provide the option of exception handling, which catches errors when the function • module executes. You may also test function modules from transaction SE37 before including them in your programs. • Function Modules must begin with a Z_ or a Y_, and can be created as follows:
  • 21. • The Attributes of the function module should be reviewed first, as it controls the behavior of the overall function module. • The processing type controls the behavior of the function module. • Normal Function Module Used for modularizing code and is not externally visible to other systems, but globally visible within the same SAP software system. Remote Function Module Visible to external systems, and thus can be called via the RFC gateway.
  • 22. • Update Function Module • Denotes the use of the function module for Asynchronous update purposes.
  • 23. Interface of function module Import • Data to be received from the calling program export • Data to be returned to the calling program • Changing • Data to be received and returned using the same reference variable
  • 24. • Tables • Obsolete interface for passing arrays of information • Exceptions • Exceptions , resulting in non zero values of the System variable SY-SUBRC • Exceptions are raised using the RAISING <exception> command in the source code of the function module.
  • 25. • Note the use of the RAISE statement in the code above to trigger an exception. • When the RAISE statement occurs, the program processing jumps to the ENDFUNCTION, and the control is passed back to the calling application.
  • 26. • Testing the Function Module • The Function Builder has its own test workbench, and can be accessed using the • TEST icon, the same one used in the ABAP Editor.