Студопедия
Случайная страница | ТОМ-1 | ТОМ-2 | ТОМ-3
АрхитектураБиологияГеографияДругоеИностранные языки
ИнформатикаИсторияКультураЛитератураМатематика
МедицинаМеханикаОбразованиеОхрана трудаПедагогика
ПолитикаПравоПрограммированиеПсихологияРелигия
СоциологияСпортСтроительствоФизикаФилософия
ФинансыХимияЭкологияЭкономикаЭлектроника

Pa_int1 TYPE i, pa_op(1) TYPE c, pa_int2 TYPE i.

ENDLOOP. ENDIF. | Wa_flight-seatsocc / wa_flight-seatsmax. | INSERT wa_flight INTO TABLE it_flight. | ID ’ACTVT’ FIELD ’02’. | WRITE: / ’Authority-Check Error’(001). ENDCASE. | Wa-percentage, ’%’. | Wa_sbook-loccurkey. | SELECT-OPTIONSname FORdata_object. | MESSAGE e045(bc400) WITH pa_car. ENDIF. | CALL SCREEN 100. |


DATA wa_flight TYPE sflight.

 

 

SELECT * FROM sflight INTO wa_flight.

 

 

NEW-LINE. WRITE:

Wa_flight-carrid, wa_flight-connid, wa_flight-fldate, wa_flight-seatsocc, wa_flight-seatsmax.

 

ENDSELECT.


 

 

49 Exercise 3: Creating Transactions

 

Exercise Duration: 10 Minutes

 

 

Exercise Objectives

 

After completing this exercise, you will be able to:

• Create transactions

• Define transaction codes as personal favorites

 

 

Business Example

 

The users of your company are to be able to start their ABAP programs as transactions or define them as personal favorites.

 

System Data

 

System: Will be assigned Client: Will be assigned User ID: Will be assigned Password: Will be assigned

Set up instructions: No special instructions when using a standard training system

 

Task 1:

 

Create transaction

 

1. Create transaction code ZBC400_##_GS for the executable program

ZBC400_##_GS_LIST.

 

Hint: In the transaction definition, select Program and Selection

Screen (Report Transaction) as the start object.

 

2. Execute your program by entering the new transaction code in the command field.

 

Task 2:

 

Define favorites

 

1. Add transaction code ZBC400_##_GS to your personal favorites.

 

2. Execute your program by double-clicking the new favorite entry.


 

Solution 3: Creating Transactions

 

Task 1:

 

Create transaction

 

1. Create transaction code ZBC400_##_GS for the executable program

ZBC400_##_GS_LIST.

 

Hint: In the transaction definition, select Program and Selection

Screen (Report Transaction) as the start object.

 

a) Carry out this step as described in the training material.

 

2. Execute your program by entering the new transaction code in the command field.

 

a) Carry out this step as usual.

 

Task 2:

 

Define favorites

 

1. Add transaction code ZBC400_##_GS to your personal favorites. a) Carry out this step as described in the training material.

2. Execute your program by double-clicking the new favorite entry. a) Carry out this step as usual.


 

LessonSummary

You should now be able to:

• Name and use the utilities for orderly software development

• Create packages

• Create programs

• Create transactions


 

UnitSummary

You should now be able to:

• Describe the structure of the Repository

• Name and use the search tools of the Repository

• Use the Object Navigator for displaying Repository objects

• Name and use the utilities for orderly software development

• Create packages

• Create programs

• Create transactions

 

Related Information

 

... Refer to the online documentation for each tool.


 

Unit 3

 

53 IntroductiontotheABAPDictionary

 

 

See the introductory instructors’ note in the lesson

 

Unit Overview

 

Refer to the lesson objectives for an overview of this unit.

 

 

UnitObjectives

After completing this unit, you will be able to:

 

• Explain the purpose and the benefits of using a data model in application development

• Describe the SAP flight data model

• Be able to describe the meaning and structure of data elements and domains

• Describe the meaning and the structure of a transparent table

• Describe the meaning and the structure of a structure

• Use the mentioned Dictionary elements in your ABAP programs

 

 

Unit Contents

 

Lesson: Data Modeling and Descriptive Elements in the ABAP Dictionary

...................................................................................... 62

Exercise 4: Using Global Structures for Data Objects and Dialogs... 73


 


Lesson:

54


Data Modeling and Descriptive Elements in the ABAP Dictionary

Lesson Duration: 75 Minutes

 

 

Lesson Overview

 

In this lesson you will get an overview of data modeling, which has to be done before the application development. Furthermore, you will learn about the basic descriptive elements in the ABAP Dictionary You will also find out when and why it is appropriate to use data types (data descriptions) from the ABAP Dictionary


 

 

 
Lesson Objectives

 

After completing this lesson, you will be able to:

 

• Explain the purpose and the benefits of using a data model in application development

• Describe the SAP flight data model

• Be able to describe the meaning and structure of data elements and domains

• Describe the meaning and the structure of a transparent table

• Describe the meaning and the structure of a structure

• Use the mentioned Dictionary elements in your ABAP programs

 

 

 
It is important for the participants to learn to use the ABAP Dictionary as a maintenance and management tool that effectively supports their daily work.

 

 

Business Example

 

When you define data objects in your ABAP program, you should use the advantages of the ABAP Dictionary.


 

Data Modeling

 

 

 

 

Figure 37: Data Modeling

 

In the development of business application software, parts of the real world must be represented in data form. A business unit then represents an entity. These entities are in relationships with each other, which are fixed in the underlying data model. We also refer to an Entity Relationship Model (ERM).

 

You use this data model as the basis for implementing appropriate table definitions (transparent tables) including their relationships with each other in the ABAP Dictionary.

 

By activating the table definitions, corresponding database tables are automatically created in the database. The actual application data is entered into those tables later on.


 

 

 

 
Figure 38: Flight Data Model for ABAP Training Courses

 

ABAP training courses, online documentation, and ABAP keyword documentation all use the same flight data model as an example. The Repository objects for the flight data model are in the package SAPBC_DATAMODEL.

 

In the context of this course it suffices to show a simple excerpt from this data model: If a customer of a travel agency wants to go from one place to another, then he or she requests the travel agency to find out:

 

• What connection offers me the best and most direct flight?

• At what times are flights offered on the date that I want to travel?

• How can I optimize the conditions under which I am traveling to find the best solution; that is, what is the cheapest flight, the fastest connection, the connection that gets me there closest to the time I want to arrive?

 

A travel agency's point of view is a bit different: In the data model that is designed for managing the required data, the data is stored by technical criteria in tables in a central database. The amount of data stored far exceeds the demands

of a customer.

 

You must be able to compile the data to suit the demands of the customer using application programs.


 

 

 
Figure 39: Relational Data Model

 

The flight data model contains entities for all business information that is logically connected, such as:

 

• Cities

• Airports

• Airlines

• Flight routes

• Flights

•...

 

These entities all relate to each other in certain ways:

 

• Each flight schedule contains exactly one airline, one departure airport, and one destination airport.

• Each bookable flight always belongs to exactly one existing flight schedule.

• Assignments can be set between cities and nearby airports.

 

You can manage all necessary data, without redundancies, using these relationships. At the same time, the travel agency is able to obtain all data requested by the customer.


 

 

 
Figure 40: Converting Using Transparent Tables

 

For each entity fixed in the data model, the developer creates a transparent table in the ABAP Dictionary. At first this is only a platform-independent description of a database table, not the actual database table. However, when the transparent table is activated, a table with the same name is automatically created in the database.

 

A transparent table contains different fields (columns) to allow you to store and manage data records in a structured way. You have to declare table fields as key fields when their content is to be used for the clear identification of data records within the database table. The key of a table (table key) consists of key fields. This is also called a primary key. Data records of the same table have to be unique with regard to the primary key values. The key value of a data record

is thus a unique ID within the table.

 

 

Descriptive Elements in the ABAP Dictionary

 

Before we deal with transparent tables, we have to explain two additional dictionary terms. Data element and domain.


 

 

 
Figure 41: Data Element and Domain.

 

A data element is a total description of a field. This includes the semantic as well as the technical field attributes.

 

The semantic field attributes include the field documentation and the field labels. They are stored directly in the data element definition. In contrast, the technical field attributes such as data type and field length (with regards to reusability)

are usually not specified in the actual data element but by means of a reference to a domain.

 

Data elements can be used for defining program-internal variables or for describing fields of transparent tables.

 

 

 
Show the depicted data element including the domain in the Dictionary as an example.


 

 

 
Figure 42: Technical Structure of a Transparent Table

 

In the ABAP Dictionary, a transparent table is an implemented description of the corresponding database table that contains the actual application data.

 

 

 

 

Figure 43: Transparent Tables in the ABAP Dictionary

 

The fields of the transparent table form the identically-named columns of the corresponding database table.


 

You normally use a data element to type a field of a transparent table. By reusing the data element in the field definition of various tables, you can ensure that the fields are consistent across tables.

 

The Key indicator marks a field as a key field.

 

 

 
If you have time, create a transparent table in the DDIC with, for example, CARRID (data element S_CARR_ID) as a key field and SEATSMAX (data element S_SEATSMAX) as an additional non-key field. Point out that the structure of a database table is maintained using the DDIC and that this is automatically converted in the database, without having to program Native SQL statements. Maintain the technical settings, activate the transparent table, and make some entries using SE16. Make it clear that everything is known, system-wide, in the DDIC.

 

 

 

 
Figure 44: Structures in the ABAP Dictionary

 

Usually, a structure in the ABAP Dictionary is used to centrally describe structure variables that are to contain the fields of various tables. You can then use these dictionary structures in the ABAP program to define data objects (concrete structure variables) that either serve as temporary data storage in the program

or as an interface for the field transport between the screen and ABAP program.

(Will we provide more information on this in the next chapter.)

 

The definition of a dictionary structure is almost identical to that of a transparent table. The only difference is that declaring key fields and specifying technical settings does not make sense for structures and is thus not required.


 

With structures however, we refer to component and component type as opposed to field and data element, because, in contrast to transparent tables, it is possible

to have a structure as the component of another structure. Such structures with included substructures as components are called complex structures. In contrast, structures with simple components are called flat.

 

 

Show the depicted structure in the Dictionary as an example.

 

 

 

 

Figure 45: Using Dictionary Elements to Define Data Objects Within the

Program


 

The definitions in the above graphic have the following meaning:

 

DATA mycarrid TYPE s_carr_id.

 

Returns a data object (variable) of the type specified in the data element

s_carr_id.

 

DATA myconnid TYPE sbc400focc-connid.

 

Returns a data object (variable) which has the same type as the structure field

sbc400focc-connid.

 

PARAMETERS pa_carr TYPE spfli-carrid.

 

Returns an input field on the selection screen as well as a variable which has the same type as the table field spfli-carrid.

 

DATA wa_focc TYPE sbc400focc.

 

Returns a structure variable which has the same type as the dictionary structure sbc400focc.

 

DATA wa_spfli TYPE spfli.

 

Returns a structure variable which has the same type as a line of the table

spfli.

 

 

 

 

Figure 46: PARAMETERS Definition using a Dictionary Element

 

If you use a data element, structure component or a field of a transparent table to define an input field on the selection screen (PARAMETERS statement) then,

in addition to the technical properties, you can use the semantic properties of

the corresponding data element: When the user presses the F1 or F4 button on


 

the selection screen, a documentation dialog or input help dialog is generated automatically. It takes the necessary information from the ABAP Dictionary (data element documentation or attached search help).

 

 

 
Enhance your SELECT program to include a PARAMETERS statement for the airline. Enhance the SELECT to include the WHERE condition for the defined parameters. This serves as a preview for the SELECT unit later on. Using F1 and F4 on the selection screen, demonstrate why it is useful to refer to DDIC types. Alternatively, you can define your PARAMETERS using TYPE c and length 3

in order to make the difference clear.

 

Mention that you work with F1 and F4 help on dynamic-program screens in the same way as on selection screens.


 

 

65 Exercise 4: Using Global Structures for

Data Objects and Dialogs

 

Exercise Duration: 30 Minutes

 

 

Exercise Objectives

 

After completing this exercise, you will be able to:

• Establish the technical names of data types (= descriptions) and data objects

(= variables) that are used in user dialogs.

• Run where-used lists within an ABAP program.

 

 

Business Example

 

You have to examine a specified ABAP program to see whether global data types

(= descriptions defined in the Dictionary) are used in it, and if so, which ones.

 

Hint: The main purpose of this unit is to get information for a specified program and not its syntax. Hence you should not try to understand the entire syntax of the program. This especially applies to the statements TABLES and MOVE-CORRESPONDING. Their meaning and functionality will be discussed later on in this course.

 

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:

 

Search for program and execute it

 

1. Display the object list for package BC400 in the Object Navigator. Find the program SAPBC400WBT_GETTING_STARTED and display its object list. Throughout the exercise, make sure that you remain in display mode.

 

2. Run the program to find out how it works.

 

Continued on next page


 

Task 2:

 

Analyze selection screen

 

 

1. What information must you provide to the program on the selection screen? (Use the field help F1.)

 

 

2. What values can you enter? (Use the input help F4.)

 

 

3. What is the technical name of the input field (definition name in the program)?

Find this information in the definition in the source code and then try finding the same information in the technical information on the F1 field help. Which information there also contains the technical name of the input field?

 

 

Task 3:

 

Analyze screen

 

 

1. What is the number of the displayed screen? (For this, choose the Status

entry of the System menu on the screen.)

 

Continued on next page


 

2. Which information is output on the screen? (Use the field help F1.)

 

 

3. What are the technical names of the screen fields?

Do the fields belong to a structure with a type defined in the ABAP Dictionary? (Use the technical information on field help F1 as well as the navigation by double-clicking.)

 

 

Task 4:

 

Analyze the program source code (using the object list of the program)

 

 

1. Which data objects (variables) are defined in the program (see the object list of the program)? Where in the program are they defined?

 

 

2. Where in the program are they used? (Use the Where-Used List in the

ABAP-Editor.)

 

Continued on next page


 

3. Under which name is the input field defined on the selection screen of the program? Can you also find the name in the object list of the program?


 

Solution 4: Using Global Structures for

Data Objects and Dialogs

 

Task 1:

 

Search for program and execute it

 

1. Display the object list for package BC400 in the Object Navigator. Find the program SAPBC400WBT_GETTING_STARTED and display its object list. Throughout the exercise, make sure that you remain in display mode.

 

a) Carry out this step as usual.

 

2. Run the program to find out how it works. a) Carry out this step as usual.

 

Task 2:

 

Analyze selection screen

 

1. What information must you provide to the program on the selection screen? (Use the field help F1.)

 

Answer: Short description of an airline

 

2. What values can you enter? (Use the input help F4.)

 

Answer: With F4, a list of available, usable airline codes appears: AA, LH

and so on.

 

3. What is the technical name of the input field (definition name in the program)?

 

Find this information in the definition in the source code and then try finding the same information in the technical information on the F1 field help. Which information there also contains the technical name of the input field?

 

Answer: PA_CAR

The information on the screen field.

 

Task 3:

 

Analyze screen

 

1. What is the number of the displayed screen? (For this, choose the Status

entry of the System menu on the screen.)

 

Answer: 100

 

 

Continued on next page


 

2. Which information is output on the screen? (Use the field help F1.)

 

Answer: The short description, long name, and local currency of the requested airline.

 

3. What are the technical names of the screen fields?

 

Do the fields belong to a structure with a type defined in the ABAP Dictionary? (Use the technical information on field help F1 as well as the navigation by double-clicking.)

 

Answer: SBC400_CARRIER-CARRID and SBC400_CARRIER- CURRCODE.

Yes, these are the components of the structure SBC400_CARRIER, as visible under Field Data. You can display this by double-clicking the specified structure.

 

Task 4:

 

Analyze the program source code (using the object list of the program)

 

1. Which data objects (variables) are defined in the program (see the object list of the program)? Where in the program are they defined?

 

Answer: In the object list of the program, open the Fields node and display the corresponding statement in the program by double-clicking the appropriate variable.

 

2. Where in the program are they used? (Use the Where-Used List in the

ABAP-Editor.)

 

Answer: You can run the where-used list of a data object in the program either from the object list via the context menu of the data object in question or from the ABAP Editor after selecting the data object in question and pressing the where-used list button. This results in a list of locations found. You can navigate to the program part in question by double-clicking.

 

3. Under which name is the input field defined on the selection screen of the program? Can you also find the name in the object list of the program?

 

Answer: PA_CAR

In the object list of the program, you will find the name under the Fields node.


 

LessonSummary

You should now be able to:

• Explain the purpose and the benefits of using a data model in application development

• Describe the SAP flight data model

• Be able to describe the meaning and structure of data elements and domains

• Describe the meaning and the structure of a transparent table

• Describe the meaning and the structure of a structure

• Use the mentioned Dictionary elements in your ABAP programs


 

UnitSummary

You should now be able to:

• Explain the purpose and the benefits of using a data model in application development

• Describe the SAP flight data model

• Be able to describe the meaning and structure of data elements and domains

• Describe the meaning and the structure of a transparent table

• Describe the meaning and the structure of a structure

• Use the mentioned Dictionary elements in your ABAP programs

 

Related Information

 

... Refer to the online documentation for the ABAP Dictionary.


 

Unit 4

 

73 BasicABAPLanguageElements

 

 

See the introductory instructors’ notes in the lessons

 

Unit Overview

 

Refer to the lesson summaries for an overview of this unit.

 

 

UnitObjectives

After completing this unit, you will be able to:

 

• Define elementary data objects (simple variables)

• Use basic ABAP statements with elementary data objects

• Execute and analyze programs in debugging mode

• Define structured data objects (structure variables)

• Use basic ABAP statements for structured data objects

• Analyze structured data objects in debugging mode

• Define internal tables

• Use basic ABAP statements with internal tables

• Analyze internal tables in debugging mode

 

 

Unit Contents

 

Lesson: Working with Elementary Data Objects............................. 82

Exercise 5: Basic ABAP Statements.....................................101

Lesson: Working with Structures.............................................107

Exercise 6: Working with Structures..................................... 113

Lesson: Working with Internal Tables........................................120

Exercise 7: Working with Internal Tables................................139


 


Lesson:

74


Working with Elementary Data Objects

 

Lesson Duration: 75 Minutes

 

 

Lesson Overview

 

In this lesson you will become familiar with the difference between data types and data objects (first only the elementary ones) and you will learn how to define

and use these in a program. You will also learn some basic ABAP statements. Furthermore, you will find out how to use the ABAP Debugger for analyzing a program flow.


 

 
Lesson Objectives

 

After completing this lesson, you will be able to:

 

• Define elementary data objects (simple variables)

• Use basic ABAP statements with elementary data objects

• Execute and analyze programs in debugging mode

 

 

 
This lesson deals with basic terms and concepts that are the same in all modern programming languages. The main thing is to point out the SAP-specific aspects.

 

However, it could be that your participants' experience is less than required. In this case, you will have to proceed more slowly in this lesson.

 

The basic handling of the ABAP Debugger will be introduced here and, in the following lessons, further aspects of it will be explained.

 

Business Example

 

You are supposed to use simple variables in your programs and edit these with simple statements.

 

Furthermore, you want to find the semantic errors in your programs by using the ABAP Debugger.

 

 

Data Types and Data Objects

 

A formal variable description is called data type. In contrast, a variable concretely defined by means of a data type is called data object.

 

The following graphic shows how data types can be used:


 

 

 

 
Figure 47: Using Data Types

 

The type of a data object defines its technical (and possibly also semantic)

attributes.

 

The type of interface parameter defines the type of the value of the actual parameters that are passed when the modularization unit is called.

 

The type of an input/output field can provide further information in addition to the technical characteristics, such as the field and value input help.

 

In this lesson, you will mainly learn how to use types for defining program-internal variables.

 

Let's have a look at the ABAP standard types predefined by SAP (implemented types) first. They are divided into two groups: Complete and incomplete types.

 

The following implemented ABAP standard types are complete. That means they already contain the type-related, fixed length information:

 

Complete ABAP standard types

 

 
D

Type for date(D), format: YYYYMMDD, length 8 (fixed)

 

T

Type for time (T), format: HHMMSS, length 6 (fixed)

 

I

Type for integer (I), length 4 (fixed)


 

F

Type for floating point number (F), length 8 (fixed)

 

STRING

Type for dynamic length character string

 

XSTRING

Type for dynamic length byte sequence (HeXadecimal string)

 

The following standard types do not contain a fixed length (incomplete). With these, the length of the variable has to be specified for data object definitions.

 

Incomplete ABAP standard types

 

 
C

Type for character string (Character) for which the fixed length is to be specified

 

N

Type for numerical character string (Numerical character) for which the fixed length is to be specified

 

X

Type for byte sequence (HeXadecimal string) for which the fixed length is to be specified

 

P

Type for packed number (Packed number) for which the fixed length is to be specified.

(In the definition of a packed number, the number of decimal points may also be specified.)

 

 

For more information on predefined ABAP types, refer to the keyword documentation on the TYPES or DATA statement.

 

You can use the standard types to declare more complete or also more more complex local data types. These only exist in the program in question and hence can only be used there. This declaration happens by means of a TYPES statement.


 

 

 

 
Figure 48: Declaring Local Types

 

A data type defined in the ABAP Dictionary is called global as it can be used throughout the entire system (meaning in the entire SAP system in question).

 

 

 

 

 

Figure 49: Global Data Types in the Dictionary

 

In this lesson, we will only describe the data elements and use them as field types. The other global data types are used later in this course.

 

There are three categories of types in total: standard, local and global.


 

We now want to use these types to define variables (data objects).

 

 

 

 

Figure 50: Defining Data Objects

 

Data objects are always defined with the DATA key word. You can use an ABAP

standard type, a local type, or a global type to type a data object.

 

You can refer to an already defined data object when defining additional variables

(LIKE addition).


 

 

 

 
Figure 51: Examples of the Definition of Elementary Data Objects

 

You can use the VALUE addition to pre-assign the value of an elementary data object.

 

If the type information is missing in a variable definition, then standard type C is assumed.

 

In contrast, if the length is missing, then the appropriate default length for the

(incomplete) standard type is used.

 

The "DATA myvar." statement without type or length information thus defines a character variable with a length of 1 as the default length of type C is one.

 

You can get the default lengths of the incomplete standard types as well as other information from the keyword documentation on the TYPES or DATA statement.


 

 

 
Figure 52: Literals and Constants (Fixed Data Objects)

 

Fixed data objects have a fixed value, which is already fixed when the source text is written and cannot be changed at runtime. Literals and constants belong to

the fixed data objects.

 

You can use literals to specify fixed values in your programs. There are numeric literals (specified without quotation marks) and text literals (specified with quotation marks). The figure above shows some examples of literals.

 

You define constants using the CONSTANTS statement. Their type is defined similarly to the definition of elementary data objects. The VALUE addition is required for constants. This is how you define the value of the constants.

 

If possible, avoid literals completely when using statements. Instead, use constants. This significantly increases the ease of maintenance of your program.


 

 

 
Figure 53: Local vs. Global Data Types

 

Local data types can only be used in the program where they are defined. Global data types, in contrast, can be used throughout the entire system. Apart from that, the latter also have the following advantages:

 

• The system-wide usability of global types increases the system's consistency and their reusability reduces the amount of maintenance required.

• In the ABAP Dictionary you have the option of generating a where-used list for a global data type. The where-used list lists the Repository objects that use the data type in question.

• In addition to the technical information, global data types can also contain semantic information that corresponds to the business descriptions of the objects to be defined. They can then also be used for designing screen displays (for example, the short description on the left of the input field).

 

Local data types should be used only if used exclusively in the program where they are defined and if semantic information does not matter for the definition of the corresponding data objects.


 

Basic ABAP Statements

 

 

 

 

Figure 54: Value Assignments

 

When the program is started, the program context is loaded into a memory area of the application server and memory is made available for the data objects defined in the program. Every elementary data object is pre-assigned the type-specific initial value, except if a different value was pre-assigned using the VALUE addition.

 

You can use the MOVE statement to transfer the contents of a data object to another data object. The following two syntax variants have the same effect:

 

• MOVE var1 TO var2..

• var2 = var1..

 

If both data objects var1 and var2 are of different types, then there is a type conflict. In this case, a type conversion is carried out automatically, if a conversion rule exists. For detailed information on copying and the conversion rules, refer to the keyword documentation for the MOVE statement.

 

The CLEAR statement resets the contents of a data object to the type-specific initial value. For detailed information on the initial values for a particular type, refer to the keyword documentation on the CLEAR statement.


 

 

 
Figure 55: Calculations

 

In ABAP you can program arithmetic expressions nested to any depth. Valid operations include:

 

+ Addition

• - Subtraction

* Multiplication

/ Division

** Exponentiation

DIV Integral division without remainder

MOD Remainder after integral division

Caution: Parentheses and operators are ABAP keywords and must therefore be separated from other words by at least one space.

 

Several functions for different data types are predefined in the ABAP runtime environment. For example, the following statement provides the current length of the content of a character variable.

 

length = STRLEN(cityfrom).

 

In the case of functions, the opening parenthesis is part of the function name. The rest must again be separated by at least one space.

 

In general, the standard algebraic rules apply to the processing sequence: Expressions in parentheses come first, then powers, then multiplication/division, and finally addition/subtraction.


 

For detailed information on the available operations and functions, refer to the keyword documentation on the COMPUTE statement.

 

 

 

 

 

Figure 56: Conditional Branches

 

In ABAP you have two ways to execute different sequences of statements, depending on certain conditions:

 

• In the IF construct you can define any logical expressions as check conditions. If the condition is met, the system executes the relevant statement block. Otherwise, the condition specified in the ELSEIF branch (several are possible) is checked and so on. If none of the specified conditions are met, then the system executes the ELSE branch, if it is available. ELSEIF and ELSE branches are optional. For detailed information on formulating a logical expression refer to the keyword documentation on the IF statement.

• You can use the CASE construct to clearly distinguish cases. The content of the field specified in the CASE part is checked against the data objects listed in the WHEN branches to see whether they match. If the field contents match, the respective statement block is processed. If no comparison is successful, the system executes the OTHERS branch if it is available. Except for the first WHEN branch, all further additions are optional.


 

In both constructs the condition or match check happens sequentially from the top down. As soon as the statement block of a branch has been executed, the system immediately jumps to ENDIF or ENDCASE.

 

Hint: If you want to implement similarity checks between a field and different values, you should prefer the CASE construct to the IF statement as it is clearer and performs better.

 

 

 

 
Figure 57: Loops

 

There are four loop constructs in ABAP. In the DO and WHILE loop the system field SY-INDEX contains the number of the current loop pass. Hence, querying this system field only makes sense within a loop. In nested loops, SY-INDEX always contains the loop pass number of the loop in which it is located.

 

Unconditional/Index-Controled Loops

The statement block between DO and ENDDO is continuously executed until the loop is left using termination instructions such as EXIT. You also have the option of specifying the maximum number of loop passes; otherwise you may get an endless loop.


 

Header-Controled Loops

The statement block between WHILE and ENDWHILE is continuously executed until the specified condition is no longer met. The condition is always checked before executing the statement block.

 

Read Loops

You can use the SELECT loop to read several entries of a database table in succession. In an internal table (table variable in the program), the same read function is implemented with the LOOP loop.

 

 

 

 

 

Figure 58: Dialog Messages

 

You use the MESSAGE statement to send dialog messages to the users of your program. When you do this, you must specify the three digit message number and the message class.

 

Message number and message class clearly identify the message to be displayed. You use the message type to specify where the message is to be displayed. You can test the display behavior for using the different message types by means of the DEMO_MESSAGES demo program that is shipped in the SAP standard.

 

If the specified message contains placeholders, you can supply them with values from your program by using the WITH addition. Instead of the placeholders, the transferred values then appear in the displayed message text.

 

For further information on the syntactical alternatives to the MESSAGE statement, refer to the keyword documentation.


 

 
If you have used a WRITE in your SELECT program in the sy-subrc query to output an error message, it would now be appropriate to replace this with the MESSAGE using message 041 from the message class BC400 and with the Carrier parameter of your selection screen. Use message type i and explain that this can be improved later on using event control. Now you could introduce the “pocket calculator exercise”.

 

Working with the ABAP Debugger

 

 

 

 

Figure59:ExecutingaPrograminDebuggingMode

 

 
Here it would be appropriate to introduce the programs SAPBC400TSD_COPY_CLEAR and SAPBC400WBT_GETTING_STARTED on debugging from the BC400 package.

 

 

There are several ways to start a program in debugging mode from the Object

Navigator:

 

a) In the navigation area for the selected program, choose the context menu

Execute → Debugging.


 

b) In the editor area, select the requested program line from which you wish to debug. Choose the Set/Delete breakpoint button. Afterwards, start the program by choosing F8 or in the navigation area via the context menu Execute → Direct. (The above-described setting of a breakpoint in the editor is only possible for active source texts.)

 

 

 

 

Figure 60: Switching to Debugging Mode at Runtime

 

If you want to “debug” a certain function of a program, first start the program without the debugger and then switch to debug mode immediately before executing the function (e.g. pushbutton). There are two ways of doing this:

 

a) Choose System → Utilities → Debugging ABAP (or screen).

 

b) Enter /h in the command field in the standard toolbar and press Enter.


 

 

 
Figure 61: Debugging Mode: Single Step and Field Contents

 

In debugging mode, you can choose Single step to execute the program statement by statement.

 

You can display the contents of up to eight data objects. To do so, enter their names in the field name area or copy them by “double-clicking” on the corresponding data objects from the source code.


 

 

 
Figure 62: Debugging Mode: Breakpoints

 

You can set a breakpoint by double-clicking in front of a line of source code. You can also set a breakpoint for specific ABAP statements: Breakpoints → Breakpoint at → Statement. If you choose Continue, the program is executed up to the next breakpoint.

 

The set breakpoints are only valid for the current debugger session. However, if you Save, the breakpoints stay for you for the duration of your current SAP session.


 

 

 
Figure 63: Debugging Mode: Tracing Data Changes

 

Watchpoints are breakpoints that depend on the field content.

 

If you set a watchpoint without specifying a relational operator/comparative value on a field and choose Continue, then the program is executed until the content of the field changes.

 

However, if you specified relational operator and comparative value, then, once you choose Continue, the program is executed until the specified condition is met.

 

You can set up to 10 watchpoints and link these using a logical operator (AND

or OR).


 


 

 

91 Exercise 5: Basic ABAP Statements

 

Exercise Duration: 30 Minutes

 

 

Exercise Objectives

 

After completing this exercise, you will be able to:

• Define elementary data objects

• Assign values

• Implement conditional branching

• Perform calculations

 

 

Business Example

 

You are to create a simple ABAP program for the four basic calculation types. You must be able to enter the values and the arithmetic operator on a selection screen. Display the result in a list.

 

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:

 

Create program

 

1. Create the executable program ZBC400_##_COMPUTE without a “TOP

include”.

 

Task 2:

 

Define input parameters (implicit definition of the selection screen).

 

1. Define the input parameters for two integer values (name suggestion:

pa_int1, pa_int2) and an arithmetic operator (name suggestion: pa_op).

 

 

Continued on next page


 

Task 3:

 

Execute calculations and set up the list output.

 

1. Additionally, define an elementary data object for the result; type: Packed number with two decimal places (name suggestion: result).

 

2. Execute the calculation dependent on the specified arithmetic operator.

 


Дата добавления: 2015-11-16; просмотров: 53 | Нарушение авторских прав


<== предыдущая страница | следующая страница ==>
Обо мне как руководителе и танцоре.| DATA result TYPE p DECIMALS 2.

mybiblioteka.su - 2015-2024 год. (0.286 сек.)