SlideShare a Scribd company logo
Lecture 11 Subroutines & Function Modules BCO5647 Applications Programming Techniques (ABAP)
Readings & Objectives Readings Keller & Keller   Chapter 5 Section 5.1 & 5.2    Objectives This lecture will Discuss modularisation techniques and how these could be implemented in ABAP Introduce the concept of internal subroutines and how these are implemented in ABAP Examine how parameters are passed between the main program and subroutines Distinguish calling parameters by value and by reference Introduce the concept of function modules and their characteristics Demonstrate how function modules can be searched for in the repository Demonstrate how the features of a function module can be displayed Demonstrate how a function module can be called Demonstrate how errors in function modules can be captured and handled.
Modularisation Techniques Modularisation enables us to reduce the complexity of large programs and to re-use code. Modularisation can be implemented using: Internal subroutines The subroutine and the call are in the same program. External subroutines The subroutine is in an external program. Function modules The subroutine is stored in the Function Library.
Internal Subroutines (“Forms”) Internal subroutines are declared using the  FORM  and  ENDFORM  keywords. All subroutines should be placed at the end of the program. Subroutines are called using the  PERFORM  statement. Nested and recursive subroutine calls are permitted. Example : perform  calculate_total. …… form  calculate_total. …. statements endform .
Global and Local Data Unless declared separately in an internal subroutine, data is global to the whole program. Data can be defined as being local to the subroutine by using the  data  keyword :   data flag value 1 type i. write flag. perform write_flag. write flag.   …….. form write_flag. data flag type i. flag = 2. write flag. endform.
Passing Parameters Data can be passed from the calling program to a subroutine using parameters. Parameters may be described as: Read only - the parameter is read in the subroutine but is not changed. Changing - the parameter is read and changed by the subroutine. In general, the parameter passed must be of the same type as the parameter received by the subroutine. Data structures (eg internal tables) can also be passed as parameters.
Passing Parameters - Example report ptest. data: val1 type p, val2 type p,   val3 type p, val4 type p,   answer  type p, operator type c. val1 = 4.  val2 = 2.  operator = ‘+’. val3 = 8.  val4 = 5. perform calc_answer  using val1 val2 operator   changing answer. operator = ‘-’. perform calc_answer  using val3 val4 operator changing answer. ……… ... form calc_answer using fv1 fv2 op    changing ans.   case op.   when ‘+’.   ans = fv1 + fv2.   when ‘-’.   ans = fv1 - fv2.   endcase. endform.
Calling by Value and by Reference Parameters can be called either by reference or by value. Calling by reference : The address of the actual parameter is called. Changes have an immediate effect. If only the formal parameter name is specified in the subroutine interface, then the parameter is called by reference . Calling by value : When the subroutine is called, the actual parameter value is copied to the formal parameter. There are two types of call by value.
External Subroutines A program can make an external call to a subroutine in another program. Example : report main. data:  name(20). …. perform print_name(process) using name. …. report process. …. form print_name using name1. …. endform.
Function  M odules A  function module   is a  separate program  that can be called from your ABAP code to perform a specific task.   SAP comes with a  library  of pre-written function modules. Function modules are pooled together into  function groups . E.g. calendar functions  Function modules have  a  clearly defined  fixed interface for data exchange.  The interface supports exception handling.  Function modules  use their own memory area.
Searching for a Function Module Go to the Function Builder: SAP Standard Menu >> Development >> Function Builder. Transaction Code SE37. Searching can be done using the  Repository Information System  or SAP’s  Application hierarchy . Click Matchcode Button
Displaying a Function Module You can display information about existing function modules: Attributes:  specifies  administrative  information like the person responsible for the module  and  a short description of the module. Import :  contains a list of the formal parameters that are used to pass data to a function module.  Export :  contains a list of the formal parameters that are used to receive data from a function module.
Displaying a Function Module You can display information about existing function modules: Changing :  contains a list of the formal parameters that are used both to pass data to and receive data from a function module.  Tables :  specifies the tables that are to be passed to a function module. Table parameters are always passed by reference.  Exceptions : s hows how the function module reacts to exceptions.  Source code :  program code of the function module . Documentation:  provides information about the interface and exceptions .
Calling a Function Module Function modules are called by the ABAP code using a  CALL  statement . To insert function into ABAP code click  [Pattern]  button on toolbar.
Calling a Function Module
Calling a Function Module
Ad

More Related Content

What's hot (20)

User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
RAJ KUMAR
 
Sap scripts
Sap scriptsSap scripts
Sap scripts
Jugul Crasta
 
DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)
RajKumarSingh213
 
user defined function
user defined functionuser defined function
user defined function
King Kavin Patel
 
Functions
FunctionsFunctions
Functions
Munazza-Mah-Jabeen
 
Smartforms interview questions with answers
Smartforms interview questions with answersSmartforms interview questions with answers
Smartforms interview questions with answers
Uttam Agrawal
 
structure of a c program
structure of a c programstructure of a c program
structure of a c program
sruthi yandapalli
 
Abap package concept
Abap package conceptAbap package concept
Abap package concept
Tobias Trapp
 
Functions in C - Programming
Functions in C - Programming Functions in C - Programming
Functions in C - Programming
GaurangVishnoi
 
Function
Function Function
Function
Kathmandu University
 
Sap Abap Reports
Sap Abap ReportsSap Abap Reports
Sap Abap Reports
vbpc
 
INTRODUCTION TO C PROGRAMMING - PART 2
INTRODUCTION TO C PROGRAMMING - PART 2INTRODUCTION TO C PROGRAMMING - PART 2
INTRODUCTION TO C PROGRAMMING - PART 2
JEENA SARA VIJU
 
Abap course chapter 7 abap objects and bsp
Abap course   chapter 7 abap objects and bspAbap course   chapter 7 abap objects and bsp
Abap course chapter 7 abap objects and bsp
Milind Patil
 
User defined functions
User defined functionsUser defined functions
User defined functions
Randy Riness @ South Puget Sound Community College
 
Built in function
Built in functionBuilt in function
Built in function
MD. Rayhanul Islam Sayket
 
Programming style guideline very good
Programming style guideline very goodProgramming style guideline very good
Programming style guideline very good
Dang Hop
 
Ms vb
Ms vbMs vb
Ms vb
sirjade4
 
Procedure n functions
Procedure n functionsProcedure n functions
Procedure n functions
Khadija Parween
 
Notes part5
Notes part5Notes part5
Notes part5
Keroles karam khalil
 
Chap 2 structure of c programming dti2143
Chap 2  structure of c programming dti2143Chap 2  structure of c programming dti2143
Chap 2 structure of c programming dti2143
alish sha
 

Similar to Lecture11 abap on line (20)

Unit 2
Unit 2Unit 2
Unit 2
R S S RAJU BATTULA
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
nmahi96
 
Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted co...
Chapter 5   modularization & catch statement (paradiso-a45b1d's conflicted co...Chapter 5   modularization & catch statement (paradiso-a45b1d's conflicted co...
Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted co...
marco_paradiso
 
Abap function module help
Abap function module helpAbap function module help
Abap function module help
Kranthi Kumar
 
Functions part1
Functions part1Functions part1
Functions part1
yndaravind
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2
yndaravind
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
Krushal Kakadia
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
ArshiniGubbala3
 
Ch07.pdf
Ch07.pdfCh07.pdf
Ch07.pdf
slayerffGamers
 
Lecture_5_-_Functions_in_C_Detailed.pptx
Lecture_5_-_Functions_in_C_Detailed.pptxLecture_5_-_Functions_in_C_Detailed.pptx
Lecture_5_-_Functions_in_C_Detailed.pptx
Salim Shadman Ankur
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 
User defined functions in matlab
User defined functions in  matlabUser defined functions in  matlab
User defined functions in matlab
Infinity Tech Solutions
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignment
Ahmad Kamal
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
guest38bf
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
zueZ3
 
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
All chapters C++ - Copy.pdfytttttttttttttttttttttttttttttAll chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
jacobdiriba
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
Amarjith C K
 
Chapter - 4.pptx
Chapter - 4.pptxChapter - 4.pptx
Chapter - 4.pptx
MikialeTesfamariam
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
Md. Imran Hossain Showrov
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
nmahi96
 
Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted co...
Chapter 5   modularization & catch statement (paradiso-a45b1d's conflicted co...Chapter 5   modularization & catch statement (paradiso-a45b1d's conflicted co...
Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted co...
marco_paradiso
 
Abap function module help
Abap function module helpAbap function module help
Abap function module help
Kranthi Kumar
 
Functions part1
Functions part1Functions part1
Functions part1
yndaravind
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2
yndaravind
 
Lecture_5_-_Functions_in_C_Detailed.pptx
Lecture_5_-_Functions_in_C_Detailed.pptxLecture_5_-_Functions_in_C_Detailed.pptx
Lecture_5_-_Functions_in_C_Detailed.pptx
Salim Shadman Ankur
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignment
Ahmad Kamal
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
guest38bf
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
zueZ3
 
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
All chapters C++ - Copy.pdfytttttttttttttttttttttttttttttAll chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
jacobdiriba
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Ad

More from Milind Patil (20)

Abap slide class4 unicode-plusfiles
Abap slide class4 unicode-plusfilesAbap slide class4 unicode-plusfiles
Abap slide class4 unicode-plusfiles
Milind Patil
 
Step by step abap_input help or lov
Step by step abap_input help or lovStep by step abap_input help or lov
Step by step abap_input help or lov
Milind Patil
 
Step bystep abap_fieldhelpordocumentation
Step bystep abap_fieldhelpordocumentationStep bystep abap_fieldhelpordocumentation
Step bystep abap_fieldhelpordocumentation
Milind Patil
 
Step bystep abap_field help or documentation
Step bystep abap_field help or documentationStep bystep abap_field help or documentation
Step bystep abap_field help or documentation
Milind Patil
 
Abap slides user defined data types and data
Abap slides user defined data types and dataAbap slides user defined data types and data
Abap slides user defined data types and data
Milind Patil
 
Abap slides set1
Abap slides set1Abap slides set1
Abap slides set1
Milind Patil
 
Abap slide class3
Abap slide class3Abap slide class3
Abap slide class3
Milind Patil
 
Abap slide lock Enqueue data clusters auth checks
Abap slide lock Enqueue data clusters auth checksAbap slide lock Enqueue data clusters auth checks
Abap slide lock Enqueue data clusters auth checks
Milind Patil
 
Step bystep abap_changinga_singlerecord
Step bystep abap_changinga_singlerecordStep bystep abap_changinga_singlerecord
Step bystep abap_changinga_singlerecord
Milind Patil
 
Abap slide lockenqueuedataclustersauthchecks
Abap slide lockenqueuedataclustersauthchecksAbap slide lockenqueuedataclustersauthchecks
Abap slide lockenqueuedataclustersauthchecks
Milind Patil
 
Abap slide exceptionshandling
Abap slide exceptionshandlingAbap slide exceptionshandling
Abap slide exceptionshandling
Milind Patil
 
Step bystep abap_changinga_singlerecord
Step bystep abap_changinga_singlerecordStep bystep abap_changinga_singlerecord
Step bystep abap_changinga_singlerecord
Milind Patil
 
Lecture16 abap on line
Lecture16 abap on lineLecture16 abap on line
Lecture16 abap on line
Milind Patil
 
Lecture14 abap on line
Lecture14 abap on lineLecture14 abap on line
Lecture14 abap on line
Milind Patil
 
Lecture13 abap on line
Lecture13 abap on lineLecture13 abap on line
Lecture13 abap on line
Milind Patil
 
Lecture12 abap on line
Lecture12 abap on lineLecture12 abap on line
Lecture12 abap on line
Milind Patil
 
Lecture10 abap on line
Lecture10 abap on lineLecture10 abap on line
Lecture10 abap on line
Milind Patil
 
Lecture09 abap on line
Lecture09 abap on lineLecture09 abap on line
Lecture09 abap on line
Milind Patil
 
Lecture08 abap on line
Lecture08 abap on lineLecture08 abap on line
Lecture08 abap on line
Milind Patil
 
Abap slide class4 unicode-plusfiles
Abap slide class4 unicode-plusfilesAbap slide class4 unicode-plusfiles
Abap slide class4 unicode-plusfiles
Milind Patil
 
Step by step abap_input help or lov
Step by step abap_input help or lovStep by step abap_input help or lov
Step by step abap_input help or lov
Milind Patil
 
Step bystep abap_fieldhelpordocumentation
Step bystep abap_fieldhelpordocumentationStep bystep abap_fieldhelpordocumentation
Step bystep abap_fieldhelpordocumentation
Milind Patil
 
Step bystep abap_field help or documentation
Step bystep abap_field help or documentationStep bystep abap_field help or documentation
Step bystep abap_field help or documentation
Milind Patil
 
Abap slides user defined data types and data
Abap slides user defined data types and dataAbap slides user defined data types and data
Abap slides user defined data types and data
Milind Patil
 
Abap slide lock Enqueue data clusters auth checks
Abap slide lock Enqueue data clusters auth checksAbap slide lock Enqueue data clusters auth checks
Abap slide lock Enqueue data clusters auth checks
Milind Patil
 
Step bystep abap_changinga_singlerecord
Step bystep abap_changinga_singlerecordStep bystep abap_changinga_singlerecord
Step bystep abap_changinga_singlerecord
Milind Patil
 
Abap slide lockenqueuedataclustersauthchecks
Abap slide lockenqueuedataclustersauthchecksAbap slide lockenqueuedataclustersauthchecks
Abap slide lockenqueuedataclustersauthchecks
Milind Patil
 
Abap slide exceptionshandling
Abap slide exceptionshandlingAbap slide exceptionshandling
Abap slide exceptionshandling
Milind Patil
 
Step bystep abap_changinga_singlerecord
Step bystep abap_changinga_singlerecordStep bystep abap_changinga_singlerecord
Step bystep abap_changinga_singlerecord
Milind Patil
 
Lecture16 abap on line
Lecture16 abap on lineLecture16 abap on line
Lecture16 abap on line
Milind Patil
 
Lecture14 abap on line
Lecture14 abap on lineLecture14 abap on line
Lecture14 abap on line
Milind Patil
 
Lecture13 abap on line
Lecture13 abap on lineLecture13 abap on line
Lecture13 abap on line
Milind Patil
 
Lecture12 abap on line
Lecture12 abap on lineLecture12 abap on line
Lecture12 abap on line
Milind Patil
 
Lecture10 abap on line
Lecture10 abap on lineLecture10 abap on line
Lecture10 abap on line
Milind Patil
 
Lecture09 abap on line
Lecture09 abap on lineLecture09 abap on line
Lecture09 abap on line
Milind Patil
 
Lecture08 abap on line
Lecture08 abap on lineLecture08 abap on line
Lecture08 abap on line
Milind Patil
 
Ad

Recently uploaded (20)

UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 

Lecture11 abap on line

  • 1. Lecture 11 Subroutines & Function Modules BCO5647 Applications Programming Techniques (ABAP)
  • 2. Readings & Objectives Readings Keller & Keller Chapter 5 Section 5.1 & 5.2 Objectives This lecture will Discuss modularisation techniques and how these could be implemented in ABAP Introduce the concept of internal subroutines and how these are implemented in ABAP Examine how parameters are passed between the main program and subroutines Distinguish calling parameters by value and by reference Introduce the concept of function modules and their characteristics Demonstrate how function modules can be searched for in the repository Demonstrate how the features of a function module can be displayed Demonstrate how a function module can be called Demonstrate how errors in function modules can be captured and handled.
  • 3. Modularisation Techniques Modularisation enables us to reduce the complexity of large programs and to re-use code. Modularisation can be implemented using: Internal subroutines The subroutine and the call are in the same program. External subroutines The subroutine is in an external program. Function modules The subroutine is stored in the Function Library.
  • 4. Internal Subroutines (“Forms”) Internal subroutines are declared using the FORM and ENDFORM keywords. All subroutines should be placed at the end of the program. Subroutines are called using the PERFORM statement. Nested and recursive subroutine calls are permitted. Example : perform calculate_total. …… form calculate_total. …. statements endform .
  • 5. Global and Local Data Unless declared separately in an internal subroutine, data is global to the whole program. Data can be defined as being local to the subroutine by using the data keyword : data flag value 1 type i. write flag. perform write_flag. write flag. …….. form write_flag. data flag type i. flag = 2. write flag. endform.
  • 6. Passing Parameters Data can be passed from the calling program to a subroutine using parameters. Parameters may be described as: Read only - the parameter is read in the subroutine but is not changed. Changing - the parameter is read and changed by the subroutine. In general, the parameter passed must be of the same type as the parameter received by the subroutine. Data structures (eg internal tables) can also be passed as parameters.
  • 7. Passing Parameters - Example report ptest. data: val1 type p, val2 type p, val3 type p, val4 type p, answer type p, operator type c. val1 = 4. val2 = 2. operator = ‘+’. val3 = 8. val4 = 5. perform calc_answer using val1 val2 operator changing answer. operator = ‘-’. perform calc_answer using val3 val4 operator changing answer. ……… ... form calc_answer using fv1 fv2 op changing ans. case op. when ‘+’. ans = fv1 + fv2. when ‘-’. ans = fv1 - fv2. endcase. endform.
  • 8. Calling by Value and by Reference Parameters can be called either by reference or by value. Calling by reference : The address of the actual parameter is called. Changes have an immediate effect. If only the formal parameter name is specified in the subroutine interface, then the parameter is called by reference . Calling by value : When the subroutine is called, the actual parameter value is copied to the formal parameter. There are two types of call by value.
  • 9. External Subroutines A program can make an external call to a subroutine in another program. Example : report main. data: name(20). …. perform print_name(process) using name. …. report process. …. form print_name using name1. …. endform.
  • 10. Function M odules A function module is a separate program that can be called from your ABAP code to perform a specific task. SAP comes with a library of pre-written function modules. Function modules are pooled together into function groups . E.g. calendar functions Function modules have a clearly defined fixed interface for data exchange. The interface supports exception handling. Function modules use their own memory area.
  • 11. Searching for a Function Module Go to the Function Builder: SAP Standard Menu >> Development >> Function Builder. Transaction Code SE37. Searching can be done using the Repository Information System or SAP’s Application hierarchy . Click Matchcode Button
  • 12. Displaying a Function Module You can display information about existing function modules: Attributes: specifies administrative information like the person responsible for the module and a short description of the module. Import : contains a list of the formal parameters that are used to pass data to a function module. Export : contains a list of the formal parameters that are used to receive data from a function module.
  • 13. Displaying a Function Module You can display information about existing function modules: Changing : contains a list of the formal parameters that are used both to pass data to and receive data from a function module. Tables : specifies the tables that are to be passed to a function module. Table parameters are always passed by reference. Exceptions : s hows how the function module reacts to exceptions. Source code : program code of the function module . Documentation: provides information about the interface and exceptions .
  • 14. Calling a Function Module Function modules are called by the ABAP code using a CALL statement . To insert function into ABAP code click [Pattern] button on toolbar.

Editor's Notes

  • #4: Advantages : Because the external subroutines and function modules are self-contained, they can be debugged independently of each other. Changes only have to be made in the one program - all other programs that call that subroutine or function module will be affected by the change. The overall complexity of the program is reduced.
  • #5: When the perform command is executed, all statements between the form and endform are processed. Data defined in the ‘main’ program is global and can be used and changed in the subroutine. Double-Click on the subroutine name in the perform statement to create the subroutine at the bottom of the program code with documentation .
  • #6: The output from the above program would be 1 2 1. Where possible, local data should be used in a subroutine. The contents of a local data object can be retained from one call of the subroutine to the next by using static variables. Example : perform count. perform count. ….. form count. statics calls type i. calls = calls + 1. write calls. endform. … will produce the output 1 2.
  • #7: This is the preferred method for passing data to a subroutine. Internal tables are always global.
  • #8: The result from the first call : answer = 6. The result from the second call : answer = 3. The parameter names in the PERFORM statement are called ACTUAL PARAMETERS. The parameter names in the FORM statement are called FORMAL PARAMETERS. The above example passes parameters by reference. The next slide explains this.
  • #9: Parameters can be called either by reference or by value. Calling by reference: The address of the actual parameter is called. Within the subroutine, the variable is addressed using the formal parameter name and changes have an immediate. If only the formal parameter name is specified in the subroutine interface, then the parameter is called by reference. Calling by value: When the subroutine is called the actual parameter value is copied to the formal parameter. There are two types of call by value: Calling by value: the formal parameter is listed in the interface after the USING clause with the addition VALUE( <parameter name> ) . When the subroutine is called, the actual parameter is copied to the formal parameter. Changes made to the formal parameter only affect the local copy, not the actual parameter. Calling by value and result: the formal parameter is listed in the interface after the CHANGING clause with the addition VALUE( <parameter name> ) . When the subroutine is called, the actual parameter is copied to the formal parameter. Changes made to the formal parameter initially only affect the local copy. When the ENDFORM statement is reached, the formal parameter value is copied back to the actual parameter.
  • #10: All rules re passing of data as for internal subroutines, except that using parameters is the only way of passing data. (Global data in the calling program may not be referenced in the called subroutine.) SAP do not recommend using External Subroutines.
  • #11: Examples of Function Modules : Calculates whether a date falls on a Sunday. Rounding a number with decimals to 2 places. Function modules possess a clearly defined fixed interface for data exchange. This makes it easier for you to pass input and output parameters to and from the function module. The function module interface supports exception handling. This allows you to catch errors and pass them back to the calling program for handling. Function modules use their own memory area. The calling program and the function module cannot exchange data using a shared memory area - they must use the function module interface. This avoids unpleasant side effects such as accidentally overwriting data. How many function modules are supplied with SAP? In release 3.1, more than 43,000 function modules are available. In rel 4.5 more than 80,000 function modules are available. (4.6B > 98,000; Enterprise > 170,000) The are many thousands of function groups which contain function modules.
  • #12: Hint: Add Function Builder to Favorites Information system allows you to search for function modules using search criteria of function name, short description and/or function group. SAP Applications allows you to list function modules associated with application components such as FI, SD, MM.
  • #14: NOTES: Changing parameters appears to be new in ver 4.0 or greater Documentation can be found in the Goto pull-down menu.
  • #15: {Pattern} button will display Insert Statement dialog. Enter or search for required function and click Continue to insert function into ABAP Editor. Ctrl-F6 shortcut to produce Insert Statement dialog.
  • #16: Once the function module template is inserted, it is up to the programmer to fill it in. Note the use of ‘X’ for export SIGN variable. This comes from the function’s documentation where the code “X” indicates commercial rounding. The use of the MESSAGE Statement with system message codes allows the function to handle error processing and produce appropriate error messages. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. You can choose to handle errors yourself and define your own error messages by replacing the above code with something like: CASE SY-SUBRC. WHEN 0. write: inputnum, ' commercially rounded = ', rounded. WHEN 1. write 'Input Invalid'. WHEN 2. write 'Overflow Error'. WHEN 3. write 'Output Field type Invalid'. WHEN 4. write 'Unknown Error'. ENDCASE.