internal table udemy
TRANSCRIPT
-
8/17/2019 Internal Table Udemy
1/39
INTERNAL TABLE
Temporary table stored in RAM on the application
server .
Created and filled by program and dies down when theprogram ends .
Consists of one or more rows with identical structure .
-
8/17/2019 Internal Table Udemy
2/39
Body
Header Line
Structure of an Internal Table
Body holds the rows in internal table . Header line is a field string identical to a row in the body . It is a buffer used to hold
each data before it is added to the body or retrieved from an
internal table
-
8/17/2019 Internal Table Udemy
3/39
Internal tables can exist both as data types and as data
objects .
Data type:-Abstract description of an internal table, either
in a program or centrally in the ABAP Dictionary, that is
used to create a concrete data object. The data type is
also an attribute of an existing data object.
-
8/17/2019 Internal Table Udemy
4/39
Internal Table as Data Type
Specified by : Line Type , Key and Table Type
Line Type : Declaration of the type of each row in internal table type .Can be any simple elemental data type (C,D,P,F etc) , or a
structure(each component of the structure becomes a column in the
internal table) , or it can be another internal table itself .
Key :Identifies table rows. Basically of two kinds - the standard key anda user-defined key and may be UNIQUE or NON-UNIQUE. For tables
with structured line type, the default key consists of all of its non-numerical columns that are not references or themselves internal tables.
For those with elementary line type, the default key is the entire line.
The default key is empty whose line type is an internal table
-
8/17/2019 Internal Table Udemy
5/39
TableType
Determines how ABAP will access individualtable entries.
Type Presence of
Index
Key
mention
mandatory
(U)nique/
(N)on-unique
Record
Access
Response
Time For
Key Access
Standard Y N N By indexor by key
Prop. To no.of table
entries
Sorted Y Y Both By index
or by key
Logarithmic
ally prop. To
no. of tableentries
Hashed N Y U By key Independent
of entries
-
8/17/2019 Internal Table Udemy
6/39
Internal Table As Data Objects
Internal Tables as Data objects are defined either with the
data type of an internal table, or directly as an internal table,
are always fully defined in respect of their line type, key and
access method.
The maximum memory that can be occupied by an internal
table (including its internal administration) is near about 2
gigabytes
Hashed tables may not contain more than 2 million entries.The line types of internal tables can be - elementary,
structured, or internal tables. The individual lines are called
table lines or table entries. Each component of a structured
line is called a column in the internal table.
-
8/17/2019 Internal Table Udemy
7/39
Creating Internal Tables
Two Options Are Available :-
Declaring internal tables as abstract data types in programsor in the ABAP Dictionary, and then to use them to define
data objects.
Defining Internal Tables Directly as data objects.
-
8/17/2019 Internal Table Udemy
8/39
Creating Internal Table Types
Syntax :- TYPES TYPE|LIKE OF [WITH]
[INITIAL SIZE ].
t is the name of the internal table typeTabkind is the type of table : standard / sorted/hashed
Linetype defines the data type of individual line , whichcan be elementary(C,P,F etc) or a structure
n specification of the initial amount of mainmemory assigned to an internal table object
-
8/17/2019 Internal Table Udemy
9/39
Key
[UNIQUE|NON-UNIQUE] KEY ...
Used for internal tables with flat/nested structures as line
type .
[UNIQUE|NON-UNIQUE] KEY TABLE LINEUsed mainly for tables whose line type is elementary ( C , P
,F,I etc , for them the entire line is the key) or for structures(
U can specify all components in the structure as key) .
[UNIQUE|NON-UNIQUE] DEFAULT KEYDeclares the fields of the default key as the key fields.
-
8/17/2019 Internal Table Udemy
10/39
Few Examples on Internal Table Type
TYPES: BEGIN OF MATERIAL,
MATNR(12) TYPE C,
DESCRIP(30) TYPE C,
STOCK TYPE I,
END OF MATERIAL.
TYPES IMAT TYPE SORTED TABLE OF MATERIAL WITH UNIQUE
KEY MATNR .
TYPES IMAT2 TYPE STANDARD TABLE OF MATERIAL WITH
DEFAULT KEY.
TYPES rollno TYPE HASHED TABLE OF I WITH UNIQUE KEYTABLE LINE.
-
8/17/2019 Internal Table Udemy
11/39
Creating Internal Table As Data Objects
TYPES: BEGIN OF MATERIAL,
MATNR(12) TYPE C,
DESCRIP(30) TYPE C,
STOCK TYPE I,
END OF MATERIAL.
TYPES IMAT TYPE SORTED TABLE OF MATERIAL WITH UNIQUE
KEY MATNR .
DATA : INT_MATERIAL LIKE IMAT WITH HEADER LINE .
Creating With Reference To Internal Table Types
-
8/17/2019 Internal Table Udemy
12/39
Declaring New Internal Tables
DATA IMAT TYPE HASHED TABLE OF MARA WITH
UNIQUE KEY MATNR.
Data : Begin of transaction ,
matnr like mseg-matnr ,
Mblnr like mseg-mblnr ,
Werks like mseg-werks ,
menge like mseg-menge ,
end of transaction .
Data int_trans like sorted table oftransaction with unique key matnr with
header line .
-
8/17/2019 Internal Table Udemy
13/39
data : begin of int_mseg occurs 100 ,
matnr like mseg-matnr ,
werks like mseg-werks ,lgort like mseg-lgort ,storing type I ,end of int_mseg .
(Creates an internal table with header line )
Internal Table Declared On Earlier ReleasesWithout Any Key and Without Any Table Type
-
8/17/2019 Internal Table Udemy
14/39
OPERATIONS ON INTERNAL TABLE
Initializing
Populating
FetchingData
UpdatingData
DeletingData
Single Multiple
-
8/17/2019 Internal Table Udemy
15/39
Initializing Internal Tables
Clear
clear .
clear [ ] ( To clear the body of
internal table with header line)
Refresh
refresh itab ( applies to the body of table)
Free
free .
Releases the memory allocated to internal table
-
8/17/2019 Internal Table Udemy
16/39
Operations For All Table Types
-
8/17/2019 Internal Table Udemy
17/39
Inserting Records
Single Line Insertion :
Insert into table
The record is appended at the end for standard table .
For sorted table , record is appended according to the key .
For table with non unique keys , if any entry with same
value of keys exist , the new record is placed above theexisting entry with the same key .
For hashed table, record is inserted according to the table
key
-
8/17/2019 Internal Table Udemy
18/39
Inserting Several Lines :-
Insert lines of [ from ] [to ]into table .
Insertion by Collect Statement :-
Collect statement inserts new records where table keymatch is not found /groups records as per the tablekey if all the non-key columns are numeric .
Inserting Records with MOVE Statement :
Move to .
= .
Use [] to refer to the body of the internal tables with
header line .
-
8/17/2019 Internal Table Udemy
19/39
Inserting Records into Internal table by SQLStatement :-
Select .. .. Into corresponding fields of table
from …….where ……
(selects records from database tables and fills in the body of the
internal table )
Select .. .. Into corresponding fields of
from …….where ……
(selects records from database tables and fills in the header line of
the internal table )Select .. .. appending corresponding fields
of table from …….where ……
(selects records from database tables and appends them with the pre
existing contents of the internal table )
-
8/17/2019 Internal Table Udemy
20/39
Fetching Records From Internal Table
Read table .
The key can be table key or other keys .
Search Using Table Key : Read table from [into ].
Read table with table key
= = [ into ]
Linear search for standard table , Binary search for sorted
table and search using hashing algorithm takes place for
hashed table .If no key is defined , no record will be
fetched .
-
8/17/2019 Internal Table Udemy
21/39
Using Different Search Key :Read table with key = [into wa] .
Read table with key = = :f2> [into
wa]
Read table into [comparing|transporting ……|all fields|no fields]
Reading into Field Symbol :
Read table assigning .
-
8/17/2019 Internal Table Udemy
22/39
Examples :-
Wa-col1 = 2 .
Wa-col2 = ‘Subhendu’ .
Read table itab from wa into wa .Read table itab from wa into wa comparing
col2 .
Read table itab with table key col1 = 45 intowa transporting col2 .
-
8/17/2019 Internal Table Udemy
23/39
Sorting Internal Tables
Used to sort standard and hashed tables .Sorting By key :
sort [ascending|descending] [as text] [stable] .
Sorting By Different Key(s) :
sort [ascending|descending] [as text] [stable]
By [ascending|descending] [as text]
By [ascending|descending] [as text]
Number of sort fields can be a maximum of 250.
For alphabetical sorting of character columns , as text options
is used .
-
8/17/2019 Internal Table Udemy
24/39
Stable sort :
sort …… stable Relative sequences of lines that are unchanged by the
sort is not changed , which otherwise , does not get
preserved if sort statement is not used .
Determining Table Attributes Describe table [lines ] [occurs ] [kind
]
No. of filled lines in the table is written to variable l
, Initial size of the table is written to n and the typeof the internal table is written to K
( k=T for standard table/S for sorted table/H for HashedTable)
-
8/17/2019 Internal Table Udemy
25/39
Changing Lines
Using Table Key :-
Modify table from [ transporting
….]F1 ,f2 etc will be updated from wa
Changing Several Lines Using Conditions :-
Modify < itab> from transporting …. Where .
-
8/17/2019 Internal Table Udemy
26/39
Deleting Lines
Deleting Records Using Table Key :
Delete table from .
Delete table with table key = =
….. .Deleting Several Lines :
Delete where
Delete
Deleting Adjacent Duplicate Entries :
delete adjacent duplicates from [ comparing
….|all fields]
-
8/17/2019 Internal Table Udemy
27/39
Processing Loops in Internal Table
Loop at .
…. ……..
Endloop .
Loop at assigning .
… ….
Endloop .
-
8/17/2019 Internal Table Udemy
28/39
Example :-
loop at submat into ln .write :/ ln-matnr , ln-meins .
endloop .
Submat is an internal table , each record of which is taken into a structure ln(
which is identical to line type of the internal table)
loop at intm2 from 2 to 4 where meins = 'L' .
write :/ matdet-matnr , matdet-maktx ,
matdet-meins .
skip 1 .endloop .
(True for standard and sorted tables)
-
8/17/2019 Internal Table Udemy
29/39
Looping into the header line :-
Loop at intmat .
write:/ intmat-matnr , intmat-maktx .
Endloop .
-
8/17/2019 Internal Table Udemy
30/39
Operations For Index Tables
Applicable for internal tables maintaining index , viz.,standard and sorted tables .
-
8/17/2019 Internal Table Udemy
31/39
Appending LinesAppend to .
Append lines of [From ] [ to ] to .
Append to sorted by .
Insert into index .
Insert lines of into index .
Insert lines of from to into index .
When index is used , the new record is added before theline with index .
-
8/17/2019 Internal Table Udemy
32/39
Reading lines
Read table index .
Read table assigning index .
Deleting Lines :DELETE index .
Delete from to [where ] .
Modifying lines :Modify [from wa] [index ] [transporting c1
c2 …. [where expression]]
Write to index
Index In Loops :Loop at [from ] [to ]
. ………….. . Endloop .
-
8/17/2019 Internal Table Udemy
33/39
Default with sorted tables and can be adapted forsearching standard tables also .
Can be used for fetching records from standard tableusing a key other than default key.
Standard table must be sorted in ascending order bythe specified search key .The BINARY SEARCHaddition means that accessing an entry in a standardtable by its kay can be made as quickly as would beable to do in sorted table .
Searching Records Using Binary Search
READ TABLE WITH KEY = BINARYSEARCH .
READ TABLE WITH KEY = .. = binary search .
-
8/17/2019 Internal Table Udemy
34/39
Finding Character Strings in Internal Tables
SEARCH FOR .
Searches the internal table for the character string.
IF found :
SY-SUBRC = 0 SY-
TABIX = index of the table line in which the string wasfound.
SY-FDPOS = the offset position of the string in the table
line.
IF not found :
SY-SUBRC is set to 4.
The statement treats all table lines as type C fields, regardless of their
actual line type.
-
8/17/2019 Internal Table Udemy
35/39
Options :
•ABBREVIATED
Field is searched for a word containing the string in .The characters can be separated by other characters. The first
letter of the word and the string must be the same.
•STARTING AT
Searches table for , starting at line .
•ENDING AT
Searches table for , upto line .
•AND MARK
If found, all the characters in the search string (and all the
characters in between when using ABBREVIATED) are
converted to upper case.Operates for index tables only .
-
8/17/2019 Internal Table Udemy
36/39
CONTROL STATEMENTS
Used to react to control breaks in internal tables .Control Statements Significance
At first/endat Control for first line of internal table;
At last/endat Control for first line of internal table
At new /endat Control for beginning of a group of lines with
the same contents in the field and in the
fields left of
At end of /endat Control for end of a group of lines with the
same contents in the field and in the fieldsleft of
On change of
/endon
Perform Control break processing for a field f1
Use the SUM statement to calculate totals for the rows at control level
-
8/17/2019 Internal Table Udemy
37/39
Accessing Internal Tables Using FieldSymbols :
Lines of an internal table can be assigned to field symbols when
the contents of an internal table is read using READ statement or
in a LOOP . The ….ASSIGNING is used for that . The
field symbol points directly to the assigned line in memory.Field symbols allow to read and change table entries directly .
Disadvantage:-
While accessing , the contents of the key fields of sorted or
hashed tables should not be changed . The SUM statements atcontrol breaks cannot be used also .
Advantage :
No overhead for reading or modifyint internal table
-
8/17/2019 Internal Table Udemy
38/39
EDITOR-CALL FOR Internal Tables
Editor-call for [title ] [Display mode]
[Backup into ]
Displays the internal table itab in an editor similiar to the ABAP Editor.You can then use normal editor functions to make changes.
•The internal table itab must have the table type STANDARD TABLE,
and can contain only type C components.
The lines of the internal table can be up to 72 characters long.
The records in internal table can be changed and saved :-
•SY-SUBRC = 0 when changes are made during the session. SY-
SUBRC =2 if no changes are made .SY-SUBRC=4 means that the table
is not saved .
-
8/17/2019 Internal Table Udemy
39/39
See program : ysubint for demo oninternal tables