Professional Documents
Culture Documents
Modularization is breaking down the application code into smaller units, so that it is easy
to maintain. Suppose if we want to implement the same logic like adding two numbers in
several places of the same program, then write the logic inside a modularization unit and
call the modularization unit where ever we want to add two numbers.
Even if we want to declare the same variables in multiple programs or use the same logic
in different programs then code the common part in the modularization unit and use it in
different programs.
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.
Include Programs – Include programs allow you to use the same source code in
different programs. They are mainly used for modularizing source code and have
no parameter interface.
Subroutines – Subroutines are normally called internally i.e. called from the
same program in which it is declared. But subroutines can also be called from
external programs.
Function Modules – Function Modules are stored in the central library and can
be called from any program. Even the function modules(RFC enabled) can be
called from non-SAP systems.
Methods – Methods used ABAP object oriented programming
Event Blocks – Event blocks begin with a event code and ends with next
processing block.
Dialog Modules – Dialog Modules are used in PBO and PAI events of Module
Pool programs.
Include programs are not standalone programs and cannot be executed independently.
They can be used as a container for ABAP source code. They are used to organize the
ABAP source code into small editable units which can be inserted at any place in other
ABAP programs using the INCLUDE statement. Include programs can be used in
different programs. The include statement copies the contents of the include program into
the main program.
Include programs have no parameter interface and they cannot call themselves.
While creating the INCLUDE program using the ABAP editor choose program type as
"I" i.e. INCLUDE program in the program attributes.
REPORT zmain_program.
INCLUDE zinclude_data.
INCLUDE zinclude_write.
Output
Subroutines are procedures that we define in an ABAP program and can be called from
any program. Subroutines are normally called internally, i.e. called from the same
program in which it is defined. But it is also possible to call a subroutine from an external
program. Subroutines cannot be nested and are usually defined at the end of the program.
ENDFORM.
Example Program.
PERFORM sub_display.
WRITE:/ 'After Perform'.
*&---------------------------------------------------------------------*
*& Form sub_display
*&---------------------------------------------------------------------*
FORM sub_display.
WRITE:/ 'Inside Subroutine'.
ENDFORM. " sub_display
Output
Subroutines can call other subroutines and may also call themselves. Once a subroutine
has finished running, the control returns to the next statement after the PERFORM
statement.
PERFORM sub_display.
WRITE:/ 'After Perform Statement'.
*&---------------------------------------------------------------------*
*& Form sub_display
*&---------------------------------------------------------------------*
FORM sub_display.
WRITE:/ 'Before Exit Statement'.
EXIT.
WRITE:/ 'After Exit Statement'. " This will not be executed
ENDFORM. " sub_display
Output
*&---------------------------------------------------------------------*
*& Form sub_display
*&---------------------------------------------------------------------*
FORM sub_display.
WRITE:/ 'Before Check Statement'.
Output
Messages in ABAP
Messages are usually used to tell the user what is going on. The following types of
messages are available in ABAP.
A Terminatio The message appears in a dialog box, and the program terminates. When the
n 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.
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.
Information message will be displayed in a dialog box. Once the user has confirmed the
message, the program continues immediately after the MESSAGE statement.
Error message in report programs will be displayed in the status bar and when the user
press enter, the program terminates.
Exit Message – No message is displayed, and the program terminates with a short dump.
Short dumps can be viewed in t-code ST22.
Instead of hardcode the message text in the program we can maintain the message text in
text symbols. In order to maintain text symbols use the menu path Goto->Text Elements-
>Text Symbols in ABAP editor.
In the text symbols screen we can maintain the messages with a 3 character identifier.
Related posts: