Sie sind auf Seite 1von 18

ABAP/4 PROGRAMMING

Internal Table

2000 9 26

Internal Table
Internal table is a temporary table stored in
RAM on the application server.
It is created and filled by a program during
execution and is discarded when the
program ends.
An internal table consists of a body and an
optional header line.

Definition
Data: begin of it occurs
0,
f1(1),
f2(2),
end of it.

header line
it
f1
body

The definition of an
internal table named it.
It contains two fields
f1,f2.

it

f2

Add data and Read data


append [wa to] [initial line to] it.
loop at it [into wa] [from m] [to n] [where
exp].----endloop.
read table it [into wa] [index i | with key
keyexp [binary search] ] [comparing
cmpexp] [transporting texp].

Syntax for the sort statement


sort it [descending] [as text] [by f1
[ascending|descending] [as text] f2]

Advanced Internal Table(1)


it[] means the body of the internal table it
if internal table it does not have a header
line,you can use either it[] or it represent the
body,they are equivalent
Without a header line, you can perform
efficient table operations

Information about an internal table


Determining whether an internal table is
empty:
if it[] is initial.
Determining the number of rows in an
internal table:
describe table it [lines i] [occurs j].

Copying data from one internal


table to another
it2[] = it1[].
Two internal tables have the same structure if
they both have the same number of components,
the data type and length of each component is the
same as the corresponding of another
only the component names do not have to match

Using append lines /insert lines


statement
append lines of it1 [from nf] [to nt] to it2.
insert lines of it1 [from nf] [to nt] into it2
[index nb].
User insert lines statement when you want
to insert rows at a place other than the end
into the target table.

Inserting rows into an internal table


insert [wa into] it [index n]
if index is specified, the new row is inserted
before row n.Row n then becomes row n+1

Modifying rows in an internal table


modify it [from wa] [index n] [transporting
c1 c2 [where exp]]
transporting specifies which components
are to be overwritten.

Exercise: Read contents of


zmkpf_xx into an internal table
Filling your tables zmkpf_fdevxx
Use select into table
Modify the usnam column so that the third
row contains TOM (use modify
transporting where)
Modify the mjahr, changing all 1994 to
2000 (use modify transporting where)

Deleting rows in an internal table


free : delete all rows from an internal table
and free the associated memory
refresh : delete all rows from an internal table
but leave the memory allocated
clear : either clear the header line or delete all
rows from it and leave the memory allocate
delete : delete one or more rows from an
internal table

Filling an internal table using collect


collect [wa into] it.
When collect is executed, the system forms a
key from the default key fields int the wa
The key composed of the values from all fields
of type c, n, d, t, and x.
System searches it for a row that has the same
key in wa. If not, the row is appended to the
end of the table.If it does find,the fields in wa
are added to the corresponding row

Advanced Internal Table(2)


Filling an internal table from a DB table:
Selecting multiple rows directly into the body
of an internal table.
Selecting single rows into a work area and then
appending

Selecting multiple rows


select *
from dbtab into [corresponding fields of] table it

select f1 f2
from dbtab into [corresponding fields of] table it

f1 and f2 are fields within dbtab


Other additions, such as where and order by,
can follow it
endselect is not used with into table. select
into table does not start a loop.

Using the corresponding fields


The components of the internal table arent
in the same order as those from database
Or they dont have the same data type and
length as those from database
The statement moves fields from the
database table into fields of the same name
in the internal table body

Exercise: Using internal table


Sorting function with desceding
Drilldown function
Design a GUI status using menu painter

Das könnte Ihnen auch gefallen