Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
BC430_EN_Col62_FV_Part_A4_-_ABAP_Dictionary.pdf
Скачиваний:
204
Добавлен:
21.05.2015
Размер:
21.37 Mб
Скачать

BC430

Lesson: Basic Data Types

Exercise 2: Simple and Nested Structures

Exercise Objectives

After completing this exercise, you will be able to:

Create simple and nested structures in the Dictionary and use them in ABAP programs

Business Example

In order to map complex data structures, you should build up a complex structure for your project in the Dictionary.

Task 1:

Create simple structures that you can use later in ABAP programs.

1.In the Dictionary, create a structure ZNAME## and include the following two components in the structure. Use the data elements that you created in previous exercises for typing.

Component

Component Type

Description

 

 

 

FIRSTNAME

own

first name

 

 

 

LASTNAME

own

last name

 

 

 

2.Create a structure ZADRESS## and enter the four following components:

Component

Component Type

Description

 

 

 

STREET

S_STREET

Street

 

 

 

NR

S_NO

House number

 

 

 

ZIP

POSTCODE

Post code

 

 

 

CITY

S_CITY

Place of residence

 

 

 

Task 2:

Create a nested structure, so that you can use it later in ABAP programs.

1.Create a structure ZPERSON## in the Dictionary.

Continued on next page

2006/Q2

© 2007 SAP AG. All rights reserved.

31

Unit 2: Data objects in the ABAP Dictionary

BC430

2.Add the structure ZADRESS## as an Include structure to the ZPERSON## structure. In addition, take on the structure ZNAME## in the ZPERSON## structure as a nested structure under the component name NAME

3.Enter an ABAP program ZBC430_##_STRUCT_NESTED. Create a structured data object (wa_person) in this program of the type ZPERSON##. Fill the components of this data object with any personal data and output this data in a list.

32

© 2007 SAP AG. All rights reserved.

2006/Q2

BC430

Lesson: Basic Data Types

Solution 2: Simple and Nested Structures

Task 1:

Create simple structures that you can use later in ABAP programs.

1.In the Dictionary, create a structure ZNAME## and include the following two components in the structure. Use the data elements that you created in previous exercises for typing.

Component

Component Type

Description

 

 

 

FIRSTNAME

own

first name

LASTNAME

own

last name

a)Start SE11 and enter the name of the structure in the Data type input field.

b)Choose Create and select Structure in the following dialog.

c)Provide a short description and enter the specified components. Activate the structure so that it is globally known.

2.Create a structure ZADRESS## and enter the four following components:

Component

Component Type

Description

 

 

 

STREET

S_STREET

Street

 

 

 

NR

S_NO

House number

 

 

 

ZIP

POSTCODE

Post code

 

 

 

CITY

S_CITY

Place of residence

 

 

 

a)Proceed in the same way as in the previous part of the exercise.

Task 2:

Create a nested structure, so that you can use it later in ABAP programs.

1.Create a structure ZPERSON## in the Dictionary.

a)Proceed in the same way as in the previous part of the exercise.

Continued on next page

2006/Q2

© 2007 SAP AG. All rights reserved.

33

Unit 2: Data objects in the ABAP Dictionary

BC430

2.Add the structure ZADRESS## as an Include structure to the ZPERSON## structure. In addition, take on the structure ZNAME## in the ZPERSON## structure as a nested structure under the component name NAME

a)Include the address either via the menu Edit->Include->Insert or, in the Component column, write the key word .INCLUDE.

Caution: The point before the key word is important.

For the second structure, which you want to take on as a deep structure, enter any component name (e.g. 'Name').

Component

Component Type

Description

 

 

 

.include

ZADRESS##

Address structure

 

 

 

NAME

ZNAME##

Refers to the name

 

 

structure

Continued on next page

34

© 2007 SAP AG. All rights reserved.

2006/Q2

BC430

Lesson: Basic Data Types

3.Enter an ABAP program ZBC430_##_STRUCT_NESTED. Create a structured data object (wa_person) in this program of the type ZPERSON##. Fill the components of this data object with any personal data and output this data in a list.

a)See the source code excerpt from the model solution.

Result

Source text excerpt: SAPBC430S_STRUCT_NESTED

REPORT sapbc430s_struct_nested.

*Replace ## by Your groupor screennumber and *uncomment the ABAP-coding

DATA wa_person TYPE zperson##.

START-OF-SELECTION.

wa_person-name-firstname = 'Harry'. wa_person-name-lastname = 'Potter'.

wa_person-street = 'Privet Drive'. wa_person-nr = '3'.

wa_person-zip = 'GB-10889'. wa_person-city = 'London'.

WRITE: / wa_person-name-firstname , wa_person-name-lastname , wa_person-street , wa_person-nr , wa_person-zip , wa_person-city .

2006/Q2

© 2007 SAP AG. All rights reserved.

35

Unit 2: Data objects in the ABAP Dictionary

BC430

36

© 2007 SAP AG. All rights reserved.

2006/Q2

BC430

Lesson: Basic Data Types

Exercise 3: Table Types (Internal Tables /

ITABs)

Exercise Objectives

After completing this exercise, you will be able to:

Create table types and use them in ABAP programs

Business Example

For local data retention, you define a table type that keeps the data sorted.

Task:

Create simple internal tables on the basis of an existing structure, so that you can use them later in ABAP programs.

1.Create a table type ZIT_SFLIGHT## in the Dictionary. The table type should be based on the line type of the database table SFLIGHT and be sorted according to the flight date (FLDATE)

2.Enter an ABAP program ZBC430_##_ITAB_SORTED. In this program, create a structured data object (wa_sflight) of the type SFLIGHT as the work area, and an internal table on the basis of the table type just defined. From the SFLIGHT table, select the data of a carrier (e.g. 'JL') in the work area and output this as an unsorted list.

3.Extend the program as follows. Insert a line (ABAP command ULINE) in the list. Load the same data again via the SELECT command with Array Fetch into the internal table of the type ZIT_SFLIGHT## and output the content of the table using the LOOP command in the same list. Compare the order of the data in both list excerpts.

2006/Q2

© 2007 SAP AG. All rights reserved.

37

Unit 2: Data objects in the ABAP Dictionary

BC430

Solution 3: Table Types (Internal Tables /

ITABs)

Task:

Create simple internal tables on the basis of an existing structure, so that you can use them later in ABAP programs.

1.Create a table type should be based on sorted according to

ZIT_SFLIGHT## in the Dictionary. The table type the line type of the database table SFLIGHT and be the flight date (FLDATE)

a) In the SAP EASY ACCESS menu enter se11 in the command field and confirm your entry.

If you are in another transaction, you have to enter /n se11 in the command field and confirm the entry

b)Select Data Type from the radio buttons.

c)Enter the name of the table in the input field.

d)Choose Create.

e)In the subsequent dialog box, select Table Type.

f)Assign a short description and enter the name of the database table in the line type field.

g)Switch to the Initialization and Access tab page and select Sorted Table as the access type.

h)Switch to the Key tab page and select Non-unique as the key type.

i)Now select the corresponding key component from Key definition, Key components and the Choose components button.

j)Activate the table so that it is globally known.

2.Enter an ABAP program ZBC430_##_ITAB_SORTED. In this program, create a structured data object (wa_sflight) of the type SFLIGHT as the work area, and an internal table on the basis of the table type just defined. From the SFLIGHT table, select the data of a carrier (e.g. 'JL') in the work area and output this as an unsorted list.

a)See the source code excerpt from the model solution.

3.Extend the program as follows. Insert a line (ABAP command ULINE) in the list. Load the same data again via the SELECT command with Array Fetch into the internal table of the type ZIT_SFLIGHT## and output the content of the table using the LOOP command in the same list. Compare the order of the data in both list excerpts.

Continued on next page

38

© 2007 SAP AG. All rights reserved.

2006/Q2

BC430

Lesson: Basic Data Types

a)See the source code excerpt from the model solution.

Result

Source text excerpt: SAPBC430S_ITAB_SORTED

REPORT SAPBC430S_ITAB_SORTED.

**Replace ## by Your groupor screennumber and **uncomment the ABAP-coding

DATA it_flight TYPE zit_sflight##.

DATA wa_sflight TYPE sflight.

WRITE / 'Printout in tableorder of Database:'.

SELECT * FROM sflight

INTO wa_sflight

WHERE carrid = 'JL'.

WRITE: / wa_sflight-carrid, wa_sflight-connid, wa_sflight-fldate, wa_sflight-price, wa_sflight-currency, wa_sflight-planetype.

ENDSELECT.

ULINE.

SELECT * FROM sflight

INTO TABLE it_flight

WHERE carrid = 'JL'.

WRITE / 'Printout in tableorder of sorted ITAB:'.

LOOP AT it_flight INTO wa_sflight.

WRITE: / wa_sflight-carrid,

wa_sflight-connid, wa_sflight-fldate, wa_sflight-price, wa_sflight-currency, wa_sflight-planetype.

ENDLOOP.

2006/Q2

© 2007 SAP AG. All rights reserved.

39

Unit 2: Data objects in the ABAP Dictionary

BC430

40

© 2007 SAP AG. All rights reserved.

2006/Q2

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]