SAP ABAP Introduction
SAP ABAP Introduction
What is ABAP?
The ABAP language was used by developers to develop the SAP R/3
platform. It was also planned to be used by SAP customers to enhance SAP
applications. The language was promoted towards more technical customers
with programming experience.
Why ABAP?
ABAP is one of the 4GLs (fourth-generation languages) first developed in the 1980s.
ABAP becomes as the language for developing programs for the client–server R/3
system, which SAP was first released in the year 1992.
In 1999, SAP released an object-oriented extension known as ABAP Objects along
with R/3 release 4.6.
In 2001, all but the most basic functions were written in ABAP.
In 2006, 7.0 version released that offer switch framework feature.
In 2012, 7.4 version released with Table expressions feature.
In 2015, 7.5 version released that start supporting Open SQL expressions.
In 2017, 7.52 version released with virtual sorting of the internal table feature.
In 2019, 7.54 (current) version released with many revisions of existing features.
The runtime system is a part of SAP kernel controls the ABAP programs
execution. The runtime system is responsible for processing ABAP
statements, controlling the screens flow logic and responding to events (For
example - a user clicking on a button existed on the screen).
A key component of the ABAP runtime system is the Database Interface, that
converts database-independent ABAP statements ("Open SQL") into
statements understood by the underlying DBMS ("Native SQL"). The
database interface manages all the communication with the relational
database on behalf of ABAP programs. Database interface also contains
features such as buffering of tables and frequently accessed data in the local
memory of the application server.
All ABAP programs exists inside the SAP database and they are not stored as
a separate external file like Java or C++ programs.
In the database, each ABAP program code stores in two forms - Source code
and Generated code.
Source code can view and edited with the ABAP Workbench tools.
Generated code is a binary representation that is slightly similar with Java
bytecode.
What are the types of ABAP programs-based
execution?
Executable programs –
Reports
Module pools
Non-executable programs –
INCLUDE modules – Includes into calling unit during the generation time and mostly
used to split the larger programs.
Subroutine pools - Contain ABAP subroutines that are coded in between
FORM/ENDFORM and invoked with PERFORM.
Function groups - Are libraries of function modules that are coded in between
FUNCTION/ENDFUNCTION and invoked by CALL FUNCTION).
Object classes – Defines set of methods and attributes.
Interfaces – Contains “empty” method definitions to manually provide the code by
developer.
Type pools - Defines set of data types and constants.
The ABAP development can be done in two possible days. Those are –
ABAP Workbench
ABAP Development Tools
The ABAP Workbench is part of the ABAP system and accessed via SAP
GUI. It contains various tools for editing programs. Some of the ABAP
workbench tools are -
ABAP Editor used for writing and editing reports, module pools, includes and
subroutine pools. Transaction code is SE38.
ABAP Dictionary used for processing database table definitions and retrieving global
types. Transaction code is SE11.
Menu Painter used for designing the user interface like menu bar, standard toolbar,
application toolbar, function key assignment. Transaction code is SE41.
Screen Painter used for designing screens and flow logic. Transaction code is SE51.
Function Builder used for function modules. Transaction code is SE37.
Class Builder used for ABAP Objects classes and interfaces. Transaction code is
SE24.
The ABAP Development Tools (ADT) also known as "ABAP in Eclipse" with
a set of plugins to develop ABAP.
SAP ABAP R/3 Architecture -
The R/3 system is the platform for all other applications in the R/3 System. In
R/3, R stands for Real-time and 3 stands for 3-tier architecture. The R/3
System can have different set of views in different prospects. The main views
among them are -
Logical view
Software Oriented View
The below diagram represents the logical view of the R/3 system -
The kernel and basis services is a runtime environment for all R/3 applications
(i.e. hardware, operating system, and database specific). The runtime
environment is mainly written in C and C++. However, some parts are also
written in ABAP.
The tasks of the kernel and basis services are - “running applications”, “user
and process administration”, “database access”, “communication” and
“system monitoring and administration”.
ABAP Workbench –
Presentation Components –
The presentation components are responsible for the interaction between the
R/3 System and the user.
Presentation layer
Application layer
Database layer
Presentation layer –
Presentation layer is an interface between the R/3 system and its end-users.
Presentation layer is a distributed to the workstations of end users. The end
users can be client or customer or individual users.
Presentation layer receives the data from the input devices and sends it to the
application layer (server) to process the data. And, responsible to receive the
processed data from the application layer and sends the same to the devices
where the result requires to display.
The data or input can be entered by using the input devices. The input
devices can be browsers, mobile devices, font-end GUI systems and so on.
The presentation layer is normally distributed across several presentation
servers. The presentation layer analyzes user inputs and transfers these to
the application layer.
Application layer –
The application layer is an intermediate layer. This layer process the inputs
from the presentation layer and one messaging server. The application layer
is implemented using application servers. Application server(s) can be one or
multiple. Each Application server can contain either one or multiple services to
run an R/3 system.
It communicates to the database layer with the input received from the
presentation layer, processes input and sends the results back to the
presentation layer. The application layer contains the ABAP runtime
environment where the ABAP programs are executed.
All the services are distributed to the more than one application server.
Messaging server contains the information about the application groups and
load balancing information. Messaging server is responsible for the
communication between the existing application servers.
Database layer –
Database layer is layer contains the central database system of all the data in
R/3 system. Normally, this database layer installs on the different server due
to the security, performance and processing issues.
This layer is responsible for processing the requests from the application layer
and sends back the required information. In general, either SQL or ORACLE
servers can be used.
All R/3 data stores in the database. Database layer contains two components
-
ABAP programs are mostly responsible for data processing within the
different blocks of an application program. i.e. program cannot create as a
single unit however program should divide into smaller modules that are
assigned to individual blocks.
Header section
Declaration Part for Global Data, Classes and Selection Screens
Processing Blocks container
Header section –
Header section contains the detailed information about the program. Header
section is standard template that is generated when we create the program
and it is editable. The ABAP program first statement starts with PROGRAM or
REPORT. The header section is mandatory.
Dialog Modules
Event blocks for selection screens
Event blocks for lists
Event blocks for executable programs/Reports
Subroutines
Function Modules
Methods
All ABAP statements (except the declarative statements in the declaration part)
Dialog module is used to code a business logic that relates to screens flow.
Dialog modules can be called from the screen flow logic/screen command
logic.
Lists are special screens that outputs arranged data. We can create list in any
processing block of an ABAP program using a set of commands such as
WRITE, NEW-PAGE and so on. The list processor displays the list on the
screen and handles user actions within lists. The list processor controls the
flow logic of the list.
What is Subroutines?
What is Method?
Methods are defined using the METHOD statement and coded in between the
METHOD…ENDMETHOD statement.
The ABAP statements that are not part of declaration part is called as source
code.
The ABAP program source code consists of comments and ABAP statements.
The ABAP statements and comments can be discussed in further chapters.
ABAP statements begins with an ABAP keyword and ends with a period(.).
The words (keywords, variables, operators etc.) are always separated by at least one
space. If words have more than one space in between, it will be considered as one.
ABAP statement can be more than one line long however it is not recommended.
ABAP supports a single line contain more than one ABAP statement.
There are no rules for ABAP statement starting position or indentation. ABAP
statement can start in any column of the line.
ABAP statement can be in any case (i.e. either lower case or upper case). Both are
considered as same and no differentiation between upper and lower case for
keywords, additions, and operands.
ABAP program is only case sensitive while comparison.
ABAP statements begins with an ABAP keyword and ends with a period(.).
For example -
ABAP statement can be more than one line long however it is not
recommended. ABAP supports a single line contain more than one ABAP
statement.
For example -
There are no rules for ABAP statement starting position or indentation. ABAP
statement can start in any column of the line.
For example -
Write
'Hello World, Welcome to KIIT'.
ABAP Statements are not case-sensitive. ABAP statement can be in any
case (i.e. either lower case or upper case). Both are considered as same and
no differentiation between upper and lower case for keywords, additions, and
operands. ABAP considers all cases (upper, lower, and mixed cases)
statements are valid and does not throws any error.
For example, all the statements below are considered as valid even though
they are in mixed case.
ABAP statements are formed with keywords, variables, data types and
objects.
For example, -
All elements (keywords, variables, data types and literals) are highlighted in
the above diagram of the ABAP statement.
In the above example, PROGRAM and WRITE are the keywords. The
program displays the list on the screen. In this case, the list consists of ‘Hello
World, Welcome to KIIT’.
The above diagram describes the structure of the program and all elements
(keywords and literals) are highlighted.
Declarative Statements
Modularization Statements
Control Statements
Call Statements
Operational Statements
Database Statements
Declarative Statements -
Declarative statements used to declare data objects that are used by other
ABAP statements in the program or routine. Declarative keywords to form
declarative statements.
Modularization Statements -
Event Statements –
Used to define event blocks. There are no special end statements for event
statements and ends automatically when next processing block started.
AT SELECTION-SCREEN ON <parameter_name>
START-OF-SELECTION.
<statements-block>.
AT USER-COMMAND.
<statements-block>.
Defining statements –
FORM <subroutine_name>.
<statements-block>ENDFORM.
FUNCTION <function_name>.
<statements-block>ENDFUNCTION.
MODULE <module_name> {OUTPUT|[INPUT]}.
...ENDMODULE.
Control Statements -
IF <condition>.
<statements-block>. ENDIF.
WHILE <logical-expression>
<statements-block>. ENDWHILE.
CASE <variable>. WHEN <value1>.
<statements-block>.WHEN <value2>.
<statements-block>....... ...... ...... WHEN <valuen>.
<statements-block>. WHEN OTHERS.
<statements-block>. ENDCASE.
Call Statements -
Call statements used to call processing blocks that are already defined using
modularization statements. The calling blocks can either be in the same
ABAP program or in a different program.
PERFORM <subroutine-name>
USING <variables>.
CALL <function-name>/<method-name>.
SET USER-COMMAND <function-code>.
SUBMIT <report_name>
LEAVE PROGRAM.
Operational Statements -
WRITE <data-object>/<field-symbol>/<formal-parameter>/<text-symbol>
MOVE <field1> TO <field2>.
ADD <field1> TO <field2>.
Database Statements -
Database statements use the database interface to access the tables from the
central database system. There are two kinds of database statement in ABAP
- Open SQL and Native SQL.
What is a keyword?
ABAP keywords are the vocabulary of the ABAP language. ABAP keywords
are the elements of an ABAP statement. ABAP statements are composed of
keywords, operands, and operators according to the predefined syntax rules.
ABAP keywords can also contain hyphens (-) to form multi-word expressions.
For example, ADD-CORRESPONDING, END-OF-FILE, END-OF-PAGE etc,.
ABAP keywords are not reserved names. Although the use of an ABAP word
for naming conventions is not restricted, however it should be avoided if
possible.
The program displays the list on the screen. In this case, the list consists of
'Hello World, Welcome to KIIT'.
The above diagram describes the structure of the program and all elements
(keywords and literals) are highlighted.
Declarative Keywords
Modularization keywords
Control Keywords
Call Keywords
Operation Keywords
Database statements
Declarative Keywords –
Modularization Keywords –
Event Keywords –
Event statements uses event keywords to define event blocks. There are no
special end statements and automatically ends when another block starts.
Defining Keywords –
IF WHILE CASE
Call Keywords -
Call statements uses call keywords to call processing blocks. The processing
blocks can either be in the same program or in a different program.
Operational keywords -
Database Keywords -
Database statements uses the database keywords to access the tables in the
central database system. There are two kinds of database statement in ABAP
- Open SQL and Native SQL. Both types of statements use the below DML
statements to access the database.
Statements
Formatting ABAP statements (Indentation)
Chained statement or colon notation
Comments
ABAP Statements –
Or as follows –
PROGRAM
Z_FIRST_PROG.
WRITE
'Hello World, Welcome to KIIT'.
The elements of a statement should be separated by at least one blank/space
or a line break. Otherwise, blanks and line breaks between tokens are not
significant.
Syntax -
ABAP_keyword : statements-comma-seperated.
In the chain statement, after the colon the remaining parts of the statements
are comma separated. We can write the statement like below -
In a chain statement, the first part (before the colon) is not limited to the
keyword of the statements. The identical part of all the statements can code
before the colon(:).
SUM = SUM + : 1, 2, 3.
In the above example, "SUM = SUM + " is the identical part of all the ABAP
statements. So to make the chain statement for the above, write the common
part first, next code colon(:) and then remaining part of statements comma
separated.
Example -
Code -
Output -
Explaining Example -
Comments –
Full line comment contains only a comment for the full line and nothing else.
Full line comments can be made by using asterisk (*) or quote(") as a first
character of the entire line. If the line starts with * or ", then those lines are
considered as comments and ignored by the compiler while generating
program.
Note! ABAP Editor not capitalize the comment either it may be a full or partial
comment code.
Example -
Output -
Explaining Example -
* Full line comment - Full line comment in the program. " partial comment -
Partial line comment in the program.