SlideShare a Scribd company logo
1 of 55
ABAP Chapter 5
 Modularization
 Catch Statement
Modularization
Modularization
 Internal Subroutine
Call
 External Subroutine
Call
 Function Module
Subroutine
START-OF-SELECTION.
Perfrom routine1.
Perform routine2.
Perform routine2.
Form routine1.
select * from customers into table tab.
Endform.
Form routine2.
loop at tab.
write: / tab-id,tab-name.
endloop.
Endform.
…
Modularization
 Avoid redundancy
 Make your program easy to
read & improve their structure
 Re-use Program components
Calling and Defining SubroutinesCalling and Defining Subroutines
REPORT ztest.
* Global Data
TABLES customers.
DATA tmp type i.
* Subroutine Calls
PERFORM routine1.
PERFORM routine2.
* Subroutine
FORM routine1.
DATA tmp1 type p. “Local data
write tmp.
ENDFORM.
FORM routine2.
DATA tmp2(10). “Local data
…..
ENDFORM.
Call by Value
a1
Memory Space(Subroutine)
f1
Copy
Call by ValueCall by Value
Data: a1,a2.
a1 = ‘A’.
a2 = ‘A’.
PERFORM routine1 USING a1 a2.
.…...
FORM routine1 USING VALUE(f1) VALUE(f2).
f1 = ‘X’.
f2 = ‘X’.
ENDFORM.
Call by Reference
a3
Memory Space(Subroutine)
f3
Address Passing
Call by ReferenceCall by Reference
Data: a3.
a3 = ‘A’.
PERFORM routine2 USING a3.
.…...
FORM routine2 USING f3.
f3 = ‘X’.
ENDFORM.
Call by Value and Result
a4
Memory Space(Subroutine)
f4
CopyCopy
Call by Value and ResultCall by Value and Result
a4,a5.
A’.
A’.
RM routine3 USING a4 a5.
routine3 CHANGING VALUE(f4) f5. “f5 : call by ref
‘X’.
‘X’.
ORM.
Passing Structure as ParametersPassing Structure as Parameters
TABLES sflight.
SELECT * FROM sflight.
PERFORM subproc USING sflight.
ENDSELECT.
FORM subproc USING rec LIKE sflight.
WRITE: / rec-carrid.
ENDFORM.
Passing Internal Table as ParametersPassing Internal Table as Parameters
TA: tab LIKE sflight OCCURS 0 WITH HEADER L
FORM sub TABLES tab.
Passing Internal Table as ParametersPassing Internal Table as Parameters
FORM sub TABLES tab1 STRUCTURE tab.
LOOP AT tab1.
WRITE: / tab1-carrid.
ENDLOOP.
ENDFORM.
External SubroutinesExternal Subroutines
REPORT RSAAA10F.
TABLES: sflight.
…..
PERFORM cal(RSAAA10B).
REPORT RSAAA10B.
TABLES sflight.
…..
FORM cal.
…..
ENDFORM.
EXIT StatementEXIT Statement
DATA tmp TYPE I.
tmp = 4.
PERFORM a.
WRITE tmp.
FORM a.
EXIT.
tmp = 99.
ENDFORM.
STOP StatementSTOP Statement
DATA tmp TYPE I.
START-OF-SELECTION.
tmp = 4.
PERFORM a.
WRITE tmp.
END-OF-SELECTION.
tmp = 0.
write tmp.
FORM a.
STOP. “go to END-OF-SELECTION
tmp = 99.
ENDFORM.
Function Module
Function Module
 Function Group
 Function Library
- Admin
- Import/Export Parameter
- Source Code
- Main Program
- Documentation
Function Group
 When you create a function
module, you must assign it to
function group
 The function group is the main
program in which a function
module is embedded
 The function group is a program
type F,and not executable
 The entire function group is
Function Group
 is a container for function
modules
 When a function module is
called,the entire function group is
loaded into the session of the
program
 Function group is used to define
global data for function modules
 A DATA statement in the global
memory of a function group is
Function Group : SE37
Function Group : SE80
Function Module
 is a code that can be called from
any ABAP program,therefore
making it a globally accessible
object
 ABAP program pass data to
function module from import
parameters or internal tables
 Function module receives data
from a program,process the
Function Module : SE37
Function Module
Function Module : Source CodeFunction Module : Source Code
FUNCTION Z_FMTEST.
result = number1 ** number2.
ENDFUNCTION.
Program Example IProgram Example I
REPORT ztest.
PARAMETERS: no1 TYPE I,
no2 TYPE I.
DATA result TYPE I.
START-OF-SELECTION.
CALL FUNCTION ‘Z_FMTEST’
EXPORTING
number1 = no1
number2 = no2
IMPORTING
result = result.
write: / result.
Exercise : Function Module
?
ABAP Program
Function Module
EXCEPTIONS
Function ModuleFunction Module
Function Z_CAL01.
if number1 > 9 and number2 > 9.
raise invalidnumber.
else.
result = number1 ** number2.
endif.
ENDFUNCTION.
Example II : ExceptionsExample II : Exceptions
REPORT ztest.
PARAMETERS: no1 TYPE I,
no2 TYPE I.
DATA result TYPE I.
START-OF-SELECTION.
CALL FUNCTION ‘Z_CAL01’
EXPORTING
number1 = no1
number2 = no2
IMPORTING
result = result
EXCEPTIONS
invalidnumber = 1.
IF sy-subrc <> 0.
write: / ‘Please enter number < 10’.
ELSE.
write: / result.
ENDIF.
Exercise : Exceptions
?
ABAP Program
Function Module
EXCEPTIONS VS AT SELECTION-SCREEN
NCTION Z_CAL01.
number1 > 9 and number2 > 9.
raise invalidnumber.
lse.
result = number1 ** number2.
ndif.
DFUNCTION.
REPORT ztest.
Parameters: no1 type i,
no2 type i.
At selection-screen
if no1 > 9 and no2 > 9.
message e000(38) with ‘Please enter no <
endif.
START-OF-SELECTION.
CALL FUNCTION ‘Z_CAL01’.
…..
VS
Optional
ABAP Program
Function Module
Structure in Function Module
Example : Structure
Example : Structure
Internal Table in Function Module
Example : Internal Table
Example : Internal Table
Function Group
Function Group : ZGRP00
Function Module : Z_FMTEST
Function Module : Z_CAL01
Function Group
Function Module in Function
Group
Exercise
 Display current month name
using function module
Catch Statement
•Syntax
Catch system-exceptions <error type> = <n>.
<ABAP statement – generate runtime error> .
Endcatch.
if sy-subrc = <n>.
...
endif.
CATCH StatementCATCH Statement
Error class
•Catch system-exceptions conversion_errors
ingle error
•Catch system-exceptions convt_no_number
All catchable runtime error
•Catch system-exceptions others = 1.
CATCH Error TypeCATCH Error Type
CATCH StatementCATCH Statement
eport ztest.
Data num type I.
atch system-exceptions conversion_errors = 1.”oth
Move ‘abc’ to num. “runtime error: convt_no_numbe
ndcatch.
f sy-subrc = 1.
Write: / ‘Assign wrong data type to variable: num’
ndif.
CATCH StatementCATCH Statement
Report ztest.
Data num type I.
Catch system-exceptions others = 1.
Move ‘abc’ to num.
Endcatch.
If sy-subrc = 1.
Write: / ‘Assign wrong data type to variable: num
Endif.
CATCH StatementCATCH Statement
Report ztest.
PARAMETERS: NUM1 TYPE I,
NUM2 TYPE I.
DATA RESULT TYPE I.
START-OF-SELECTION.
CATCH SYSTEM-EXCEPTIONS COMPUTE_INT_ZERODIVIDE = 1.
RESULT = NUM1 / NUM2.
ENDCATCH.
IF SY-SUBRC = 1.
WRITE: /'Divide by zero'.
ELSE.
WRITE: / RESULT.
ENDIF.
CATCH StatementCATCH Statement
Report ztest.
PARAMETERS: NUM1 TYPE I,
NUM2 TYPE I.
DATA RESULT TYPE I.
START-OF-SELECTION.
CATCH SYSTEM-EXCEPTIONS OTHERS = 1.
RESULT = NUM1 / NUM2.
ENDCATCH.
IF SY-SUBRC = 1.
WRITE: /'Divide by zero'.
ELSE.
WRITE: / RESULT.
ENDIF.
CATCH in Function Module
Function Z_CAL.
if number1 > 9 and number2 > 9.
raise invalidnumber.
else.
result = number1 ** number2.
endif.
ENDFUNCTION.
Function Z_CAL.
CATCH SYSTEM-EXCEPTIONS OTHERS = 1.
RESULT = NUMBER1 ** NUMBER2.
ENDCATCH.
IF SY-SUBRC = 1.
RAISE invalidnumber.
ENDIF.
ENDFUNCTION.
ABAP Practice

More Related Content

What's hot

Message, Debugging, File Transfer and Type Group
Message, Debugging, File Transfer and Type GroupMessage, Debugging, File Transfer and Type Group
Message, Debugging, File Transfer and Type Groupsapdocs. info
 
Sap abap modularization interview questions
Sap abap modularization interview questionsSap abap modularization interview questions
Sap abap modularization interview questionsPradipta Mohanty
 
0105 abap programming_overview
0105 abap programming_overview0105 abap programming_overview
0105 abap programming_overviewvkyecc1
 
Project FoX: A Tool That Offers Automated Testing Using a Formal Approach
Project FoX: A Tool That Offers Automated Testing Using a Formal ApproachProject FoX: A Tool That Offers Automated Testing Using a Formal Approach
Project FoX: A Tool That Offers Automated Testing Using a Formal ApproachIvo Neskovic
 
15 functions
15 functions15 functions
15 functionsfyjordan9
 
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 dti2143alish sha
 
user defined functions in c language
user defined functions in c languageuser defined functions in c language
user defined functions in c languageDeepRaval7
 
Ch10 Program Organization
Ch10 Program OrganizationCh10 Program Organization
Ch10 Program OrganizationSzeChingChen
 
3 modularisation and bdc
3 modularisation and bdc3 modularisation and bdc
3 modularisation and bdcSiva Kumar
 
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 ABAPNoman Mohamed Hanif
 

What's hot (20)

Message, Debugging, File Transfer and Type Group
Message, Debugging, File Transfer and Type GroupMessage, Debugging, File Transfer and Type Group
Message, Debugging, File Transfer and Type Group
 
Functional programming in python
Functional programming in pythonFunctional programming in python
Functional programming in python
 
Functional programming in python
Functional programming in pythonFunctional programming in python
Functional programming in python
 
Abap slides set1
Abap slides set1Abap slides set1
Abap slides set1
 
Functions
FunctionsFunctions
Functions
 
Sap abap modularization interview questions
Sap abap modularization interview questionsSap abap modularization interview questions
Sap abap modularization interview questions
 
0105 abap programming_overview
0105 abap programming_overview0105 abap programming_overview
0105 abap programming_overview
 
Functions and return type
Functions and return typeFunctions and return type
Functions and return type
 
Project FoX: A Tool That Offers Automated Testing Using a Formal Approach
Project FoX: A Tool That Offers Automated Testing Using a Formal ApproachProject FoX: A Tool That Offers Automated Testing Using a Formal Approach
Project FoX: A Tool That Offers Automated Testing Using a Formal Approach
 
Orcal FUNCTIONS
Orcal FUNCTIONSOrcal FUNCTIONS
Orcal FUNCTIONS
 
15 functions
15 functions15 functions
15 functions
 
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
 
user defined functions in c language
user defined functions in c languageuser defined functions in c language
user defined functions in c language
 
Ch10 Program Organization
Ch10 Program OrganizationCh10 Program Organization
Ch10 Program Organization
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
Function
FunctionFunction
Function
 
Ch9 Functions
Ch9 FunctionsCh9 Functions
Ch9 Functions
 
User defined functions.1
User defined functions.1User defined functions.1
User defined functions.1
 
3 modularisation and bdc
3 modularisation and bdc3 modularisation and bdc
3 modularisation and bdc
 
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
 

Viewers also liked

Unit 2 - Object Navigator, Repository and ABAP Programs
Unit 2 - Object Navigator, Repository and ABAP ProgramsUnit 2 - Object Navigator, Repository and ABAP Programs
Unit 2 - Object Navigator, Repository and ABAP Programsdubon07
 
Abap course chapter 2 tools in the development environment
Abap course   chapter 2 tools in the development environmentAbap course   chapter 2 tools in the development environment
Abap course chapter 2 tools in the development environmentMilind Patil
 
Abap course chapter 3 basic concepts
Abap course   chapter 3 basic conceptsAbap course   chapter 3 basic concepts
Abap course chapter 3 basic conceptsMilind Patil
 
Sap abap ppt
Sap abap pptSap abap ppt
Sap abap pptvonline
 
Beginner’s guide to sap abap 1
Beginner’s guide to sap abap 1Beginner’s guide to sap abap 1
Beginner’s guide to sap abap 1Panduka Bandara
 
List Processing in ABAP
List Processing in ABAPList Processing in ABAP
List Processing in ABAPsapdocs. info
 
SAP ABAP - Needed Notes
SAP   ABAP - Needed NotesSAP   ABAP - Needed Notes
SAP ABAP - Needed NotesAkash Bhavsar
 
ABAP Event-driven Programming &Selection Screen
ABAP Event-driven Programming &Selection ScreenABAP Event-driven Programming &Selection Screen
ABAP Event-driven Programming &Selection Screensapdocs. info
 
ABAP Open SQL & Internal Table
ABAP Open SQL & Internal TableABAP Open SQL & Internal Table
ABAP Open SQL & Internal Tablesapdocs. info
 
Introduction to ABAP
Introduction to ABAPIntroduction to ABAP
Introduction to ABAPsapdocs. info
 

Viewers also liked (10)

Unit 2 - Object Navigator, Repository and ABAP Programs
Unit 2 - Object Navigator, Repository and ABAP ProgramsUnit 2 - Object Navigator, Repository and ABAP Programs
Unit 2 - Object Navigator, Repository and ABAP Programs
 
Abap course chapter 2 tools in the development environment
Abap course   chapter 2 tools in the development environmentAbap course   chapter 2 tools in the development environment
Abap course chapter 2 tools in the development environment
 
Abap course chapter 3 basic concepts
Abap course   chapter 3 basic conceptsAbap course   chapter 3 basic concepts
Abap course chapter 3 basic concepts
 
Sap abap ppt
Sap abap pptSap abap ppt
Sap abap ppt
 
Beginner’s guide to sap abap 1
Beginner’s guide to sap abap 1Beginner’s guide to sap abap 1
Beginner’s guide to sap abap 1
 
List Processing in ABAP
List Processing in ABAPList Processing in ABAP
List Processing in ABAP
 
SAP ABAP - Needed Notes
SAP   ABAP - Needed NotesSAP   ABAP - Needed Notes
SAP ABAP - Needed Notes
 
ABAP Event-driven Programming &Selection Screen
ABAP Event-driven Programming &Selection ScreenABAP Event-driven Programming &Selection Screen
ABAP Event-driven Programming &Selection Screen
 
ABAP Open SQL & Internal Table
ABAP Open SQL & Internal TableABAP Open SQL & Internal Table
ABAP Open SQL & Internal Table
 
Introduction to ABAP
Introduction to ABAPIntroduction to ABAP
Introduction to ABAP
 

Similar to Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)

Modularization & Catch Statement
Modularization & Catch StatementModularization & Catch Statement
Modularization & Catch Statementsapdocs. info
 
Complete reference to_abap_basics
Complete reference to_abap_basicsComplete reference to_abap_basics
Complete reference to_abap_basicsAbhishek Dixit
 
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.pdfSowmyaJyothi3
 
Basic information of function in cpu
Basic information of function in cpuBasic information of function in cpu
Basic information of function in cpuDhaval Jalalpara
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxKhurramKhan173
 
Subroutines rev01 fa16
Subroutines rev01 fa16Subroutines rev01 fa16
Subroutines rev01 fa16John Todora
 
ERP Magazine April 2018 Issue 1
ERP Magazine April 2018 Issue 1 ERP Magazine April 2018 Issue 1
ERP Magazine April 2018 Issue 1 Rehan Zaidi
 
ERP Magazine April 2018 - The magazine for SAP ABAP Professionals
ERP Magazine April 2018 - The magazine for SAP ABAP ProfessionalsERP Magazine April 2018 - The magazine for SAP ABAP Professionals
ERP Magazine April 2018 - The magazine for SAP ABAP ProfessionalsRehan Zaidi
 
modularization-160202092213 (1).pdf
modularization-160202092213 (1).pdfmodularization-160202092213 (1).pdf
modularization-160202092213 (1).pdfSreeramBaddila
 
Functions part1
Functions part1Functions part1
Functions part1yndaravind
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2yndaravind
 
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptxChapter 1_C Fundamentals_HS_Tech Yourself C.pptx
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptxssuser71a90c
 
c.p function
c.p functionc.p function
c.p functiongiri5624
 
Sap abap modularization interview questions
Sap abap modularization interview questionsSap abap modularization interview questions
Sap abap modularization interview questionsPradipta Mohanty
 

Similar to Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25) (20)

Modularization & Catch Statement
Modularization & Catch StatementModularization & Catch Statement
Modularization & Catch Statement
 
Complete reference to_abap_basics
Complete reference to_abap_basicsComplete reference to_abap_basics
Complete reference to_abap_basics
 
Call
CallCall
Call
 
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
 
Basic information of function in cpu
Basic information of function in cpuBasic information of function in cpu
Basic information of function in cpu
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
Subroutines rev01 fa16
Subroutines rev01 fa16Subroutines rev01 fa16
Subroutines rev01 fa16
 
ERP Magazine April 2018 Issue 1
ERP Magazine April 2018 Issue 1 ERP Magazine April 2018 Issue 1
ERP Magazine April 2018 Issue 1
 
ERP Magazine April 2018 - The magazine for SAP ABAP Professionals
ERP Magazine April 2018 - The magazine for SAP ABAP ProfessionalsERP Magazine April 2018 - The magazine for SAP ABAP Professionals
ERP Magazine April 2018 - The magazine for SAP ABAP Professionals
 
modularization-160202092213 (1).pdf
modularization-160202092213 (1).pdfmodularization-160202092213 (1).pdf
modularization-160202092213 (1).pdf
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
 
Function in C
Function in CFunction in C
Function in C
 
Functions part1
Functions part1Functions part1
Functions part1
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2
 
Functions
FunctionsFunctions
Functions
 
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptxChapter 1_C Fundamentals_HS_Tech Yourself C.pptx
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
 
c.p function
c.p functionc.p function
c.p function
 
FUNCTIONS.pptx
FUNCTIONS.pptxFUNCTIONS.pptx
FUNCTIONS.pptx
 
Modular programming
Modular programmingModular programming
Modular programming
 
Sap abap modularization interview questions
Sap abap modularization interview questionsSap abap modularization interview questions
Sap abap modularization interview questions
 

Recently uploaded

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Recently uploaded (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)

  • 1. ABAP Chapter 5  Modularization  Catch Statement
  • 3. Modularization  Internal Subroutine Call  External Subroutine Call  Function Module
  • 4. Subroutine START-OF-SELECTION. Perfrom routine1. Perform routine2. Perform routine2. Form routine1. select * from customers into table tab. Endform. Form routine2. loop at tab. write: / tab-id,tab-name. endloop. Endform. …
  • 5. Modularization  Avoid redundancy  Make your program easy to read & improve their structure  Re-use Program components
  • 6. Calling and Defining SubroutinesCalling and Defining Subroutines REPORT ztest. * Global Data TABLES customers. DATA tmp type i. * Subroutine Calls PERFORM routine1. PERFORM routine2. * Subroutine FORM routine1. DATA tmp1 type p. “Local data write tmp. ENDFORM. FORM routine2. DATA tmp2(10). “Local data ….. ENDFORM.
  • 7. Call by Value a1 Memory Space(Subroutine) f1 Copy
  • 8. Call by ValueCall by Value Data: a1,a2. a1 = ‘A’. a2 = ‘A’. PERFORM routine1 USING a1 a2. .…... FORM routine1 USING VALUE(f1) VALUE(f2). f1 = ‘X’. f2 = ‘X’. ENDFORM.
  • 9. Call by Reference a3 Memory Space(Subroutine) f3 Address Passing
  • 10. Call by ReferenceCall by Reference Data: a3. a3 = ‘A’. PERFORM routine2 USING a3. .…... FORM routine2 USING f3. f3 = ‘X’. ENDFORM.
  • 11. Call by Value and Result a4 Memory Space(Subroutine) f4 CopyCopy
  • 12. Call by Value and ResultCall by Value and Result a4,a5. A’. A’. RM routine3 USING a4 a5. routine3 CHANGING VALUE(f4) f5. “f5 : call by ref ‘X’. ‘X’. ORM.
  • 13. Passing Structure as ParametersPassing Structure as Parameters TABLES sflight. SELECT * FROM sflight. PERFORM subproc USING sflight. ENDSELECT. FORM subproc USING rec LIKE sflight. WRITE: / rec-carrid. ENDFORM.
  • 14. Passing Internal Table as ParametersPassing Internal Table as Parameters TA: tab LIKE sflight OCCURS 0 WITH HEADER L FORM sub TABLES tab.
  • 15. Passing Internal Table as ParametersPassing Internal Table as Parameters FORM sub TABLES tab1 STRUCTURE tab. LOOP AT tab1. WRITE: / tab1-carrid. ENDLOOP. ENDFORM.
  • 16. External SubroutinesExternal Subroutines REPORT RSAAA10F. TABLES: sflight. ….. PERFORM cal(RSAAA10B). REPORT RSAAA10B. TABLES sflight. ….. FORM cal. ….. ENDFORM.
  • 17. EXIT StatementEXIT Statement DATA tmp TYPE I. tmp = 4. PERFORM a. WRITE tmp. FORM a. EXIT. tmp = 99. ENDFORM.
  • 18. STOP StatementSTOP Statement DATA tmp TYPE I. START-OF-SELECTION. tmp = 4. PERFORM a. WRITE tmp. END-OF-SELECTION. tmp = 0. write tmp. FORM a. STOP. “go to END-OF-SELECTION tmp = 99. ENDFORM.
  • 20. Function Module  Function Group  Function Library - Admin - Import/Export Parameter - Source Code - Main Program - Documentation
  • 21. Function Group  When you create a function module, you must assign it to function group  The function group is the main program in which a function module is embedded  The function group is a program type F,and not executable  The entire function group is
  • 22. Function Group  is a container for function modules  When a function module is called,the entire function group is loaded into the session of the program  Function group is used to define global data for function modules  A DATA statement in the global memory of a function group is
  • 25. Function Module  is a code that can be called from any ABAP program,therefore making it a globally accessible object  ABAP program pass data to function module from import parameters or internal tables  Function module receives data from a program,process the
  • 28. Function Module : Source CodeFunction Module : Source Code FUNCTION Z_FMTEST. result = number1 ** number2. ENDFUNCTION.
  • 29. Program Example IProgram Example I REPORT ztest. PARAMETERS: no1 TYPE I, no2 TYPE I. DATA result TYPE I. START-OF-SELECTION. CALL FUNCTION ‘Z_FMTEST’ EXPORTING number1 = no1 number2 = no2 IMPORTING result = result. write: / result.
  • 30. Exercise : Function Module ? ABAP Program Function Module
  • 32. Function ModuleFunction Module Function Z_CAL01. if number1 > 9 and number2 > 9. raise invalidnumber. else. result = number1 ** number2. endif. ENDFUNCTION.
  • 33. Example II : ExceptionsExample II : Exceptions REPORT ztest. PARAMETERS: no1 TYPE I, no2 TYPE I. DATA result TYPE I. START-OF-SELECTION. CALL FUNCTION ‘Z_CAL01’ EXPORTING number1 = no1 number2 = no2 IMPORTING result = result EXCEPTIONS invalidnumber = 1. IF sy-subrc <> 0. write: / ‘Please enter number < 10’. ELSE. write: / result. ENDIF.
  • 34. Exercise : Exceptions ? ABAP Program Function Module
  • 35. EXCEPTIONS VS AT SELECTION-SCREEN NCTION Z_CAL01. number1 > 9 and number2 > 9. raise invalidnumber. lse. result = number1 ** number2. ndif. DFUNCTION. REPORT ztest. Parameters: no1 type i, no2 type i. At selection-screen if no1 > 9 and no2 > 9. message e000(38) with ‘Please enter no < endif. START-OF-SELECTION. CALL FUNCTION ‘Z_CAL01’. ….. VS
  • 40. Internal Table in Function Module
  • 43. Function Group Function Group : ZGRP00 Function Module : Z_FMTEST Function Module : Z_CAL01
  • 45. Function Module in Function Group
  • 46. Exercise  Display current month name using function module
  • 48. •Syntax Catch system-exceptions <error type> = <n>. <ABAP statement – generate runtime error> . Endcatch. if sy-subrc = <n>. ... endif. CATCH StatementCATCH Statement
  • 49. Error class •Catch system-exceptions conversion_errors ingle error •Catch system-exceptions convt_no_number All catchable runtime error •Catch system-exceptions others = 1. CATCH Error TypeCATCH Error Type
  • 50. CATCH StatementCATCH Statement eport ztest. Data num type I. atch system-exceptions conversion_errors = 1.”oth Move ‘abc’ to num. “runtime error: convt_no_numbe ndcatch. f sy-subrc = 1. Write: / ‘Assign wrong data type to variable: num’ ndif.
  • 51. CATCH StatementCATCH Statement Report ztest. Data num type I. Catch system-exceptions others = 1. Move ‘abc’ to num. Endcatch. If sy-subrc = 1. Write: / ‘Assign wrong data type to variable: num Endif.
  • 52. CATCH StatementCATCH Statement Report ztest. PARAMETERS: NUM1 TYPE I, NUM2 TYPE I. DATA RESULT TYPE I. START-OF-SELECTION. CATCH SYSTEM-EXCEPTIONS COMPUTE_INT_ZERODIVIDE = 1. RESULT = NUM1 / NUM2. ENDCATCH. IF SY-SUBRC = 1. WRITE: /'Divide by zero'. ELSE. WRITE: / RESULT. ENDIF.
  • 53. CATCH StatementCATCH Statement Report ztest. PARAMETERS: NUM1 TYPE I, NUM2 TYPE I. DATA RESULT TYPE I. START-OF-SELECTION. CATCH SYSTEM-EXCEPTIONS OTHERS = 1. RESULT = NUM1 / NUM2. ENDCATCH. IF SY-SUBRC = 1. WRITE: /'Divide by zero'. ELSE. WRITE: / RESULT. ENDIF.
  • 54. CATCH in Function Module Function Z_CAL. if number1 > 9 and number2 > 9. raise invalidnumber. else. result = number1 ** number2. endif. ENDFUNCTION. Function Z_CAL. CATCH SYSTEM-EXCEPTIONS OTHERS = 1. RESULT = NUMBER1 ** NUMBER2. ENDCATCH. IF SY-SUBRC = 1. RAISE invalidnumber. ENDIF. ENDFUNCTION.