Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
AbapWB_content_EN.doc
Скачиваний:
1
Добавлен:
01.03.2025
Размер:
40.44 Mб
Скачать

Case pa_op.

WHEN ’+’.

result = pa_int1 + pa_int2. WHEN ’-’.

result = pa_int1 - pa_int2. WHEN ’*’.

result = pa_int1 * pa_int2.

When ’/’.

result = pa_int1 / pa_int2. ENDCASE.

Continued on next page

WRITE: ’Result:’(res), result.

ENDIF.

Note: You will learn about the additions in parentheses for the WRITE

statement in a later lesson. You can omit them here.

Lesson Summary

You should now be able to:

• Define elementary data objects (simple variables)

• Use basic ABAP statements with elementary data objects

• Execute and analyze programs in debugging mode

Lesson:

97

Working with Structures

Lesson Duration: 75 Minutes

Lesson Overview

In this lesson, we will continue with the definition of structured data objects (structure variables) and their analysis using the ABAP Debugger. Also, this chapter will teach you how to use basic ABAP statements for structured data objects.

Lesson Objectives

After completing this lesson, you will be able to:

• Define structured data objects (structure variables)

• Use basic ABAP statements for structured data objects

Analyze structured data objects in debugging mode

Structure variables in the program are simply “records” in other programming languages. The advantage of ABAP is that you can use global structure types (dictionary structures) to define uniform structure variables in different programs. This should be emphasized as a strength of the ABAP language.

Business Example

You are to process your own first data structures and search your programs for semantic errors using the ABAP Debugger.

Working with Structures

Figure 64: Definition of Structures with Global Types

In ABAP, you can define structured data objects (called structure variables or simply structures). This allows you to combine values that belong together logically into one data object. Structures can be nested. This means that components can be made up of more structures or even internal tables.

In the program, structure variables are defined with the DATA statement, in the same way as elementary data objects. When you set the types, you can refer to

• a Dictionary structure

• a transparent table (that is then used as a structure type) or

• a structure type that is locally declared in the program

.

The following graphic shows the definition of a structure variable using a locally declared structure type.

Figure 65: Defining Structures with Local Types

You can use the TYPES statement to define local structure types. Here the components are enclosed by

BEGIN OF structure_type_name,

... ,

END OF structure_type_name.

. You can assign any type you want to each component by using the TYPE addition. For more details, refer to the keyword documentation for the TYPES statement.

You define the data object itself in the usual way.

If necessary, you can also define a structured data object directly. To do so, all you have to do is replace the leading key word TYPES with DATA.

DATA: BEGIN OF structure_name,

... ,

END OF structure_name.

Figure 66: Access to Structure Components

Components of a structure are always addressed using a hyphen:

structure_name-component_name.

For this reason, you should not use hyphens in names.

Figure 67: Copying Structure Components with the Same Name

The MOVE-CORRESPONDING statement copies the contents of the source structure to the target structure one component at a time. Here, only those components are considered that are available under the same name in both the source and the target structure. All other components of the structures remain unchanged.

The individual value assignments can each be executed using MOVE.

Figure 68: Structures in Debugging Mode

You can trace the field contents of a structure in the Debugger by first entering the structure name in the Field Names area or copying it from the source

code by double-clicking it. You get the component display of the structure by double-clicking the structure name in the Field Names area.

Using this exercise, make it clear that the Debugger can also be used for semantic operations in a program whose functions are not yet known.

103 Exercise 6: Working with Structures

Exercise Duration: 30 Minutes

Exercise Objectives

After completing this exercise, you will be able to:

• Use the ABAP Debugger to trace the data flow and understand the connections between processing blocks.

• Use the ABAP statement MOVE-CORRESPONDING to assign values between structures.

Business Example

You have to examine a specified ABAP program to ascertain when and how specific data is transported between certain structured data objects.

System Data

System: Will be assigned Client: Will be assigned User ID: Will be assigned Password: Will be assigned Set up instructions:

1. No special instructions required when using a standard training system

Task 1:

Execute a program in debugging mode

1. Start the program SAPBC400WBS_GETTING_STARTED. On the selection screen, enter LH in the Airline field. In the command field, enter

/h and then choose Enter. Choose F8 to run the program. You are now