Modularization TQ
Modularization:
- It is a technique of dividing a main program into
smaller program for re-usability.
- Advantages of Modularization are as follows.
- Easier to read, maintain and debug.
- Eliminates redundancy of code and
increases re-usability of code .
1. Include
program:
Client dependent.
These must be inserted
in a main program.
2. Subroutine:
Contains piece of ABAP
code which are used for reusability.
Types of subroutines:
1. Local
subroutine [definition, implementation]
2. Global
subroutine [definition is available in one program, Implementation is available
in another program is called global OR external subroutine.
Parameters of
subroutine:
Using: Importing
Changing: Exporting
Tables: Importing
& Exporting
Types of passing
values:
1. Pass by
reference or pass by value:
In this actual &formal
parameters will referring to the same memory location. If any changes are made
to the formal parameters will also be effected.
2. Pass by
value:
Here we are changing the
formal parameter, but actual parameter, is not changed both are refering to
different memory.
Pass by value is
identified by the keyboard value ( ).
3. Pass by
value & return:
Actual & formal
parameters will be referring to separate memory locations.
If any changes are made
to formal parameters, the actual parameters will be changed only when
subroutine implementations or the entire subroutine is
executed.
Have no exception
parameters
Local subroutines.
Can’t be tested
independetly.
Is not remote enable.
A subroutine can be
defined using FORM and ENDFORM statements.
FORM .
...
ENDFORM.
A subroutine can be
called using PERFORM statement.
PERFORM .
3. Functional module:
A functional module is a
sub program which contains piece of code which is used for specific task.
Client independent.
Exceptions to rise the
error messages.
Global data.
Components of functional module:
Import- input to FM
Export-output to fm
Changing- import
& export
Tables- internal tables
as input & output
Exception- to catch the
certain type of errors
Source code-contain the
abap code for a fm
Can be remote enable.
Global data.
Can be tested
independently
Have exception
parameters to call exceptions.
4.
Macros – 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.
We can use the following
syntax to define a macro.
DEFINE .
...
END-OF-DEFINITION.
5. Message class:
All the messages are
stored in a class are called message class.
SE91 t-code.
Messages are usually used to tell the user what is going on. The following types of messages are available in ABAP.
A
|
Termination
|
The message appears in a dialog box, and the program terminates. When the user has confirmed the message, control returns to the next-highest area menu.
|
E
|
Error
|
Depending on the program context, an error dialog appears or the program terminates.
|
I
|
Status
|
The message appears in a dialog box. Once the user has confirmed the message, the program continues immediately after the MESSAGE statement.
|
S
|
Error
|
The program continues normally after the MESSAGE statement, and the message is displayed in the status bar of the next screen.
|
W
|
Warning
|
Depending on the program context, an error dialog appears or the program terminates.
|
X
|
Exit
|
No message is displayed, and the program terminates with a short dump. Program terminations with a short dump normally only occur when a runtime error occurs.
|
The syntax for issuing a message is as follows.
MESSAGE TYPE .
We can issue a status message as follows. Status message will be displayed in the status bar. After the message is displayed the program continues after the MESSAGE statement.
MESSAGE 'This is a status message' TYPE 'S'.
Information message will be displayed in a dialog box. Once the user has confirmed the message, the program continues immediately after the MESSAGE statement.
MESSAGE 'This is an information message' TYPE 'I'.
Error message in report programs will be displayed in the status bar and when the user press enter, the program terminates.
MESSAGE 'This is an error message' TYPE 'E'.
Warning message behaves similar to error message in report programs.
Exit Message – No message is displayed, and the program terminates with a short dump. Short dumps can be viewed in t-code ST22.
MESSAGE 'This produces short dump' TYPE 'X'.
Termination Message appears in a dialog box, and the program terminates. When the user has confirmed the message, control returns to the next-highest area menu.
MESSAGE 'This is termination message' TYPE 'A'.
What is a Message Class?
Message Class is a like a container which holds a number of different messages. Each message in the message class is identified with unique message number. So when you call a message in a ABAP program, you need to specify the message class and message number.
How to create a Message Class?
First go to t-code SE91 i.e. Message Maintenance, enter the name of the message class and click on create button.
Maintain the required message texts with message numbers. Then save the entries and assign it to proper development class and transport request. Once the message class is saved we can use it in our ABAP programs.
Messages can be issued as follows.
MESSAGE s000(ztest).
Output:
In the above code, the message number, message class and message type are specified in the MESSAGE statement. We can also specify the message class in the REPORT statement as shown below, so that we can skip the message class in the MESSAGE statements of the program.
REPORT zmessages
MESSAGE-ID ztest
.
MESSAGE s000.
We can also maintain placeholders for variables in messages.
In the above message “&” is the placeholder. At runtime the placeholders (&) will be replaced by the variable values specified in the MESSAGE statement.
REPORT zmessages MESSAGE-ID ztest.
MESSAGE s001
WITH ‘XYZ’ ’1000′
.
Output
The values “XYZ” and “1000” replaces the placeholders in the actual message.
Message parameters:
& is the symbol use to substitute a variable or parameter into the message.
No comments:
Post a Comment