Professional Documents
Culture Documents
Introduction
To
Internal Tables
3
www.aspireit.net Call us 7058198728 / 8856033664
Report - Internal Tables
4
www.aspireit.net Call us 7058198728 / 8856033664
Report - Declaring Internal Tables
Example
TYPES: BEGIN OF LINE_TYPE,
NAME(20) TYPE C,
AGE TYPE I,
END OF LINE_TYPE.
PERSONS-NAME = 'Michael'.
PERSONS-AGE = 25.
5
www.aspireit.net Call us 7058198728 / 8856033664
Report - Declaring Internal Tables
Example
PERSONS-NAME = 'Michael'.
PERSONS-AGE = 25.
APPEND PERSONS.
6
www.aspireit.net Call us 7058198728 / 8856033664
Report - Declaring Internal Tables
Referencing data dictionary object
With header line
DATA FLIGHT_TAB LIKE SFLIGHT OCCURS 10 WITH HEADER LINE.
Without header line
DATA FLIGHT_TAB LIKE SFLIGHT OCCURS 10.
DATA FLIGHT_TAB LIKE SFLIGHT.
Including structures
You can Include another structure into Internal table.
DATA : BEGIN OF T_TAB1 OCCURS 10,
FIELDS1 LIKE BKPF-BELNR,
FIELDS2 LIKE BSEG-BUZEI,
END OF T_TAB1.
In this example, T_TAB2 will also contain the fields FIELD1 & FIELD2.
7
www.aspireit.net Call us 7058198728 / 8856033664
Report - Filling Internal Tables
APPEND Statement
Appends a new line to the end of the internal table itab. If you specify wa TO,
the new line is taken from the contents of the explicitly specified work area
wa.
If you use INITIAL LINE TO, a line filled with the correct value for the type is
added. If the specification before itab is omitted, the new line is taken from
the internal table itab.
After the APPEND, the system field SY-TABIX contains the index of the
newly added table entry.
8
www.aspireit.net Call us 7058198728 / 8856033664
Report - Filling Internal Tables
INSERT Statement
Inserts a new line into an internal table. If you specify wa INTO , the new line
is taken from the contents of the explicitly specified work area wa.
When using INITIAL LINE INTO , a line containing the appropriate initial
value for its type is inserted into the table. If you omit the specification
before itab , the new line is taken from the header line of the internal table
itab.
INDEX idx specifies the table index before which the line is inserted into the
table itab .
9
www.aspireit.net Call us 7058198728 / 8856033664
Assigning internal tables
10
www.aspireit.net Call us 7058198728 / 8856033664
Extracting data from database table
11
www.aspireit.net Call us 7058198728 / 8856033664
Report - Retrieving Internal Tables
LOOP AT Statement
LOOP AT itab.
LOOP AT itab INTO wa.
Processes an internal table (DATA) in a loop which begins with LOOP and
ends with ENDLOOP. Each of the internal table entries is sent to the output
area in turn.
When LOOP AT itab. is used, the header line of the internal table itab is used
as output area.
In the case of LOOP AT itab INTO wa , there is an explicitly specified work
area wa.
If the internal table is empty, all the statements between LOOP and
ENDLOOP are ignored.
In each loop pass, SY-TABIX contains the index of the current table entry.
After leaving a LOOP, SY-TABIX has the same value as it had before.
12
www.aspireit.net Call us 7058198728 / 8856033664
Report - Retrieving Internal Tables
READ Statement
13
www.aspireit.net Call us 7058198728 / 8856033664
Report - Modifying Internal Tables
MODIFY Statement
Note
The counting of table entries begins with 1.
14
www.aspireit.net Call us 7058198728 / 8856033664
Report - Deleting Internal Tables
DELETE Statement
DELETE itab.
The current entry of the internal table itab is deleted in a LOOP loop.
Return code value is set to 0.
15
www.aspireit.net Call us 7058198728 / 8856033664
Report - Deleting Internal Tables
DELETE Statement
16
www.aspireit.net Call us 7058198728 / 8856033664
Report - Sorting Internal Tables
SORT Statement
SORT itab DESCENDING.
SORT itab ASCENDING.
SORT itab BY f1 f2 ... fi.
Sorts the entries of the internal table itab in ascending order. The default
key is used as the sort key for internal tables.
Sorts itab by the sub-fields f1, f2 , ..., fi which form the sort key. These fields
can be any type (even number fields or tables).
Unless you specify otherwise, the sort is in ascending order. You can also
use additions 1 and 2 before BY if you want all sub-fields to apply.
To change the sort sequence for each individual field, specify
DESCENDING or ASCENDING after each of the sub-fields f1 , f2 , ..., fi .
17
www.aspireit.net Call us 7058198728 / 8856033664
CLEAR/REFRESH
CLEAR ITAB.
If ITAB is an internal table without a header line, the entire table is
deleted together with all its entries.
If, however, ITAB is an internal table with a header line, only the
subfields in the table header entry are reset to their initial values.
To delete the entire internal table together with all its entries, you
can use CLEAR ITAB[ ] or REFRESH ITAB.
NOTE:
CLEAR f.
Clears the field contents
18
www.aspireit.net Call us 7058198728 / 8856033664
Report - Retrieving Internal Table attributes
DESCRIBE Statement
Additions :
1. ... LINES lin
Places the number of filled lines of the table t in the field lin.
2. ... OCCURS n
Transfers the size of the OCCURS parameter from the table definition
to the variable n.
19
www.aspireit.net Call us 7058198728 / 8856033664
Report - Control Break With Internal Tables
All these structures begin with AT and end with ENDAT. The sequence
of statements which lies between them is then executed if a control
break occurs.
AT NEW f. / AT END OF f.
f is a sub-field of an internal table processed with LOOP.
The sequence of statements which follow it is executed if the sub-
field f or a sub-field in the current LOOP line defined (on the left)
before f has a different value than in the preceding (AT NEW) or
subsequent (AT END OF) table line.
AT FIRST. / AT LAST.
Executes the appropriate sequence of statements once during the
first (AT FIRST) or last (AT LAST) loop pass.
20
www.aspireit.net Call us 7058198728 / 8856033664
Report - Control Break With Internal Tables
AT FIRST
Statements are executed before any records are processed while
looping at Internal table.
Example :
LOOP AT itab.
AT FIRST.
WRITE : SY-ULINE.
ENDAT.
ENDLOOP.
21
www.aspireit.net Call us 7058198728 / 8856033664
Report - Control Break With Internal Tables
AT LAST
Statements are executed after all records are processed while looping
at Internal table.
Example :
LOOP AT itab.
AT LAST.
WRITE : SY-ULINE.
ENDAT.
ENDLOOP.
22
www.aspireit.net Call us 7058198728 / 8856033664
Report - Control Break With Internal Tables
Example :
LOOP AT itab.
AT NEW I_LIFNR.
WRITE : SY-ULINE
ENDAT.
ENDLOOP.
23
24
Report - Control Break With Internal Tables
25
Report - Summation
SUM Statement
SUM.
SUM calculates the control totals of all fields of type I , F and P and places them
in the LOOP output area (header line of the internal table or an explicitly
specified work area).
You can use the SUM statement both at the end and the beginning of a control
group
Example:
LOOP AT itab.
AT LAST.
SUM.
WRITE : itab-fld1.
ENDAT.
ENDLOOP.
Prints the sum of values of fld1 in all rows of itab.
Fld1 should be a numeric type field
26
Report - Summation
COLLECT Statement
COLLECT [wa INTO] itab.
27
Report - Summation
INT_EMPTMSHT INT_TMSHTSUM
1000 20040102 5 1000 12
1000 20040103 7
1001 20040103 8 1001 8
1001 20040106 3
28
Report - Summation
INT_EMPTMSHT
1000 20040102 5
1000 20040103 7
1001 20040103 8
1001 20040106 3
29
Thank You
For SAP ABAP Online / Classroom Training
Please visit our website www.aspireit.net
call us on 7058198728 / 8856033664
30