Você está na página 1de 40

INTERNAL TABLES

~ Madhusudan

Powered By iGATE SAP University


1
Making SAP Simple

iSU

INTERNAL TABLES
These internal tables can be created as a replica of data base table, using some or all fields of one table or more tables.
These internal tables are created only during run time. No memory is reserved.

iSU

Why we need inttables?


Long Life data is stored in database tables. When we are directly modifying data, there is every possibility that we may loose data by accident, which we can not afford to do so. As such we need some intermediate tables to do some operations. Up on satisfactory results, we can modify database table

iSU

Types of internal tables


Basically there are 2 types of Internal tables. Internal tables with header line. Internal tables without header line.

iSU

Internal tables with header line


When you create internal table with header line, a default work area is created.

iSU

Internal table with out header line


In this case, we need to create explicit work area to work with it. When we need to nest the tables with in tables, we need to use this type of internal table.

iSU

Steps in creating internal tables


There are 3 steps involved in creating Internal tables. Declaration of Internal table. Populating Internal table. Processing Internal table.

iSU

Declaration of internal table

Declaring table type


1. Data dictionary

2.

Using TYPES key word

iSU

Using TYPES key word

TYPES: Begin of <Structype>, . End of <Structype>.

First

DATA: <tablename> TYPE <itabkind> OF <Structype>

Second

WITH {UNIQUE|NON-UNIQUE} KEY <keys>] [INITIAL SIZE <n>] [WITH HEADER LINE].

iSU

TABKIND ( TABLE KIND)


1. STANDARD TABLE

2. SORTED TABLE 3. HASHED TABLE 4. INDEX 5. ANY TABLE TABLE

Which TABKIND to choose depends on how you are accessing the Entries in the internal table.
10

iSU

STANDARD TABLE This table type is most appropriate when you intend to address the table entries using the index. Key access to the standard table uses linear search.

This means that the time required for a search is in linear relation to the number of table entries.
You should use index operations to access standard tables.

11

iSU

SORTED TABLE Defines the table as one that is always saved correctly sorted. Key access to a sorted table uses a binary key. You can also access sorted tables by index operations.

The time required for a search is in logarithmical relation to the number of table entries.
iSU

12

HASHED TABLE Defines the table as one that is managed with an internal hash procedure. You can imagine a hashed table as a set, whose elements you can address using their unique key.

Unlike standard and sorted tables, you cannot access hash tables using an index. Access time using the key is constant, regardless of the number of table entries.
13

iSU

INDEX TABLES

Standard and sorted tables belong to the generic class index tables.

An index table is one that you can access using an index.

14

iSU

ANY TABLE
The set of permitted operations for a table with type ANY TABLE consists of the intersection of all permitted operations for STANDARD, SORTED and HASHED TABLES, and so is identical to the set of operations permitted for hashed tables.

15

iSU

16

iSU

LINETYP ( LINE TYPE) The line type of an internal table can be any ABAP data type (including another internal table). Line type gives the columns required for the internal table.

17

iSU

Key
The key is used to identify lines in the table. There are two possible keys for an internal table 1. The default key 2 User-defined key. You can specify that the key should by UNIQUE or NON-UNIQUE. If the key is unique, the internal table may not contain duplicate entries. The uniqueness of the key depends partly on the table type.
iSU

18

Populating internal tables


Selecting the fields from the standard table(s) and transferring them to the internal table created. For this we use SELECT STATEMENTS.

19

iSU

PROCESSING INTERNAL TABLES


Processing of internal table includes: Write Read Insert Modify Delete Collect

20

iSU

PROCESSING INTERNAL TABLES CONTD

Other operations like.. Clear Refresh Free

21

iSU

Write
loop at itab < where carried = LH >. Write:/ itab-carrid,itab-connid,itab-fldate. endloop.

22

iSU

Internal Table
Loop At...

SCREEN Carrid Connid Fldate

AA AA AL DL

0017 0026 0555 1699

10/29/1998
11/26/1998 11/21/1998

11/29/1998

23

iSU

Read
Read table itab index <index>. OR Read table itab with key carrid = LH connid = 0400.

24

iSU

Internal Table
Read Table

AA
Carrid

0017
Connid

10/29/1998

Header line

Fldate
10/29/1998
11/26/1998 11/21/1998

AA AA AL DL

0017 0026 0555 1699

Body

11/29/1998

25

iSU

Insert
itab-carrid = MN. itab-connid = 1111. insert itab index 3.

26

iSU

Internal Table
Insert table

Header line Carrid Connid Fldate

AA AA AL DL

0017 0026 0555 1699

10/29/1998 11/26/1998 11/21/1998 11/29/1998

Body

27

iSU

Modify
itab-carrid = NM. itab-connid = 2222. modify itab index 3.

28

iSU

Internal Table
Modify

Internal Table Header line


10/29/1998

Header line AA 0017 (change)

AA Carrid

0050 Connid

10/29/1998

Carrid Connid

Fldate
10/29/1998

Fldate
10/29/1998
11/26/1998 11/21/1998 11/29/1998

AA AA 0017 0017 AA 0026


AL DL 0555 1699

AA
Modify

0050 0026
0555 1699

11/26/1998 11/21/1998 11/29/1998

AA
AL DL

TABLE: SFLIGHT
29

iSU

Delete
delete itab index 3. OR delete from itab where carrid = LH.

30

iSU

Internal Table
Delete

Internal Table Header line


10/29/1998

Header line AA Carrid AA AA AA AL DL 0017 Connid 0017 0017 0026 0555 1699 (delete)

AA

0017

10/29/1998

Fldate
10/29/1998 11/26/1998 11/21/1998 11/29/1998

Carrid Connid Fldate Modify AA AL DL 0026 0555 1699


11/26/1998 11/21/1998 11/29/1998

TABLE: SFLIGHT
31

iSU

Initializing internal table


clear itab. clear itab [ ]. refresh itab. free itab : clears header of int table. : clears body. : remove contents. : deallocates memory associated with int table.

32

iSU

Internal Table
Clear - Refresh

CLEAR Carrid AA Connid 0017 0026 0555 1699 Fldate


10/29/1998 11/26/1998 11/21/1998 11/29/1998

Header line

REFRESH

AA AL DL

Body

33

iSU

Sorting of internal table


sort itab. This command will sort internal table on all non-numeric fileds in ascending order. sort itab by carrid. sort itab by carrid descending.

34

iSU

Database Table
Sort

Internal Table Header line

Header line

Move
Body Carrid DL AA AL AA Connid 1699 0026 0555 0017 Fldate Append
11/29/1998 11/26/1998 11/21/1998 10/29/1998

Body Carrid Connid AA AA AL DL 0017 0026 0555 1699 Fldate


10/29/1998 11/26/1998 11/21/1998 11/29/1998

TABLE: SFLIGHT
35

iSU

Collect itab

If non numeric fields are same, then numeric fields will be added by using this command.

36

iSU

External Table
Collect

Internal Table
Header line

Header line

Carrid AA AA AL DL

Connid Seatsmax 0017 0017 0064 1699 660 280 220 380

Carrid Connid Seatsmax AA AL DL 0017 0064 1699 940 220 380

TABLE: SFLIGHT
37

iSU

Questions???

38

iSU

THANKS!
Please complete the feed back form which will be sent across and send it back to Dinesh.Vennu@igate.com.

iGATE SAP University


Making SAP Simple

39

iSU

KEY CONTACTS:

Presenter : Madhusudan Rao Budati Madhusudan.Budati@igate.com iSU Team Details : Dinesh Vennu Dinesh.Vennu@igate.com Madhusudan Rao Budati Madhusudan.Budati@igate.com

Pradeep Kumar Reddy Pradeep.Teelati@igate.com Aswani Kumar Nune Aswanikumar.Nune@igate.com

40

iSU

Você também pode gostar