abap training session # 3
TRANSCRIPT
-
8/12/2019 ABAP Training Session # 3
1/42
Inspire ABAP trainingsessions
Training session # 3
Date: 16/06/2014
-
8/12/2019 ABAP Training Session # 3
2/42
Contents
ABAP Data Dictionary
Data Elements
Domains
SAP Tables
Open SQL
Modularization
-
8/12/2019 ABAP Training Session # 3
3/42
ABAP Data Dictionary
Create and manage data definitions (metadata)
SQL can be divided into following 2 parts.
DML
Data Manipulation Language
DDL Data Definition Language
DML part consists of query and update commands like SELECT, UPDATE, DELETE, INSEprograms handle DML part of SQL.
DDL part consist of commands like CREATE TABLE, ALTER TABLE, DROP TABLE, CREAetc. ABAP Dictionary handles DDL part of SQL.
So ABAP Dictionary is used to create and manage data definitions (metadata). ABAPused to create Tables, Data Elements, Domains, Views, Lock Objects etc.
-
8/12/2019 ABAP Training Session # 3
4/42
Data Elements and Domains
While creating a table in data dictionary each table field is assigned to a data element. Eais in turn assigned to a domain.
Table Field
Data Element
Domain
-
8/12/2019 ABAP Training Session # 3
5/42
Create a Domain in SAP
-
8/12/2019 ABAP Training Session # 3
6/42
Create a Data Element in SAP
-
8/12/2019 ABAP Training Session # 3
7/42
Create a SAP table
There are three types of SAP DDIC table that you can define.
1. Transparent Table
2. Cluster Table
3. Pooled Table
-
8/12/2019 ABAP Training Session # 3
8/42
-
8/12/2019 ABAP Training Session # 3
9/42
2. Cluster Table
Many-to-one relationship with a table in the database.
Many cluster tables are stored in a single table in the database called a table cluster
Tables have a part of their primary keys in common.
III. Cluster Tables (BSEG, BSED, BSEC)
Should be accessed via primary key - very fast retrieval otherwise very slow
No secondary indexes
Select * is Ok because all columns retrieved anyway. Performing an operation on multipleefficient than single row operations. Therefore you still want to select into an internal tableare being selected into the internal table, you might still like to retrieve specific columns tomemory required.
Statistical SQL functions (SUM, AVG, MIN, MAX, etc) not supported
Can not be buffered
-
8/12/2019 ABAP Training Session # 3
10/42
3. Pooled Table
Many-to-one relationship with a table in the database.
For one table in the database, there are many tables in the Data Dictionary. The table i
has a different name than the tables in the DDIC, it has a different number of fields, anddifferent names as well.
II. Pool Tables (match codes, look up tables)
A001, A004, A044
Should be accessed via primary key or
Should be buffered (SE11->Display Table->technical settings)
No secondary indexes
Select * is Ok because all columns retrieved anyway
-
8/12/2019 ABAP Training Session # 3
11/42
SAP Table Maintenance Generator
SAP Table Maintenance Generator (TMG) is a tool to generate a table maintenance progrgenerate a program to maintain (Create, Edit & Delete) entries in a table.
-
8/12/2019 ABAP Training Session # 3
12/42
Open SQL
Open SQL is a set of ABAP statements that performs operations like reads, modi
data in the SAP database.
All open SQL statements are pass Open SQL is independent of the database syssyntax of the open SQL is uniform for all the databases supported by SAP.
The DB interface converts the open SQL to native SQL and passes it on to the da
OPEN SQL DESCRIPTION
SELECT Reads data from database
INSERT Inserts lines to database
UPDATE Changes the contents of lines in
database
MODIFY Inserts lines into database or
changes the contents of existing
lines
DELETE Deletes lines from database
-
8/12/2019 ABAP Training Session # 3
13/42
Open SQL
All Open SQL statements fill the following two system fields:
SY-SUBRCAfter every Open SQL statement, the system field SY-SUBRC contains the operation was successful, a value other than 0 if not.
SY-DBCNTAfter an open SQL statement, the system field SY-DBCNT contains the numlines processed.
-
8/12/2019 ABAP Training Session # 3
14/42
Reading Data using Open SQL
SELECT is the open SQL statement to read the data from the database. The general syntstatement is as follows.
SELECT INTO
FROM
[WHERE ]
CLAUSE DESCRIPTION
SELECT Specifies which columns you want to
whether one line or many lines needs
selected, and whether duplicate entr
allowed
INTO Determines the target area into whic
selected data is to be placed
FROM Specifies the database table from whdata is to be selected
WHERE
specifies which lines are to be read by
specifying conditions for the selection
-
8/12/2019 ABAP Training Session # 3
15/42
Reading Data using Open SQL
Source Code
DATA: gwa_employee TYPE zemployee.
WRITE:/1 'Emp ID' color 5,9 'Name' color 5,17 'Place' color 5,
27 'Phone' color 5,39 'Dept' color 5.
SELECT * FROM zemployee INTO gwa_employee.
WRITE:/1 gwa_employee-id,9 gwa_employee-name,
17 gwa_employee-place,27 gwa_employee-phone,
39 gwa_employee-dept_id.
ENDSELECT.
Table Output
http://www.saphub.com/wp-content/uploads/2011/12/sql-select-12.png -
8/12/2019 ABAP Training Session # 3
16/42
Inserting Values using SAP Open SQL
INSERT is the open SQL statement to add values to the database table.
First declare a work area as the line structure of database table and populate the work aredesired values. Then add the values in the work area to the database table using INSERT
The syntax for the INSERT statement is as follows.
INSERT FROM
or
INSERT INTO VALUES
-
8/12/2019 ABAP Training Session # 3
17/42
EMPLOYEE table entries after INSERT
Inserting Values using SAP Open SQL
Source Code
DATA: gwa_employee TYPE zemployee.
gwa_employee-id = 6.
gwa_employee-name = 'MARY'.
gwa_employee-place = 'FRANKFURT'.
gwa_employee-phone = '7897897890'.
gwa_employee-dept_id = 5.
INSERT zemployee FROM gwa_employee.
Table
-
8/12/2019 ABAP Training Session # 3
18/42
Changing Values using SAP Open SQL
UPDATE is the open SQL statement to change the values in the database table. First decas the line structure of database table and populate the work area with the desired values
key in the database table. Then update the values for the specified key in the database taUPDATE statement.
The syntax for the UPDATE statement is as follows.
UPDATE FROM
If the database table contains a line with the same primary key as specified in the work aris completed successfully and SY-SUBRC is set to 0. Otherwise, the line is not inserted, aset to 4.
-
8/12/2019 ABAP Training Session # 3
19/42
EMPLOYEE table entries before UPDATE EMPLOYEE table entries after UPDATE
Changing Values using SAP Open SQL
Source Code
DATA: gwa_employee TYPE zemployee.
gwa_employee-id = 6.
gwa_employee-name = 'JOSEPH'.
gwa_employee-place = 'FRANKFURT'.
gwa_employee-phone = '7897897890'.
gwa_employee-dept_id = 5.
UPDATE zemployee FROM gwa_employee.
-
8/12/2019 ABAP Training Session # 3
20/42
EMPLOYEE table entries after UPDATE
Changing Values using SAP Open SQL
Source Code
UPDATE zemployee SET place = 'MUMBAI' WHERE dept_id = 2.
-
8/12/2019 ABAP Training Session # 3
21/42
Deleting Entries using SAP Open SQL
DELETE is the open SQL statement to delete entries from database table. First declare a line structure of database table and populate the work area with the specific key that we w
from the database table. Then delete the entries from the database table using DELETE s
The syntax for the DELETE statement is as follows.
DELETE FROM
If the database table contains a line with the same primary key as specified in the work aris completed successfully and SY-SUBRC is set to 0. Otherwise, the line is not deleted, anset to 4
-
8/12/2019 ABAP Training Session # 3
22/42
EMPLOYEE table entries before DELETE EMPLOYEE table entries after DELETE
Deleting Entries using SAP Open SQL
Source Code
DATA: gwa_employee TYPE zemployee.
gwa_employee-id = 6.gwa_employee-name = 'JOSEPH'.
gwa_employee-place = 'FRANKFURT'.
gwa_employee-phone = '7897897890'.
gwa_employee-dept_id = 5.
DELETE zemployee FROM gwa_employee.
-
8/12/2019 ABAP Training Session # 3
23/42
EMPLOYEE table entries after DELETE
Deleting Entries using SAP Open SQL
Source Code
DELETE FROM zemployee WHERE dept_id = 2.
-
8/12/2019 ABAP Training Session # 3
24/42
Inserting or Changing Values using SAP Open SQL
MODIFY is the open SQL statement to insert or change entries in the database table. If thcontains no line with the same primary key as the line to be inserted, MODIFY works like I
the line is added. If the database already contains a line with the same primary key as theinserted, MODIFY works like UPDATE, that is, the line is changed.
The syntax for the MODIFY statement is as follows.
MODIFY FROM
If the database table does not already contain a line with the same primary key as specifiearea, a new line is inserted. If the database table does already contain a line with the samspecified in the work area, the existing line is overwritten. SY-SUBRC is always set to 0.
-
8/12/2019 ABAP Training Session # 3
25/42
-
8/12/2019 ABAP Training Session # 3
26/42
Output
Source Code
DATA: gwa_employee TYPE zemployee.
gwa_employee-id = 6.gwa_employee-name = 'JOHNNY'.
gwa_employee-place = 'LONDON'.
gwa_employee-phone = '7897897890'.
gwa_employee-dept_id = 3.
MODIFY zemployee FROM gwa_employee
Inserting or Changing Values using SAP Open SQL
-
8/12/2019 ABAP Training Session # 3
27/42
Modularization in ABAP
Modularization is breaking down the application code into smaller units, so that it is easy t
Advantages of Modularization are as follows. Easier to read, maintain and debug.
Eliminates redundancy of code and increases reusability of code .
-
8/12/2019 ABAP Training Session # 3
28/42
Types of Modularization
Macros If you want to reuse the same set of statements more than once in a programinclude them in a macro. You can only use a macro within the program in which it is def
Include ProgramsInclude programs allow you to use the same source code in differThey are mainly used for modularizing source code and have no parameter interface.
SubroutinesSubroutines are normally called internally i.e. called from the same prois declared. But subroutines can also be called from external programs.
Function ModulesFunction Modules are stored in the central library and can be callprogram. Even the function modules(RFC enabled) can be called from non-SAP system
Methods
Methods used ABAP object oriented programming
-
8/12/2019 ABAP Training Session # 3
29/42
If we want to reuse the same set of statements more than once in a program, we can inmacro. We can only use a macro within the program in which it is defined. Macro defini
before the macro is used in the program.
Syntax
DEFINE .
...
END-OF-DEFINITION.
Program
*Macro definition
DEFINE print.
write:/ 'Hello Macro'.
END-OF-DEFINITION.
WRITE:/ 'Before Using Macro'.
print.
Output
Macros
-
8/12/2019 ABAP Training Session # 3
30/42
Include programs are not standalone programs and cannot be executed independently.
Container for ABAP source code.
They are used to organize the ABAP source code into small editable units which can be inserted aother ABAP programs using the INCLUDE statement.
The include statement copies the contents of the include program into the main program.
ABAP Include Program
-
8/12/2019 ABAP Training Session # 3
31/42
If we want to reuse the same set of statements more than once in a program, we can inmacro. We can only use a macro within the program in which it is defined. Macro defini
before the macro is used in the program.
Syntax
INCLUDE
Source Code
Source code of ZINCLUDE_DATA.
DATA: g_name(10) TYPE c.
Source code of ZINCLUDE_WRITE.
WRITE:/ 'Inside include program'.
Source code of main program.
REPORT zmain_program.
INCLUDE zinclude_data.
WRITE:/ 'Main Program'.
INCLUDE zinclude_write.
Output
ABAP Include Program
-
8/12/2019 ABAP Training Session # 3
32/42
Subroutines are procedures that we define in an ABAP program
Can be called from any program..
ABAP Subroutine
ABAP F i M d l
-
8/12/2019 ABAP Training Session # 3
33/42
Function Group
When you create a function module, you must assign it to functio
The function group is the main program in which a function moduembedded
is a container for function modules
Function Library
Admin
Import/Export Parameter
Source Code Main Program
Documentation
ABAP Function Modules
-
8/12/2019 ABAP Training Session # 3
34/42
ABAP F ti M d l
-
8/12/2019 ABAP Training Session # 3
35/42
ABAP Function Modules
ABAP F ti M d l
-
8/12/2019 ABAP Training Session # 3
36/42
is a code that can be called from any ABAP program, therefore making it a globally acc
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 codeback information in the export parameters or internal tables
ABAP Function Modules
ABAP F ti M d l
-
8/12/2019 ABAP Training Session # 3
37/42
ABAP Function Modules
ABAP Function Modules
-
8/12/2019 ABAP Training Session # 3
38/42
ABAP Function Modules
ABAP Function Modules
-
8/12/2019 ABAP Training Session # 3
39/42
ABAP Function Modules
FUNCTION Z_FMTEST.
result = number1 ** number2.
ENDFUNCTION.
ABAP Function Modules
-
8/12/2019 ABAP Training Session # 3
40/42
ABAP Function Modules
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.
-
8/12/2019 ABAP Training Session # 3
41/42
-
8/12/2019 ABAP Training Session # 3
42/42
ABAP Practice