Structures and Internal Table
Structures and Internal Table
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.
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.
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.
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
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
.
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.
Working with internal tables and work areas in SAP ABAP, Internal
table operations in SAP ABAP programs
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.
ENDLOOP.
<VALUE> .
ENDLOOP.
<INDEX2>.
ENDLOOP.
Syntax1: MODIFY <ITAB> FROM <WA> INDEX <INDEX NO> TRANSPORTING <FIELD1>
<FIELD2>
SY-TABIX is a key word which stores the index no of currently processed record.
SELECT * FROM MARA INTO TABLE IT_MARA . " GET DATA INTO ITAB IT_MARA
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>.
I - information message
S - status message
E - error message
W - warning
A - termination message
X - exit message.
Message
Type Effect Description
A Termination The message appears in a dialog box, and the program terminates. When the user has
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 is
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 contains
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
There are three types of internal tables in SAP ABAP programming, an
ABAP developer must know and understand before using them in ABAP
programs.
1 These are default internal These are a special type of internal These are used with
tables. tables, where data is logical databases i:e
already(automatically) sorted as you with all fields and all
insert the record records.
2 To read a record we use To read a record we use either key or Here the index
either key or index index operation. operation is not
operation. allowed, we only use key
operation.
3 To search for a record, we To search for a record, we use binary To search for a record,
can use either linear search as data is already sorted. we use hashed
search or binary search. algorithm.
5 We can use insert and We only use insert, not append. These are mainly used in
append to add records. ABAP with BI projects