Beruflich Dokumente
Kultur Dokumente
3/18/13
Topics
22
3/18/13
Objectives
The participants will be able to: Create a Structure in an ABAP Program Create an Internal Table in an ABAP program Populate an Internal Table with data Read Database information into an Internal Table
3/18/13
Data Structures
Internal Table Address List LN LN LN FN FN FN City City City ST. ST. ST.
3/18/13
Is this statement necessary for the 1 REPORT YN1C0008. code? 2 Basic Syntax: 3 TABLES: TABNA. DATA: BEGIN OF <name> 4 DATA: BEGIN OF <field1> . . . ADDRESS, <field2> . . . 5 FLAG TYPE C, ... 6 ID LIKE TABNA-ID, END OF <name>. 7 NAME1 LIKE TABNANAME1, 8 CITY LIKE TABNA-CITY, 9 END OF ADDRESS. 10 MOVE X TO ADDRESS-FLAG. 11 MOVE 0001TO ADDRESS-ID. 12 MOVE Smith TO ADDRESSAddress NAME1. Structure 13 MOVE Philadelphia TO Flag ID Name1 City 14 ADDRESS- CITY. 15 WRITE ADDRESS.
16 17 5 55
3/18/13
Address Structure
Flag ID Name1 City
6 66
3/18/13
7 77
3/18/13
Demonstration
w
Declaring a structure and populating the structure with values inside a program.
8 88
3/18/13
Practice
w
Declaring a structure and populating the structure with values inside a program.
9 99
3/18/13
10 1010
3/18/13
The TYPES statement defines the structure and data type for the internal table. The DATA statement with an INITIAL SIZE creates the actual internal table capable of storing data. Because of the WITH HEADER LINE addition, this internal table is created with a header NAME1 line. ID COUNTRY
3/18/13
12 1212
3/18/13
APPEND <int. table>. Department Salary R&D MKTG SALES PROD IT HR 400,000 1,000,000 500,000 7,800,000 50,000 140,000
1 2 3 4 5 6
APPEND <int. table> SORTED BY Salary Department <field>. R&D 400,000 PROD 7,800,000 MKTG 1,000,000 SALES 500,000 HR 140,000 IT 50,000
Hea der
13 1313
3/18/13
With both versions of the APPEND statement, memory space for ten records is allocated when the first record is written to the internal table. Example 1 More than ten entries can be saved in the internal table. Example 2
A maximum of ten APPEND EMPTAB. entries can be saved O in the internal table. MOVE-CORRESPONDING EMPLOYEE TO R Any entries that EMPTAB. exceed the top ten APPEND EMPTAB SORTED BY SALARY. 14 3/18/13 will ENDSELECT. be deleted. Data Structure & Internal Tables | 3.07 1414
With both versions of the APPEND statement, memory space for ten records is allocated when the first record is written to the internal table. Example 1 More than ten entries can be saved in the internal table. Example 2
A maximum of ten APPEND EMPTAB. entries can be saved O in the internal table. MOVE-CORRESPONDING EMPLOYEE TO R Any entries that EMPTAB. exceed the top ten APPEND EMPTAB SORTED BY SALARY. 15 3/18/13 will ENDSELECT. be deleted. Data Structure & Internal Tables | 3.07 1515
EMPLOYE E
COUNTRY .
ID
FORMA
NAME1
SORTL
. .
ID
NAME1COUNTRY
Header Line
16 1616
3/18/13
EMPLOYE E
. . .
ID COUNTRY
17 1717
3/18/13
EMPLOYE E
COUNTRY ID FORMA NAME1 SORTL . . . USA 00000001 Company Baker Distributors BAKER 2 ID NAME1 COUNTRY USA 00000001 Baker Distributors
. . .
Header Line
18 1818
3/18/13
. . .
19 1919
3/18/13
3/18/13
REPORT Y170DM40. TABLES: EMPLOYEE. TYPES: BEGIN OF EMP, ID LIKE EMPLOYEE-ID, NAME1 LIKE EMPLOYEE-NAME1, COUNTRY LIKE EMPLOYEE-COUNTRY, END OF EMP. DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10, EMPTAB_WA TYPE EMP. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB_WA. APPEND EMPTAB_WA TO EMPTAB. Work ENDSELECT.
Area
ID
NAME1
COUNTRY
3/18/13
Performance Issues
22 2222
3/18/13
ID COUNTRY
NAME1
Work Area
23 2323
3/18/13
This work area is not attached to the body of the internal table.
3/18/13
Individual field type conversion Structure to structure Field to structure Structure to field
MOVE
25 2525
3/18/13
REPORT Y170DM69. TABLES: EMPLOYEE. DATA: EMPTAB LIKE STANDARD TABLE EMPLOYEE INITIAL SIZE 10 WITH HEADER LINE. SELECT * FROM EMPLOYEE INTO TABLE EMPTAB WHERE COUNTRY = USA.
26 2626
3/18/13
This LOOP AT <EMPTAB> statement allows for a logical expression in a WHERE clause to limit the processing of the internal table.
DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. ENDSELECT. LOOP AT EMPTAB WHERE COUNTRY BETWEEN A AND D. WRITE: / EMPTAB-COUNTRY, EMPTAB-NAME1, EMPTAB-SALES. ENDLOOP. IF SY-SUBRC NE 0. WRITE: / NO ENTRIES. ENDIF.
If no internal table entries qualify under the logical expression, the statement within the loop is not executed and SY-SUBRC is set to 4.
27 2727
3/18/13
END OF EMP. DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE. PARAMETERS: 10, START LIKE SY-TABIX DEFAULT
Screen output
END LIKE SY-TABIX DEFAULT 20. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. ENDSELECT. LOOP AT EMPTAB FROM START TO END. WRITE: / SY-TABIX, EMPTAB-COUNTRY, 28 EMPTAB-NAME1. Data Structure & Internal Tables | 3.07 2828 ENDLOOP.
SY-TABIX
3/18/13
LIKE EMPLOYEE-SALES,
END OF EMP. DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE. SELECT * FROM EMPLOYEE.
A CH MOVE-CORRESPONDING EMPLOYEE TO 45,305.00 EMPTAB. D COLLECT EMPTAB. 8,200,000.00 ENDSELECT. F 0.00 GB 500,000.00 LOOP AT EMPTAB. NL 577,000.00 WRITE: / EMPTAB-COUNTRY, EMPTABNO 234.00 SALES. USA 29 3/18/13 ENDLOOP. 1,000,000.00 Data Structure & Internal Tables | 3.07 2929
Sale s 400,00
Header Line
Sorting options: 1) SORT <EMPTAB> - sorts the entries of the internal table <EMPTAB> in ascending order.
2) SORT <EMPTAB> BY <field> - sorts the table on DATA: EMPTAB TYPE STANDARD TABLE OF EMP one or more fields within INITIAL SIZE 10 WITH HEADER LINE. the table.
END OF EMP. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. ENDSELECT. SORT EMPTAB BY SALES DESCENDING. LOOP AT EMPTAB. WRITE: / ITAB-COUNTRY, ITAB-NAME1, ITAB30 SALES. 3/18/13 Data Structure & Internal Tables | 3.07 3030 ENDLOOP.
screen output
AT FIRST AT NEW < field > AT END < field > AT LAST
31 3131
3/18/13
32 3232
3/18/13
33 3333
3/18/13
34 3434
3/18/13
APPEND <work area> TO <internal table>. COLLECT <work area> INTO <internal table>. INSERT <work area> INTO <internal table>. MODIFY <internal table> FROM <work area>. READ TABLE <internal table> INTO <work area>. LOOP AT <internal table> INTO <work area>.
35 3535 Data Structure & Internal Tables | 3.07
3/18/13
Initialises the header line. Internal table lines remain unchanged. REFRESH <internal table> FREE <internal table>
Deletes all table lines. Storage space is not released. Paging is released. Header line remains unchanged.
Deletes all table lines. Storage space is released. Header line remains unchanged
36 3636
3/18/13
screen output
3/18/13
screen output
38 3838
3/18/13
Demonstration
w
Declaring an internal table, populating it by selecting data from the table and then looping into it and displaying the data fetched.
39 3939
3/18/13
Practice
w
Declaring an internal table, populating it by selecting data from the table and then looping into it and displaying the data fetched.
40 4040
3/18/13
Summary
Structures in code are temporary objects in program memory. A structure can be defined using a combination of the TYPES and DATA statements. The statement MOVE-CORRESPONDING transports values field by field between the ABAP data structures. Internal table, that can store records of data temporarily during the processing of a program. 3 different types of internal tables: Standard, Sorted, and Hashed. An internal table object is created with the DATA statement by referring to an internal table type using the TYPE parameter APPEND statement adds the contents of the header line to the end of the internal table. the system field SY-TABIX is set to the line number of the entry read.
41 4141
3/18/13
Summary (Contd.)
w
The CLEAR statement resets all fields to their initial value. The REFRESH statement deletes all table lines. The FREE statement releases the storage space required for a table.
42 4242
3/18/13
Questions
What is a Structure? What is an internal table? What are the different types of internal tables are there? Explain the following statements : Move corresponding Append Clear Refresh Free.
43 4343
3/18/13
Thanks
44
3/18/13