ABAP Tutotrial
ABAP Tutotrial
What
are main Functions of Data Dictionary in
SAP ?
Last Updated: August 10th 2017 by Ashok Kumar Reddy
What is a Data Dictionary in SAP ? What are the main functions of Data Dictionary in
SAP ? Transaction code for Data Dictionary
A+ A-
The SAP Data Dictionary is a central repository for the development of Objects, SAP
Data Dictionary is used to create and maintain metadata (data definitions) . T-Code
for Data Dictionary is SE11.
Where DML consists of SELECT, INSERT, UPDATE, MODIFY, DELETE etc, this
will be handled by ABAP Programs and DDL consists of commands like CREATE
TABLE, DROP TABLE, ALTER TABLE, CREATE INDEX etc, this will be handled by
Data Dictionary, hence Data Dictionary is the central repository for the development
of objects .
The Main Functions of Data Dictionary are :
Creating Tables
Creating Data elements and Domains
Creating structures and Table types
Creating search helps
Creating Lock objects
Creating data base views
In Next lessons we will learn how to create tables, data elements, domains and other
data dictionary objects.
What are the data types in SAP ABAP? Explain Data Elements and Domains in SAP
ABAP programming
A+ A-
ABAP uses different types of Data Types for Objects, basically there are three types
of data types Elementary Data types, Complex Types, Reference Types .
In Elementary types there are again two types of data types( Categories ) Fixed
Length and Variable Length .
Fixed Length:
C Text Field
N Numeric
D Date
T Time
H Hexadecimal
P Parked Number
I Integer
F Float
Variable Length
How to create a domain in SAP ? how to create data element in SAP ? Step-by-Step
process to create data elements and domains in SAP
A+ A-
Domain is created.
What are the components of database tables in SAP? What is a key field, delivery
class and size category in SAP?
A+ A-
A relationship which can be defined between tables and must be explicitly defined at
field level. Foreign keys are used to ensure the consistency of data. Data entered
should be checked against existing data to ensure that there are now contradiction.
While defining foreign key relationship cardinality has to be specified. Cardinality
mentions how many dependent records or how referenced records are possible.
0 0 - 7,100
1 7,100 - 28,000
2 28,000 - 1,10,000
Buffer
It is a temporary memory for storing the data.
What are the different types of database tables in SAP? What are Transparent
Tables, Pooled Tables and Cluster Tables in SAP?
A+ A-
There are three types of database tables available in SAP, explained below
Transparent table
There is a physical table on the database for each transparent table. The names of
the physical tables and the logical table definition in the ABAP/4 Dictionary
correspond.
All business data and application data are stored in transparent tables.
Pooled table
Pooled tables can be used to store control data (e.g. screen sequences, program
parameters or temporary data). Several pooled tables can be combined to form a
table pool. The table pool corresponds to a physical table on the database in which
all the records of the allocated pooled tables are stored.
Cluster table
Cluster tables contain continuous text, for example, documentation. Several cluster
tables can be combined to form a table cluster. Several logical lines of different
tables are combined to form a physical record in this table type. This permits object-
by-object storage or object-by-object access. In order to combine tables in clusters,
at least parts of the keys must agree. Several cluster tables are stored in one
corresponding table on the database.
How to create a Transparent Table in SAP data dictionary? What in Top to Bottom
and Bottom to top approach to create database tables in SAP?
A+ A-
A table can be created in two ways, one is top to bottom approach and another one
is bottom to top approach.
1. Top to Bottom: In this approach, first table fields are defined and later domain and
data element are defined.
2. Bottom to Top: In this approach, first domain and data element are defined and
later table will be created.
In this example we are going to learn creating an SAP transparent table using a top
to bottom approach (I suggest a simplest way).
Select Fields tab, add a field STUDENT_NO, data element as ZSTUDENT_NO and
check Key and Initial Value check boxes.
A table must contain at least one key field, without a key field we can not create a
table.
Double click on data element ZSTUDENT_NO (Not yet created), a pop up will open,
click yes and one more information message will come press enter.
Now a pop up will come asking to create date element, click yes.
Provide short description, data type, no. Characters, save and activate.
Similarly create remaining fields with data elements and domains as below
Once all fields are created click on 'Technical Settings' button.
What is a structure in the SAP Data Dictionary? How to create a Structure in SAP
data dictionary?
A+ A-
Structure
The structure is a list of fields defined under a name, which is used to process data
at run-time in SAP ABAP applications.
Structures are two types one is global structure and another one is local structure.
Local structure can be created in ABAP programs and global structure can be
created in the data dictionary and can be reusable in different objects.
In this lesson we will be learning how to create  a structure in the data dictionary.
A+ A-
Table and structure have lots of differences in the sense of behavior and properties, the below
are the main differences between tables and structure in the data dictionary.
Tables will store data physically and permanently. Structure can not store data physically, it can
hold data at run time only.
Table Structure
Tables have primary key's. Structure's does not have any primary key.
Table have technical settings (data class, size category, etc), Structure's does not have any technical
maintenance attributes (Display maintenance restrictions). attributes and maintenance attributes.
Table have primary and secondary indexes. Structures does not have primary and secondar
indexes.
What is a check tables in SAP ? Data validations on SAP tables using check table,
creating check table in SAP
A+ A-
2. Domain level validations: We can restrict entries at the domain level with the
help of fixed values of the domain and value table of the domain.
Provide short text, check table name ZSTUDENT_CHECK and click on 'Generate
Proposal' and click on copy.
A Check table will be assigned to CITY field
Save and activate the table(If you get a warning popup when activating just press
no).
Provide a city name which is not in ZSTUDENT_CHECK table and try to save, it
will trough an error.
What is a domain fixed value in SAP? What are the uses of domain fixed values?
Creating fixed values for a domain in SAP
A+ A-
SAP Table screen entries can be restricted using domain fixed values, we can maintain domain fixed values at
domain level when creating a domain.
Provide short description, data type and length as below and click on value range tab.
Provide fixed values.
What is an internal table and work area in SAP ABAP ? Difference between internal
table and work area
A+ A-
Internal Tables and Work Areas are temporary memory locations which are used to store the
data of database tables at run time and in other way we can call them as instances of
database tables.
Temporary memory locations which are used to Temporary memory locations which are used to
store the data of database table. store the data of database table.
Internal table is an instance of database table. Work area is an instance of database table.
Internal Tables Work Areas
Internal tables can store multiple records. Work areas can store only one record.
Reading data from databases tables using OPEN SQL (SELECT) statements in SAP
ABAP
A+ A-
The only way of reading data from a database table is using select statements, in the
below example we will read data from the MARA table in various ways.
Operation Explanation
INTO TABLE ITAB Means getting data into an internal table ITAB from database table
INTO WA Means getting data into WAa work area (Work area can store only one record)
INTO CORRESPONDING FIELDS Means getting data in the common fields of database table and user defined
OF TABLE ITAB internal table ITAB (Here ITAB is a user defined internal table )
INTO CORRESPONDING FIELDS Means getting data of the common fields of database tables and work
OF WA areaWA (Here WA is a work area )
data : it_mara type table of mara . " Declare internal table of type
MARA
Select * from MARA into table it_mara . " Read all records from MARA
table and store in it_mara internal table
Read single record from MARA based on where condition
data : wa_mara type mara . " Declare work area of type MARA, because we
are getting only one record
Select single * from MARA into wa_mara where matnr = '00001' . " Read
one records from MARA table and store in wa_mara work area
OR
data : it_mara type table of mara . " Declare internal table of type
MARA
select * from MARA into table it_mara where matnr = '00001' . " Read
all records from MARA table where MATNR is 00001, MATNR is a key field
.
Reading data into the corresponding fields
By using INTO CORRESPONDING FIELDS of statement, we can get data into a user
defined internal table.
Working with internal tables and work areas in SAP ABAP, Internal table operations
in SAP ABAP programs
A+ A-
Internal table operations are most important for an ABAP developer, below are some
of the most important internal table operations
APPEND
INSERT
SORT
DESCRIBE TABLE
READ TABLE WITH KEY
READ TABLE WITH INDEX
LOOP....ENDLOOP.
MODIFY
DELETE
DELETE ADJACENT DUPLICATES
CLEAR, REFRESH, FREE
APPEND LINES OF
INSERT LINES OF
MOVE
COLLECT
Syntax: DESCRIBE TABLE <ITAB> LINES <v_lines> ." Count the no. Of
BINARY SEARCH is a search mechanism which is used to read a record from internal
table into work area very fast, the functionality of binary search it divides the into
parts and searches, for full details Binary Search mechanism in SAP ABAPThe
internal table must be sorted in ascending order before using binary search.
Syntax: READ TABLE <ITAB> INTO <WA> WITH KEY <FIELD1> = <FIELD1 VALUE>
<FIELD1> = <FIELD1 VALUE>
BINARY SEARCH.
." Read a record into work area where some field = some value
READ TABLE IT_MARA INTO WA_MARA WITH KEY MATNR = '0001' BINARY SEARCH .
"Read a
index is 2.
Using LOOP....ENDLOOP. in SAP ABAP
Loop...Endloop. is also used to read data from a internal table into work area, this
is used to read multiple records serially one after one .
ENDLOOP.
<VALUE> .
ENDLOOP.
<INDEX2>.
ENDLOOP.
Using MODIFY in SAP ABAP
MODIFY is used to modify a single or multiple internal table records based on
condition
Syntax1: MODIFY <ITAB> FROM <WA> INDEX <INDEX NO> TRANSPORTING <FIELD1>
<FIELD2>
SELECT * FROM MARA INTO TABLE IT_MARA . " GET DATA INTO ITAB IT_MARA
WA_MARA-MTART = 'FERT'; "ASSIGN A VALUE TO WORKAREA TO MODIFY INTERNAL
TABLE
MODIFY IT_MARA FROM WA_MARA INDEX SY-TABIX TRANSPORTING MTART. " NOW
THE VALUE OF
SELECT * FROM MARA INTO TABLE IT_MARA. " GET DATA INTO ITAB IT_MARA
MODIFY IT_MARA FROM WA_MARA TRANSPORTING MTART WHERE MATNR = '0001'. "
NOW THE
FREE is used to clear (free) memory of an internal table or work area. We all know
whenever we declare an internal table or work area, 8kb memory will be allocated.
Syntax REFRESH: REFRESH <ITAB> "CLEAR ALL RECORDS OF INTERNAL TABLE BUT
REFRESH IT_MARA.
FREE IT_MARA.
TO <ITAB2>.
Writing Hello World program in SAP ABAP, write first ABAP program in SE38
A+ A-
Step 3: Select 'Executable Program' from drop down and click on 'Save'.
Step4: Select 'Local Object' (Click on Local Object, marked yellow in the above
image
Step 5: ABAP editor will open, write 'Hello World', Save and click on activate icon
(marked yellow in below image)
Step 6: Now you can see 'Active' beside the program name, now click
The Simple ABAP Report uses Internal
tables and Work Areas
Last Updated: April 1st 2018 by Ashok Kumar Reddy
SAP ABAP report using internal tables and work areas, write statement in SAP
ABAP
A+ A-
Getting data from a data base table and display data in the form of report using SAP
ABAP.
DATA : IT_MARA TYPE TABLE OF MARA . "INTERNAL TABLE FOR MARA TABLE
SELECT * FROM MARA INTO TABLE IT_MARA. " GET MARA DATA
LOOP AT IT_MARA INTO WA_MARA.
WRITE :/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MEINS, WA_MARA-MBRSH.
"Display required fields
ENDLOOP.
Display MARA data using user defined internal table
DATA : WA_MARA TYPE TY_MARA. "WORK AREA FOR ABOVE USER DEFINED TABLE
SELECT MATNR MTART MEINS MBRSH FROM MARA INTO TABLE IT_MARA. " GET MARA
DATA
LOOP AT IT_MARA INTO WA_MARA.
WRITE :/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MEINS, WA_MARA-MBRSH.
"Display required fields
ENDLOOP.
Display MARA data using user defined internal table ABAP 7.4
SELECT matnr, mtart, meins, mbrsh FROM mara INTO TABLE @DATA(it_mara).
" GET MARA DATA
LOOP AT it_mara INTO DATA(wa_mara).
WRITE :/ wa_mara-matnr, wa_mara-mtart, wa_mara-meins, wa_mara-mbrsh.
"Display required fields
ENDLOOP.
A+ A-
Like all programming languages, we need to raise status, error, warning, information,
abort etc messages in ABAP programs, in SAP we can raise the following
messages.
I - information message
S - status message
E - error message
W - warning
A - termination message
X - exit message.
A Termination The message appears in a dialog box, and the program terminates. When the user h
Message 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
Message terminates.
I Information The message appears in a dialog box. Once the user has confirmed the message, the
program continues immediately after the MESSAGE statement.
S Status The program continues normally after the MESSAGE statement, and the message
Message 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.
Message type X allows you to force a program termination. The short dump contain
the message ID.
What are the different types of internal tables in SAP ABAP ? Difference between
standard, sorted and hashed internal tables in SAP ABAP
A+ A-
There are three types of internal tables in SAP ABAP programming, an ABAP
developer must know and understand before using them in ABAP programs.
Difference between Standard internal tables, Sorted internal tables and Hashed internal tables
# Standard Internal tables Sorted Internal Tables Hashed Internal tables
1 These are default internal These are a special type of internal tables, where These are used with logical
tables. data is already(automatically) sorted as you insert the databases i:e with all fields an
# Standard Internal tables Sorted Internal Tables Hashed Internal tables
2 To read a record we use either To read a record we use either key or index Here the index operation is n
key or index operation. operation. allowed, we only use key
operation.
3 To search for a record, we can To search for a record, we use binary search as data To search for a record, we use
use either linear search or is already sorted. hashed algorithm.
binary search.
4 We can use sort operation. We do not use sort as data is already sorted. -
5 We can use insert and append We only use insert, not append. These are mainly used in ABA
to add records. with BI projects