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

BC430

Lesson: Basic Data Types

Exercise 4: Deep Structures

Exercise Objectives

After completing this exercise, you will be able to:

Create deep structures and use them in ABAP programs

Business Example

You expand the structure of the personal data for your project team to such an extent that you can incorporate a telephone list of any length you wish for each employee.

Task:

Create an internal table based on a data object so that you can enter this in a structure. Use this in an ABAP program.

1.Create a table type for a standard table ZIT_PHONE_NUMBER## in the Dictionary. The table type should be based on the line type of the existing structure STR_PHONE.

2.Extend your existing structure ZPERSON## in the Dictionary. The new component should receive the name PHONE and be based on the internal table ZIT_PHONE_NUMBER##.

3.Create an ABAP program ZBC430_##_STRUCT_DEEP. To do this, copy your solution for the program ZBC430_##_STRUCT_NESTED or the model template SAPBC430S_STRUCT_NESTED. Extend this program by one work area for a structured data object (wa_phone) of the type

STR_PHONE.

4.Extend the program as follows:

Insert three telephone numbers into the structured data object wa_person and output this data in the same list using the LOOP command.

2006/Q2

© 2007 SAP AG. All rights reserved.

41

Unit 2: Data objects in the ABAP Dictionary

BC430

Solution 4: Deep Structures

Task:

Create an internal table based on a data object so that you can enter this in a structure. Use this in an ABAP program.

1.Create a table type for a standard table ZIT_PHONE_NUMBER## in the Dictionary. The table type should be based on the line type of the existing structure STR_PHONE.

a) In the SAP EASY ACCESS, 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, choose Table Type.

f)Provide a short description and enter the name of the structure in the line type field.

g)Switch to the Initialization and Access tab page and choose Standard Table as the access type.

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

i)Now choose Standard Key as a Key Definition

2.Extend your existing structure ZPERSON## in the Dictionary. The new component should receive the name PHONE and be based on the internal table ZIT_PHONE_NUMBER##.

a)Enter a new component with the name 'Phone' in your structure and specify the newly created table type as component type.

Compo-

Component Type

 

Description

nent

 

 

 

 

 

 

 

.include

ZADRESS##

 

Address structure

NAME

ZNAME##

 

References the

 

 

 

name structure

PHONE

ZIT_PHONE_NUMBER##

 

References the

 

 

 

telephone table

 

 

Continued on next page

42

© 2007 SAP AG. All rights reserved.

2006/Q2

BC430

Lesson: Basic Data Types

3.Create an ABAP program ZBC430_##_STRUCT_DEEP. To do this, copy your solution for the program ZBC430_##_STRUCT_NESTED or the model template SAPBC430S_STRUCT_NESTED. Extend this program by one work area for a structured data object (wa_phone) of the type

STR_PHONE.

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

4.Extend the program as follows:

Insert three telephone numbers into the structured data object wa_person and output this data in the same list using the LOOP command.

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

Result

Source text excerpt: SAPBC430S_STRUCT_DEEP

REPORT sapbc430s_struct_deep.

DATA wa_person TYPE zperson##.

DATA wa_phone TYPE str_phone.

START-OF-SELECTION.

*Fill deep structure with data 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'.

wa_phone-p_type = 'P'. wa_phone-p_number = '+31-10-9938990'.

INSERT wa_phone INTO TABLE wa_person-phone.

wa_phone-p_type = 'F'. wa_phone-p_number = '+31-10-9938991'.

INSERT wa_phone INTO TABLE wa_person-phone.

wa_phone-p_type = 'M'. wa_phone-p_number = '+31-79-12211433'.

INSERT wa_phone INTO TABLE wa_person-phone.

Continued on next page

2006/Q2

© 2007 SAP AG. All rights reserved.

43

Unit 2: Data objects in the ABAP Dictionary

BC430

*Write on List

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

WRITE: / 'Phone-Numbers:'.

LOOP AT wa_person-phone INTO wa_phone.

WRITE: AT 20 wa_phone-p_type,

wa_phone-p_number.

NEW-LINE.

ENDLOOP.

44

© 2007 SAP AG. All rights reserved.

2006/Q2

BC430

Lesson: Basic Data Types

Lesson Summary

You should now be able to:

Create domains and use them in data elements

Define data elements and use them as the basis for defining data objects in ABAP programs

Define structures and use them as the basis for defining data objects in ABAP programs

Define internal tables and use them as the basis for defining data objects in ABAP programs

Define complex (nested / deep) structures and use them as the basis for defining data objects in ABAP programs

Define global constants with the help of a type pool and use them in ABAP programs

2006/Q2

© 2007 SAP AG. All rights reserved.

45

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