0% found this document useful (0 votes)
92 views45 pages

ABAP Tutotrial

The document discusses the SAP data dictionary, which is a central repository for metadata and development objects. It stores information about database tables, views, data elements, domains, and other objects. The main functions of the data dictionary include managing database tables, views, data elements, domains, search helps, and lock objects. The document also provides instructions for creating domains, data elements, and transparent tables in the SAP data dictionary using transaction code SE11.

Uploaded by

veeramani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views45 pages

ABAP Tutotrial

The document discusses the SAP data dictionary, which is a central repository for metadata and development objects. It stores information about database tables, views, data elements, domains, and other objects. The main functions of the data dictionary include managing database tables, views, data elements, domains, search helps, and lock objects. The document also provides instructions for creating domains, data elements, and transparent tables in the SAP data dictionary using transaction code SE11.

Uploaded by

veeramani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 45

What is Data Dictionary in SAP ?

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.

SQL Can be divided into two parts

 DML -- Data Manipulation Language


 DDL -- Data Definition Language

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 :

 Data Base Tables


 Views
 Data Elements
 Domains
 Structures
 Search Helps
 Lock Objects

An ABAP Consultant may need to work on below areas of data dictionary :

 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.

Navigation: T-code : SE11

Data Types Domains Data Elements in


SAP
Last Updated: August 10th 2017 by Ashok Kumar Reddy

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

 STRING Character Sequence


 XSTRING Byte Sequence

Complex Types includes Structure Types and Table Types.


Reference Types includes Data References and Object References
What is a Date Element in SAP ABAP ?
Data element is an object which specified semantic information of a field, ex: field
label , heading.(
We all know that table is a collection of fields, ex: STUDENT is a table with fields
STUDENT_ID, STUDENT_NAME ext, data element specifies the field labels and
headings for these fields )

What is a Domain in SAP ABAP ?


Domain is an object which specified technical information of a field in a table ex:
Data type, length, value range etc

Why we use Data elements and Domains in SAP ?


When ever we are creating a new table or adding a field to existing table, we need to
specify field labels and data types for the field, in SAP we maintain these values in
the form of Data elements and Domains.
Navigation : T-code - SE11

How to create Domain and Data Element


in SAP?
Last Updated: August 10th 2017 by Ashok Kumar Reddy

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-

How to create Domain in SAP


Creating a Domain in SAP
Go to SE11 T-code, select domain radio button, provide a name (ZSAPN_DOMAIN) and create.
Provide short description, no of characters and save (Ctrl S ).

Select local object ( non transportable object ).


Activate.

Domain is created.

How to create Data Element in SAP


Creating data element in SAP
Go to SE11, select data type radio button, provide a name (ZSAPN_DATAELEMENT) and create.

A popup will open, select data element radio button


Enter short description and domain name (ZSAPN_DOMAIN) and select field label tab.

Select field label tab and maintain field labels.


Save and Activate, Data element is created.

What are the components of SAP Tables


SE11?
Last Updated: August 10th 2017 by Ashok Kumar Reddy

What are the components of database tables in SAP? What is a key field, delivery
class and size category in SAP?

A+ A-

What are the components of Table in SAP ?


Before creating a table, we must know the components of the table.

What is a key field in ABAP Dictionary Table?


A field which does not accept duplicate data is called as the key field.

What is a foreign Key in ABAP Dictionary


Foreign Key is a concept which is used to define relations between tables in ABAP
Dictionary.

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.

What are Compound Foreign Key in ABAP Dictionary?


A compound foreign key is a foreign key composed of two or more fields. In other
words, a check is done to compare two fields in the foreign key table against two
fields in the check table. The combination of values must exist in the check table
before they can be inserted into the foreign key table. However only one field on the
screen will trigger the compound foreign key check.

What is a delivery class in ABAP Dictionary?


It specifies the type of data stored in a database table ex: master data, Transaction
data, system data etc.

Options available under delivery class:

A- Application Table (Master and Transaction data).

C-Customizing table, maintenance only by customer not SAP.

L-Table for storing temporary data.

G, E, S, W - These are used to store system data (Basis data).

Display and Maintenance


It specifies whether the user can display the data and maintain the data, the
following options are available under display and maintenance.

1. Display/Maintenance Allowed. - User can display and maintain data.


2. Display/Maintenance allowed with restrictions - Some users can display and maintain
data.
3. Display/Maintenance not allowed - No user can display data.

What is data class ?


It specifies the physical area of a table in the database, the following options are
available under data class.

APPL0 - Master data

APPl1 - Transaction data

APPL2 - Organization and Customizing

DDIM, DFACT, DODS etc., is used by BI and BW.

What is size category in Data Dictionary?


It specifies the number of records that can be stored in a database table, options
available under size category are below.
Size
Category No of expected records

0 0 - 7,100

1 7,100 - 28,000

2 28,000 - 1,10,000

The above numbers may vary from company to company.


Size category will be incremented dynamically based on increase in records.

Buffer
It is a temporary memory for storing the data.

It is same as cache memory.

What are the types of database tables in


SAP?
Last Updated: August 10th 2017 by Ashok Kumar Reddy

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 database table in SAP


SE11?
Last Updated: August 10th 2017 by Ashok Kumar Reddy

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).

Go to SE11 T-code, provide table name to be created ZSTUDENT_TABLE and


create.
Provide short description, delivery class (A), Display Maintenance Allowed and
select fields tab.

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, domain and label


Save, double click on domain name ZSTUDENT_NO, click on 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.

Provide data class and size category, save and activate.


You will get a warning message just click on No, table is created.

Now add entries to table.


How to create a Structure in SAP SE11?
Last Updated: August 10th 2017 by Ashok Kumar Reddy

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.

Go to SE11, select Data Type radio button and click on create.


A pop up will open, select structure radio button and continue.

Provide short description, add some fields, save and activate.


The structure is created, now we can use this structure in our ABAP programs.

What is the difference between structure


and table in SAP data dictionary?
Last Updated: August 10th 2017 by Ashok Kumar Reddy

Differences between database tables and structures in SAP, Do structures have


Primary Keys in SAP?

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.

Table and Structure Difference


Table Structure

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 table? How to create a


check table in SAP?
Last Updated: August 10th 2017 by Ashok Kumar Reddy

What is a check tables in SAP ? Data validations on SAP tables using check table,
creating check table in SAP

A+ A-

What are table validations?


Table validation is a concept through which we can restrict invalid entries in a table.

Possible methods/concepts for table validation


1. Field Level validations: We can validate entries at field level with the help of
check table concept.

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.

What is a check table?


It is a table which contains all valid entries of a field.

What is value table?


It is a table which contains all valid entries of a domain, this domain can be reused in
multiple tables.

What are fixed values for the domain?


These are allowed values for a domain ex: GENDER (domain).
Creating check table for table validations.
Step1: Go to SE11, create a table ZSTUDENT_CHECK as below
Go to SE11, provide name as ZSTUDENT_CHECK and click on create.

Provide delivery class and display maintenance allowed.

Go to fields tab and add a field as below


Click on technical settings button and provide data class and size category.
Go to utilities- table contents - create entries add some entries to the table.
Similarly add some more entries.

Step2: Add ZSTUDENT_CHECK as check table for ZSTUDENT_TABLE


Go to SE11, provide table name as ZSTUDENT_TABLE( which we have created
already in our previous lessons, if not create a table )
Go to tab Entry help/check, select city fields and click on 'Foreign key' icon.

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).

Now go to utilities - table entries -> create entries

Provide a city name which is not in ZSTUDENT_CHECK table and try to save, it
will trough an error.

Fixed values of a domain in SAP


Last Updated: August 10th 2017 by Ashok Kumar Reddy

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.

Create domain with fixed values


Go to SE11, select domain, provide name as ZGENDER, click on create.

Provide short description, data type and length as below and click on value range tab.
Provide fixed values.

Save and activate.

Create data element with domain


Go to SE11, select data type, provide name as ZGENDER, click on create .

A popup will come, select data element and press enter.


Provide short description, domain and click on field label.

Provide field labels

Save and activate


Add a field in table
Go to SE11, provide a table name ZSTUDENT_TABLE(we have already created, if not create table ) and click on
change

Go to fields tab and add a field as below.

Save and activate

Go to table utilities- table entries - create entries


Provide values other than M, F and N, it will through an error .

What are Internal Tables and Work


areas ?
Last Updated: August 10th 2017 by Ashok Kumar Reddy

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.

Internal tables and Work areas


Internal Tables Work Areas

 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

 By default 8kb memory will be allocated and it


increases dynamically( +8kb +8kb).

 Internal tables can store multiple records.  Work areas can store only one record.

General Syntax : General Syntax:

DATA : <ITAB> TYPE TABLE OF <DBTABLE> . DATA : <WA> TYPE <DBTABLE> .

Internal Table declaration


DATA : <ITAB> TYPE TABLE OF <DBTABLE> .
Example :
DATA : IT_ITAB TYPE TABLE OF MARA .
Example Explanation : Here IT_ITAB is the name of Internal table and MARA is the
Database table name, after declaring, IT_ITAB will be the instance of table MARA.

An internal Table declaration with user defined types


DATA : <ITAB> TYPE TABLE OF <userdefinedtype>.
Example is : TYPES : BEGIN OF TY_TABLE,
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MEINS TYPE MARA-MEINS,
END OF TY_TABLE.<br>
DATA : IT_ITAB TYPE TABLE OF TY_TABLE .
Here TY_TABLE is a user defined type with 3 fields

Internal Table Deceleration Old Syntax (Obsolete Method)


Obsolete Syntax: DATA : IT_ITAB TYPE TABLE OF MARA occurs 0 with header
line .
In this example Internal Table itself acts as work area, technically a work area will be created
at the first row of the internal table.

Reading data from database Table in SAP


ABAP
Last Updated: August 10th 2017 by Ashok Kumar Reddy

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 )

Read whole data from MARA


To read all records from MARA table, we use below code

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.

As per performance standards, this method is not preferable

TYPES : BEGIN OF TY_MARA,


MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MEINS TYPE MARA-MEINS,
MBRSH TYPE MARA-MBRSH,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA . "Declare internal table of type
user defined table.
SELECT * FROM MARA INTO CORRESPONDING FIELD OF TABLE IT_MARA . " Here
we are getting data from <code>MARA</code>
"table into internal table IT_MARA which contains only four fields.
Reading data into user defined internal table
Reading data from a database table into a user defined table.

This method is advisable as it gets limited fields from database table

TYPES : BEGIN OF TY_MARA,


MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MEINS TYPE MARA-MEINS,
MBRSH TYPE MARA-MBRSH,
END OF TY_MARA.

DATA : IT_MARA TYPE TABLE OF TY_MARA. " Declare a Internal table of


user defined type
SELECT MATNR, MTART, MEINS, MBRSH FROM MARA INTO TABLE IT_MARA. " Get
list of fields Data Into internal table
" Now data of four fields is available in IT_MARA

Internal Table Operations in SAP ABAP


Last Updated: April 13th 2018 by Ashok Kumar Reddy

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

Using APPEND in SAP ABAP


APPEND statement is used to append or add a record from work area to internal table,
the new record will be added at the end of the internal table.

Syntax: APPEND <WA> TO <ITAB>


DATA: IT_MARA TYPE TABLE OF MARA.
DATA : WA_MARA TYPE MARA.
WA_MARA-MATNR = '00001'.
WA_MARA-MTART = 'FERT'.
WA_MARA-MEINS = 'EA'.
APPEND WA_MARA TO IT_MARA . "APPEND WORK AREA TO INTERNAL TABLE
Using INSERT in SAP ABAP
INSERT statement is used to insert or add a record from work area into internal table
at the specified location

Syntax: INSERT <WA> INTO <ITAB> INDEX <index>


DATA: IT_MARA TYPE TABLE OF MARA.
DATA: WA_MARA TYPE MARA.
WA_MARA-MATNR = '00001'.
WA_MARA-MTART = 'FERT'.
WA_MARA-MEINS = 'EA'.
INSERT WA_MARA INTO IT_MARA INDEX 2 . "The record will be inserted into
internal table at 2nd position
Using SORT in SAP ABAP
SORT is used to sort a Internal table data in ascending order or descending order, by default
it will sort the data in ascending order. In addition to this we can able to sort data based on
specified fields.

Syntax1: SORT <ITAB . "Default sorts data in ascending order


Syntax2 : SORT <ITAB> DESCENDING . " Sort in descending order
Syntax3 : SORT <ITAB> BY <FIELD1> <FIELD2...ASCENDING/DESCENDING ."It
sorts data by specified fields <FIELD1>, <FIELD2>..
Using DESCRIBE TABLE in SAP ABAP
DESCRIBE TABLE is used to count the no of records in a internal table

Syntax: DESCRIBE TABLE <ITAB> LINES <v_lines> ." Count the no. Of

record of an internal table, here v_lines store count


DATA : V_LINES TYPE I. "Type integer
DESCRIBE TABLE IT_MARA LINES V_LINES ." Count the no. of record of a
internal table
Write: v_lines .
Using READ TABLE WITH KEY in SAP ABAP
READ TABLE WITH KEY .. BINARY SEARCH is used to read a single record from an
internal table into work area specified by field name and field value .

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

record into work area where MATNE is '0001'


Using READ TABLE WITH INDEX in SAP ABAP
READ TABLE WITH INDEX is used to read a single record from an internal table into
work area specified by index.

Syntax: READ TABLE <ITAB> INTO <WA> INDEX <index_no


." Read a record into work area using index ( position )
READ TABLE IT_MARA INTO WA_MARA INDEX '2'. "Read a record into work
area where

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 .

Syntax1: LOOP AT <ITAB> INTO <WA> .

ENDLOOP.

Syntax2: LOOP AT <ITAB> INTO <WA> WHERE <FIELDS1> =

<VALUE> .

ENDLOOP.

Syntax3: LOOP AT <ITAB> INTO <WA> FROM <INDEX1> TO

<INDEX2>.

ENDLOOP.
Using MODIFY in SAP ABAP
MODIFY is used to modify a single or multiple internal table records based on
condition

TRANSPORTING is a keyword which is used to specify a list of fields to be modified


instead of all fields.

Syntax1: MODIFY <ITAB> FROM <WA> INDEX <INDEX NO> TRANSPORTING <FIELD1>
<FIELD2>

Syntax1: MODIFY <ITAB> FROM <WA> TRANSPORTING <FIELD1>


<FIELD2> WHERE <CONDITION>
SY-TABIX is a key word which stores the index no of currently processed record.

DATA: IT_MARA TYPE TABLE OF MARA.


DATA: WA_MARA TYPE MARA.

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

FIELD MTART WILL BE MODIFIED FOR CURRENT RECORD IN IT_MARA

DATA: IT_MARA TYPE TABLE OF MARA.


DATA: WA_MARA TYPE MARA.

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 TRANSPORTING MTART WHERE MATNR = '0001'. "
NOW THE

VALUE OF FIELD MTART WILL BE MODIFIED WHERE MATNR = '0001' IN ITAB

Using DELETE in SAP ABAP


DELETE is used to delete single or multiple records from an internal table from work
area based on some condition.

Syntax1: DELETE <ITAB> INDEX <INDEX NO>.

Syntax2: DELETE <ITAB> WHERE <FIELD1> = <FIELD1 VALUE>

<FIELD2> = <FIELD2 VALUE>.


DELETE IT_MARA INDEX 3. "3rd RECORD WILL BE DELETED IN IT_MARA

DELETE IT_MARA WHERE MTART = 'FERT'. "MATERIALS WITH MTART = 'FERT'


WILL BE DELETED

Using DELETE ADJACENT DUPLICATES in SAP ABAP


DELETE ADJACENT DUPLICATES is used to delete delete duplicate records which are
adjacent to each-other.Pre-requisite for this is the internal table must be sorted
in ascending order

Syntax1: DELETE ADJACENT DUPLICATED FROM <ITAB> ."ADJACENT DUPLICATED


WILL

BE DELETED IN INTERNAL TABLE COMPARING ALL FIELDS

Syntax2: DELETE ADJACENT DUPLICATES FROM <ITAB> COMPARING <FIELD1>

<FIELD2> . "ADJACENT DUPLICATES WILL BE DELETED COMPARING SPECIFIED


FIELDS
SORT IT_MARA ASCENDING.
DELETE ADJACENT DUPLICATES FROM IT_MARA . "3rd RECORD WILL BE DELETED
IN IT_MARA

SORT IT_MARA ASCENDING.


DELETE ADJACENT DUPLICATES IT_MARA COMPARING MATR, MTART. "DUPLICATES
WILL BE

DELETED BY COMPARING MATNR AND MTART

Using CLEAR, REFRESH, FREE in SAP ABAP


CLEAR is used to clear a value in a work area or in a variable.

REFRESH is used to clear all values in an internal table.

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 clear : CLEAR <WA> "CLEAR WORK AREA OR VARIABLE

Syntax REFRESH: REFRESH <ITAB> "CLEAR ALL RECORDS OF INTERNAL TABLE BUT

MEMORY WILL BE THERE

Syntax FREE : FREE <WA> "FREE INTERNAL TABLE MEMORY


CLEAR WA_MARA.

REFRESH IT_MARA.

FREE IT_MARA.

Using APPEND LINES OF in SAP ABAP


APPEND LINES OF is used to append multiple records to an internal table from
another internal table.

Syntax : APPEND LINES OF <ITAB1> FROM <index no> TO <index no2>

TO <ITAB2>.

DATA: IT_MARA TYPE TABLE OF MARA. "FIRST INTERNAL TABLE


DATA: IT_MARA1 TYPE TABLE OF MARA. "SECOND INTERNAL TABLE

APPEND LINES OF IT_MARA FROM 3 TO 5 TO IT_MARA1. "DATA IN IT_MARA WILL


BE APPENDED

TO IT_MARA1 FROM INDEX 3 TO INDEX 5 .


Using INSERT LINES OF in SAP ABAP
INSERT LINES OF is used to INSERT multiple records to an internal table from
another internal table at the specified location.

Syntax : INSERT LINES OF <ITAB1> FROM <index no> TO <index no2>

INTO <ITAB2> INDEX <index no>.

DATA: IT_MARA TYPE TABLE OF MARA. "FIRST INTERNAL TABLE


DATA : IT_MARA1 TYPE TABLE OF MARA. "SECOND INTERNAL TABLE

INSERT LINES OF IT_MARA FROM 3 TO 5 INTO IT_MARA1 INDEX 3. "DATA IN


IT_MARA WILL
BE INSERTED INTO IT_MARA1 FROM INDEX 3 TO INDEX 5 AT INDEX 3 LOCATION.
Using MOVE in SAP ABAP
MOVE keyword is used to move one internal table data to another.

Syantax: <ITAB2[]> = []> . "Move ITAB1 to ITAB2


Using COLLECT in SAP ABAP
COLLECT is slimier to APPEND, the difference is it (COLLECT) will check whether the
work area record already exists with the same key (only C, D, N, T), if exists it will
add numerical fields (sum) to the existing record, if the work area record does not
exist it will append a new record.

Syntax: COLLECT <WA> INTO <ITAB>.


See explanation with example of using collect Working with SUM and COLLECT in
SAP ABAP

Writing first ABAP Program


Last Updated: August 10th 2017 by Ashok Kumar Reddy

Writing Hello World program in SAP ABAP, write first ABAP program in SE38

A+ A-

Creating first hello world ABAP program.

Step 1: Go to T-code SE38.


Step2: Enter a program name ex: ZHELLO_WORLD and click on create.
A popup will open, then.

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)

write :/ 'Hello World'..

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.

In ABAP write statement is used to print output and : is chain statement ( Print


multiple records ).

Display MARA data

DATA : IT_MARA TYPE TABLE OF MARA . "INTERNAL TABLE FOR MARA TABLE

DATA : WA_MARA TYPE MARA. "WORK AREA FOR MARA

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

**TYPES is a statement which is used to declare a user defined internal


table with specific fields
TYPES : BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MEINS TYPE MARA-MEINS,
MBRSH TYPE MARA-MBRSH,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA . "INTERNAL TABLE FOR ABOVE USER
DEFINED TYPES 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.

Types of messages in SAP ABAP


Programming
Last Updated: April 1st 2018 by Ashok Kumar Reddy

Using messages in SAP ABAP programming, types of messages in SAP ABAP,


display error, success and warning messages in SAP ABAP

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.

The below syntax is used to raise messages in SAP.

MESSAGE '<MESSAGE TEXT>' TYPE '<MESSAGE TYPE>'. "Message text = any


string, message type = A, E, I, S, W, X
Types of messages available in SAP
Message
Type Effect Description

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 types of internal tables in


SAP ABAP?
Last Updated: April 1st 2018 by Ashok Kumar Reddy

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.

 Standard Internal Tables


 Sorted Internal Tables
 Hashed Internal Tables

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

record all records.

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

You might also like