Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)
-
Upload
marcoparadiso -
Category
Technology
-
view
481 -
download
0
description
Transcript of Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)
![Page 1: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/1.jpg)
ABAP Chapter 5
Modularization Catch Statement
![Page 2: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/2.jpg)
Modularization
![Page 3: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/3.jpg)
Modularization
Internal Subroutine Call
External Subroutine Call
Function Module
![Page 4: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/4.jpg)
SubroutineSTART-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.…
![Page 5: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/5.jpg)
Modularization
Avoid redundancy Make your program easy to
read & improve their structure
Re-use Program components
![Page 6: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/6.jpg)
Calling and Defining SubroutinesCalling and Defining Subroutines REPORT ztest.
* Global Data TABLES customers.
DATA tmp type i. * Subroutine Calls
PERFORM routine1. PERFORM routine2.
SSSSSSSSSS *
FORM routine1. DATA tmp1 type p. SSSS“ write tmp.ENDFORM.
2FORM routine . DATA tmp2(10). “Localdata
…. .ENDFORM.
![Page 7: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/7.jpg)
Call by Value
a1
Memory Space(Subroutine)
f1
Copy
![Page 8: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/8.jpg)
Call by ValueCall by Value
1 2Data: a ,a .a1 = ‘A’.a2 = ‘A’. SSS11 2. .…...
1 1 2FORM routine USING VALUE(f ) VALUE(f ). f1 = ‘X’. f2 = ‘X’.ENDFORM.
![Page 9: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/9.jpg)
Call by Reference
a3
Memory Space(Subroutine)
f3
Address Passing
![Page 10: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/10.jpg)
Call by ReferenceCall by Reference
: 3.Data aa3 = ‘A’.
2 3PERFORM routine USING a . .…...
2 3FORM routine USING f . f3 = ‘X’.ENDFORM.
![Page 11: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/11.jpg)
Call by Value and Result
a4
Memory Space(Subroutine)
f4
CopyCopy
![Page 12: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/12.jpg)
Call by Value and ResultCall by Value and Result
: 4, 5.Data a aa4 = ‘A’.a5 = ‘A’.
3 4 5PERFORM routine USING a a . .…...
FORM routine3 ( 4) 5. “f5 : call by reference f4 = ‘X’. f5 = ‘X’.ENDFORM.
![Page 13: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/13.jpg)
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.
![Page 14: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/14.jpg)
Passing Internal Table as ParametersPassing Internal Table as Parameters
0DATA: tab LIKE sflight OCCURS WITH HEADER LINE. …SSSSSSS sub TABLES tab.
![Page 15: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/15.jpg)
Passing Internal Table as ParametersPassing Internal Table as Parameters
FORM sub TABLES tab1 STRUCTURE tab. LOOP AT tab1. WRITE: / tab1-carrid. ENDLOOP.ENDFORM.
![Page 16: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/16.jpg)
External SubroutinesExternal Subroutines
10REPORT RSAAA F. : . …. . ( 10).
10REPORT RSAAA B. TABLES sflight.
…. . FORM cal.
…. ..
![Page 17: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/17.jpg)
EXIT StatementEXIT Statement
DATA tmp TYPE I.tmp = 4.PERFORM a.WRITE tmp.
FORM a. EXIT. tmp = 99.ENDFORM.
![Page 18: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/18.jpg)
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.
![Page 19: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/19.jpg)
Function Module
![Page 20: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/20.jpg)
Function Module
Function Group Function Library - Admin - Import/Export Parameter - Source Code - Main Program - Documentation
![Page 21: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/21.jpg)
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 loaded in a program the first time that you call a function module that belongs to it
![Page 22: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/22.jpg)
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 shared by all the function modules that belong to that function group
![Page 23: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/23.jpg)
Function Group : SE37
![Page 24: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/24.jpg)
Function Group : SE80
![Page 25: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/25.jpg)
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 information in its own code, and then sends back information in the export parameters or internal tables
![Page 26: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/26.jpg)
Function Module : SE37
![Page 27: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/27.jpg)
Function Module
![Page 28: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/28.jpg)
Function Module : Source CodeFunction Module : Source Code
FUNCTION Z_FMTEST. result = number1 ** number2.ENDFUNCTION.
![Page 29: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/29.jpg)
Program Example IProgram Example I
REPORT ztest. PARAMETERS: no1 SSSS I,
no2 TYPE I.DATA result TYPE I.START-OF-SELECTION. CALL FUNCTION ‘Z_FMTEST’ EXPORTING number1 = no1 number2 = no2 IMPORTING SSSSSS = result.
write: / result.
![Page 30: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/30.jpg)
Exercise : Function Module
?
ABAP Program
Function Module
![Page 31: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/31.jpg)
EXCEPTIONS
![Page 32: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/32.jpg)
Function ModuleFunction Module
Function Z_CAL01. if number1 > 9 and number2 > 9. raise invalidnumber. else. result = number1 ** number2. endif.ENDFUNCTION.
![Page 33: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/33.jpg)
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.
![Page 34: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/34.jpg)
Exercise : Exceptions
?
ABAP Program
Function Module
![Page 35: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/35.jpg)
EXCEPTIONS VS AT SELECTION-SCREEN
FUNCTION Z_CAL01. if number1 > 9 and number2 > 9. raise invalidnumber. else. result = number1 ** number2. endif.ENDFUNCTION.
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 < 10’. endif.START-OF-SELECTION. CALL FUNCTION ‘Z_CAL01’. …..
VS
![Page 36: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/36.jpg)
Optional
ABAP Program
Function Module
![Page 37: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/37.jpg)
Structure in Function Module
![Page 38: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/38.jpg)
Example : Structure
![Page 39: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/39.jpg)
Example : Structure
![Page 40: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/40.jpg)
Internal Table in Function Module
![Page 41: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/41.jpg)
Example : Internal Table
![Page 42: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/42.jpg)
Example : Internal Table
![Page 43: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/43.jpg)
Function Group
Function Group : ZGRP00
Function Module : Z_FMTEST
Function Module : Z_CAL01
![Page 44: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/44.jpg)
Function Group
![Page 45: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/45.jpg)
Function Module in Function Group
![Page 46: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/46.jpg)
Exercise Display current month name
using function module
![Page 47: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/47.jpg)
Catch Statement
![Page 48: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/48.jpg)
•Syntax - Catch system exceptions <error type> = <n>.
<ABAP statement – generate runtime error> .Endcatch.if sy-subrc = <n>. ...endif.
CATCH Statement CATCH Statement
![Page 49: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/49.jpg)
•Error class•Catch system-exceptions conversion_errors = 1.
•Single error•Catch system-exceptions convt_no_number = 1.
•All catchable runtime error•Catch system-exceptions others = 1.
CATCH Error TypeCATCH Error Type
![Page 50: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/50.jpg)
CATCH StatementCATCH Statement
Report ztest. Data num type I. - 1Catch system exceptions conversion_errors = .”others
Move ‘abc’ to num. SSSSSSS S SSSSSS SSSSSSSSSSSS SSSEndcatch.
- 1If sy subrc = . Write: / ‘Assign wrong data type to variable: num’.Endif.
![Page 51: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/51.jpg)
CATCH StatementCATCH Statement
Report ztest. Data num type I. - Catch system exceptions other 1s = .
Move ‘abc’ to num. Endcatch.
- 1If sy subrc = . Write: / ‘Assign wrong data type to variable: num’.Endif.
![Page 52: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/52.jpg)
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.
![Page 53: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/53.jpg)
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.
![Page 54: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/54.jpg)
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.
![Page 55: Chapter 5 modularization & catch statement (paradiso-a45b1d's conflicted copy 2012-08-25)](https://reader033.fdocuments.net/reader033/viewer/2022061113/545c874ab0af9f952c8b4919/html5/thumbnails/55.jpg)
ABAP Practice