Wednesday, May 26, 2010

ABAP internal table2

The index Addition on the read table Statement Locates a Single Row by Its Relative Row Number

1 report ztx1106.
2 data: begin of it occurs 3,
3 f1(2) type n,
4 f2 type i,
5 f3(2) type c,
6 f4 type p,
7 end of it,
8 wa like it.
9
10 it-f1 = '10'. it-f3 = 'AA'. it-f2 = it-f4 = 1. append it.
11 it-f1 = '20'. it-f3 = 'BB'. it-f2 = it-f4 = 2. append it.
12 it-f1 = '30'. it-f3 = 'CC'. it-f2 = it-f4 = 3. append it.
13
14 read table it index 2.
15 write: / 'sy-subrc =', sy-subrc,
16 / 'sy-tabix =', sy-tabix,
17 / it-f1, it-f2, it-f3, it-f4.
18
19 read table it into wa index 1.
20 write: /,
21 / 'sy-subrc =', sy-subrc,
22 / 'sy-tabix =', sy-tabix,
23 / it-f1, it-f2, it-f3, it-f4,
24 / wa-f1, wa-f2, wa-f3, wa-f4.
25
26 read table it index 4.
27 write: /,
28 / 'sy-subrc =', sy-subrc,
29 / 'sy-tabix =', sy-tabix,
30 / it-f1, it-f2, it-f3, it-f4,
31 / wa-f1, wa-f2, wa-f3, wa-f4.

ABAP internal table

"" This Program Is Like Listing 11.4, but Only Some of the Rows Are Read

1 report ztx1105.
2 data: begin of it occurs 3,
3 f1(1),
4 f2(2),
5 end of it.
6 it-f1 = 'A'.
7 it-f2 = 'XX'.
8 append it.
9 it-f1 = 'B'.
10 it-f2 = 'YY'.
11 append it.
12 it-f1 = 'C'.
13 append it. "it now contains three rows
14
15 loop at it where f2 = 'YY'. "f2 is right, it-f2 would be wrong here
16 write: / sy-tabix, it-f1, it-f2.
17 endloop.
18 skip.
19
20 loop at it to 2. "same as: loop at it from 1 to 2.
21 write: / sy-tabix, it-f1, it-f2.
22 endloop.
23 skip.
24
25 loop at it from 2. "same as: loop at it from 2 to 3.
26 write: / sy-tabix, it-f1, it-f2.
27 endloop.
28 skip.
29
30 loop at it from 2 where f1 = 'C'.
31 write: / sy-tabix, it-f1, it-f2.
32 endloop.

Blog Archive