Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
- Kunal Behary
2009 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
Objectives
Introduce the structure of an Internal Table Explore ways of defining an Internal Table in ABAP Explore ways of filling an Internal Table in ABAP Examine how to sort an Internal Table Examine how to retrieve lines from an Internal Table
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
line.
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
Performance Issues
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
Examples : insert vendtab index 3. The contents of the header line will be inserted before line 3.
insert lines of new_vend from 2 to 5 into vendtab index 3. Lines 2 to 5 of the internal table new_vend will be inserted before line 3 of vendtab.
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
10
Retrieving lines
Once an internal table has been filled, data can be retrieved by reading each line of the table using a loop, or reading individual lines. Examples : 1) loop at stud_tab. write / stud_tab-studid. write stud_tab-studname. endloop. 2) loop at stud_tab where studname = Smith. write / stud_tab-studid. endloop.
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
11
4)
5)
6)
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
12
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
13
t_cust_info LIKE
STANDARD TABLE OF zcustomers. SELECT * FROM zcustomers INTO TABLE cust_info. SORT cust_info BY cnum. READ TABLE cust_info WITH KEY cnum = 3456755 BINARY SEARCH. IF sy-subrc = 0. cust_info-cphone = 9654-2345. MODIFY cust_info INDEX sy-tabix. ENDIF. LOOP AT cust_info. WRITE: / cust_info-cnum, cust_info-cname. ENDLOOP.
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
14
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
15
Proprietary Information. DCDM Consulting. Not be disclosed without express written consent.
Objectives
Revise the structure of internal tables Review the attributes of internal tables Describe the three internal table kinds: standard, sorted, hashed Examine the features and application of STANDARD internal tables Examine the features and application of SORTED internal tables Examine the features and application of HASHED internal tables Distinguish between the use of work areas Vs header lines when processing internal tables
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
17
f2 XX
2
3
data: BEGIN OF itab OCCURS 10, f1, f2, f3, END OF itab.
B
C
YY
YY
LOOP AT itab. write: / sy-tabix, itab-f1, itab-f2. ENDLOOP. WRITE: / 'done. sy-tabix =', sy-tabix, / ' sy-subrc =', sy-subrc. OUTPUTS: 1 A XX 2 B YY 3 C YY sy-tabix = 99 sy-subrc = 0
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
18
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
19
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
20
DATA: itab TYPE STANDARD TABLE OF sbook WITH NON-UNIQUE KEY bookid.
DATA:
21
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
22
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
23
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
24
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
25
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
26
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
27
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
28
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
29
Sorted table
When you choose to use a sorted table, it will normally be because you want to define and use a unique key. When a sorted table is created the data is first sorted and then inserted. If you have a table with few entries but lots of accesses that change the contents, a sorted table may be more efficient than a standard table in terms of runtime because of binary search access.
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
30
Hashed table
The hash algorithm calculates the address of an entry based on the key. This means that, with larger tables, the access time is reduced significantly in comparison with a binary search. But when you use a loop with a hashed table, the whole table has to be scanned. Because the data records are usually totally unsorted, a sorted table may be more useful if you have a loop over the beginning of a key. Alternatively, you could also sort the hashed table. Hashed table is only beneficial if you want to keep large amounts of data locally in the program and you mostly access it only to read it. You must ensure that you design your hashed table so that it is possible to specify the full key when you access it from your program. Typical use for hashed tables is for buffering or bundling large amounts of data from several database tables when an ABAP Dictionary view or a nested SELECT statement is not possible.
2010 DCDM. All Rights Reserved. Proprietary Information. Not to be disclosed without prior written agreement.
31