Beruflich Dokumente
Kultur Dokumente
Lesson 2
Lesson Objectives
Transparent Tables
Table Definition
Displaying Domains
Structures
Creating Structures
Data Objects
Assigning Values
Calculating Values
Sub-fields
Calculating Dates
Input Parameters
Elementary Types
Field Strings
Type Conversion
Summary
Summary
Summary
Quick Check
Quick Check
Quick Check
Quick Check
Slide
1 of
47
Lesson Purpose
The purpose of this lesson is to examine and describe the use of data in ABAP/4
programs including the relationship to obtaining data from tables in the ABAP/4
Dictionary.
In learning to write ABAP/4 programs you need to learn about obtaining data
from tables in the ABAP/4 Dictionary including how the data are defined as fields
in the Dictionary. ABAP/4 has a number of different data types that are used with
the data manipulated in an ABAP/4 program.
Slide
2 of
47
Lesson Topics
ABAP/4 Dictionary
Dictionary Objects
Table Definitions
• Table Fields
• Data Elements
• Domains
Structures
Data Type
• Predefined
• User-defined
Calculations
• Arithmetic
• Date
Input Parameters
Slide
3 of
47
Lesson Objectives
Upon completion of this lesson, you should be able to:
• Describe the ABAP/4 Dictionary and the immediate effect of changes to ABAP/4
programs stored in the Dictionary
• Describe the basic Dictionary objects including a table, table field, data element,
and domain
• Describe a transparent table including its use in ABAP/4 programming and its
creation
• Describe the use of structures in an ABAP/4 program including their creation
• List the numeric and alpha-numeric predefined data types that are part of ABAP/4
data
• Describe arithmetic and date calculations in ABAP/4 including the arithmetic
operators and their syntax in the COMPUTE statement
Slide
4 of
47
• All data entered in the ABAP/4 Dictionary is available throughout the SAP R/3
System.
• Changes take effect in all relevant system components via the activation
mechanism in R/3.
• Via the Repository Information System, the Dictionary can be analyzed from
many different angles of inquiry.
• Foreign key relations, used in linking data in different tables, are stored in the data
dictionary.
Slide
5 of
47
• This ACTIVE workbench is integrated into both the development and runtime
environment.
• The basis for this is the interpretive nature of the R/3 Systems. The interpreter
does not operate directly on the original SOURCE code of an ABAP/4 program or
screen, but interprets a generated, internal representation, the GENERATED
code.
• When changes are made in the ABAP/4 Dictionary, automatic post-generation of
this internal representation guarantees that the interpreter is always working with
the latest version of the program.
• The ABAP/4 Dictionary enables you to develop and maintain large program
systems where many developers work together because it allows everyone to
access and use correct, consistent information.
Slide
6 of
47
Objects in the ABAP/4 Dictionary resided on three levels that support their re-usability.
These levels are:
2. Data elements
3. Domains
• The basic data definition objects in the ABAP/4 Dictionary are tables, domains
and data elements. Domains describe the technical attributes of table fields (e.g.
field type, field length), while data elements contain the semantic definition (e.g.
short description).
• Table fields are not independent objects and can only be maintained within tables.
The table field requires the existence of a referenced data element.
• A data element requires the existence of a referenced domain.
• Domains can be defined without further reference to other Dictionary objects.
Slide
7 of
47
In the ABAP/4 Dictionary, two types of objects are used for data definition purposes.
These are technical domains (known as domains in the R/3 System) and semantic
domains (known as data elements in the R/3 System).
• The domain is the central object used to describe the attributes of a business
object. It describes a field’s value range which is defined by specifying formal
attributes such as external format and length and by specifying fixed values or a
value table.
• The data element is the semantic object. It describes precisely the purpose of a
domain in a particular business setting for the fields which depend on it.
• For example, the table fields FORCURAM (table SBOOK) and PRICE (table
SFLIGHT) belong to the same domain S_PRICE. To distinguish their actual
business application, the field FORCURAM uses the data element S_F_CUR_PR
and the field PRICE uses the data element S_PRICE. However, both fields belong
to the same domain because they are currency fields and thus have similar
technical attributes.
• Data elements and domains are used in SAP to insure that fields with equivalent
forms and semantics are CONSISTENT.
Slide
8 of
47
Transparent Tables
Transparent tables provide a logical view of the data in the ABAP/4 Dictionary that is
independent of the table's physical storage in the database management system (DBMS)
such as Oracle. When it has been activated in the ABAP/4 Dictionary, a transparent table
is automatically created in the database. This process translates the database-independent
description of the table in the ABAP/4 Dictionary into the language of the database
system being used.
• Transparent tables are a representation of the way SAP R/3 interacts with the
DBMS that actually stores the data, such as Oracle. This is just the manner in
which data is made available to an ABAP/4 program by the R/3 Basis System and
is NOT a user-defined or controlled specification.
• The database table has the same name as the table in the ABAP/4 Dictionary. The
fields also have the same names in both the database and in the ABAP/4
Dictionary. The data types in the ABAP/4 Dictionary are converted to the
corresponding data types of the database system.
• Beginning with Release 3.0, the sequence of fields in the ABAP/4 Dictionary can
vary from the sequence of fields in the database. This allows you to insert new
fields without having to convert the table by performing a physical reorganization.
When adding new fields, the adjustment is made by changing the database catalog
(ALTER TABLE). A new field is appended to the database table, regardless of its
position in the ABAP/4 Dictionary.
Slide
9 of
47
Many of the example programs and exercises for the ABAP/4 Programming lessons
relate to the SAP flight data model. This is contained in the development class SAB4.
The following tables from this model are used with these lessons:
A data model specifies tables and their relationships for the data used with the SAP R/3
System. A graphical data model helps you visualize the tables and their mutual
dependencies. The two key elements of the graphical data model are small boxes (called
entity types) representing the tables and arrows to show relationships between these
tables. A data model is based on the ABAP/4 Dicitionary so changes to a table definition
are automatically reflected in the model. You can double-click an entity to drill down
from the data model to the underlying table definition in the Dictionary.
A data model can be displayed in either the Data Browser or graphically. You may
explore the data model from the SAB4 development class that includes the SFLIGHT
table in the Data Browser (Standard View) or the graphic Data Modeler (Display Mode)
by examining these additional screens:
A list of the fields that define the content of a table can be displayed. The following
description includes the steps for displaying a table definition starting from the ABAP/4
Development Workbench screen.
1. Click the ABAP/4 Dictionary button on the Application toolbar to display the
Dictionary: Initial Screen.
2. Type the table name in the Object name textbox, e.g. SBOOK.
3. If necessary, click the Tables option button in the Dictionary objects section to
select that option.
4. Click the Display button in the Dictionary objects section to display the
Dictionary: Table/Structure: Display Fields screen containing the table definition.
If necessary, you may need to scroll down the Initial Screen to see the Display
button in the Dictionary objects section.
Slide
11 of
47
Table Definition
You can double-click a data element name to navigate to the definition of that data
element. That is, you “drill-down” to the data element name from the table definition.
1. Double-click the desired data element name in the Data elem. column, e.g.
S_CARR_ID. The Dictionary: Display Data Element screen displays.
Slide
12 of
47
The Dictionary: Display Data Element screen includes the Short text used with the
selected data element to describe that data element. On this screen, the data type indicates
how the data would be displayed on output from the table. The domain attributes can be
displayed from the Display Data Element screen using drill down.
1. Double-click the value in the Domain name textbox, e.g. S_CARR_ID. The
Dictionary: Display Domain screen appears with the domain definition.
Slide
13 of
47
Displaying Domains
The Dictionary: Display Domain screen includes the Format section that is used when
specifying these attributes. Although you can view this same information from the
Display Data Element screen, these attributes can be changed from the Domain screen,
which is indicated by the textboxes in the Format section. Of course, you must have
appropriate authorization to make any changes to the Domain.
Slide
14 of
47
To define a table, you go into the Object Browser and proceed as follows:
• Under a defined development class, click the Display button to display the
development object list for the specified development class. Select the
development class by positioning the cursor on the development class name and
click the Create icon on the application tool bar.
• A pop-up window will be displayed with the classifications of development
objects. Click the Dictionary objects radio button to select this classification.
• On the Dictionary objects screen, click Table and enter the table name.
• On the next screen, you can enter the field names for your table and specify the
name of an existing data element (or define a new one) which points to a domain.
Slide
15 of
47
Structures
Besides defining tables stored in the database, you can also define the structure of data
which occurs when performing calculations in programs, or when passing data between
programs with a global definition in the ABAP/4 Dictionary. This kind of definition is
known as a structure. That is, structures define data that is transferred between programs
without storing it it a database table.
Slide
16 of
47
Creating Structures
To define a structure, you go into the Object Browser and proceed as follows:
• Under a defined development class, click the Display button to display the
development object list for the specified development class. Select the
development class by positioning the cursor on the development class name and
click the Create icon on the Application tool bar.
• A pop-up window displays with the classifications of development objects. Click
the Dictionary objects radio button to select this classification.
• On the Dictionary objects screen, click Structure.
• On the next screen, you can enter the field names of your structure and specify the
name of an existing data element (or define a new one) which points to a domain.
When checked and found to have no errors, the structure is saved and activated, and then
it is ready for use.
Slide
17 of
47
Database (DB) views can be defined from the SAP R/3 System. They provide users with
a virtual table or a logical user view of the data in one or more database tables.
Data Types
• There are eight predefined data types for use by the ABAP/4 language.
Slide
19 of
47
The eight pre-defined data types in ABAP/4 are specified by a letter which indicate the
type.
• The numeric data types P, I and F have the following properties and value ranges:
property
Type range suitable for
value
I integer -231 to +231 counters, quantities, indexes, time
periods
P number 2 characters amounts of money, lengths,
with per byte weights
decimal
places
F floating -2.2E-308 to calculation in a very large value
point +1.8E308 range
•
• Calculations with number of type I are the most economical, followed by type F
and then type P. You should note, however, that approximation can cause errors
with type F numbers. It is particularly inadvisable to compare two floating point
type numbers for equality. You should instead check whether the difference
between the two falls within an acceptable tolerance. You should only use
floating point number for mathematical problems where you can accept
approximation errors. For business problems, you should normally use type P.
• Packed numbers are the best choice if you have large numbers, or if decimals are
involved in your calculations.
• In type P numbers, two digits are stored in each byte. The last half byte is used for
the plus or minus sign.
The format of data fields on the output screen depends on their data
type.
The numeric data types F, I, and P are right-justified and padded with
blanks on the left. If there is sufficient space, thousands separators are
also output. If a type P field contains decimal places, the default output
length is increased by one.
Note
With the data type D, the internal format of a date differs from
its output format. When you use the WRITE statement for
outputting data, the system automatically outputs dates of type
D in the format specified in the user's master record (e.g.
DD/MM/YYYY or MM/DD/YYYY).
PROGRAM ZA01TEST.
DATA NUMBER TYPE P VALUE '-1234567.89' DECIMALS
2.
WRITE: 'Number', NUMBER, 'is packed'.
The field NUMBER has a total length of 13, i.e. 9 digits (including the
decimal point), the leading minus sign, and two commas as separators.
The output length of the NUMBER field is 2*8+1=17 because the field
length of a type P field is 8. The superfluous positions are filled with
four blanks. This means that there are five blanks between the literal
'Number' and the number itself.
Slide
20 of
47
Data Objects
• While the value of variable data objects can be changed in the program, the value
of fixed data objects cannot be changed at runtime.
• You can differentiate between literals and constants in fixed data objects. Literals
are unnamed, constants are named data objects.
Slide
21 of
47
You use the DATA statement to declare data objects in your ABAP/4 programs.
The additions for the DATA statement are the same as those for the TYPES
statement. In exactly the same way as with the TYPES statement, you can use
TYPE to refer to a predefined or user-defined data type or
LIKE to refer to the type of a data object within the program or an
ABAP/4 Dictionary object.
The LIKE addition is specified so you can use the attributes from an existing field
defined in the data dictionary instead of defining the variable attributes internally
in the program.
Note that you can use the TYPE and LIKE additions for any data object
declarations.
Slide
22 of
47
You can specify a length for predefined data types P, N, C and X. You enter this in
parenthesis following the data object name.
• If there is no length specified, the standard length for the data type applies.
• For data type P you can specify the number of decimal places (up to a maximum
of 14) using the DECIMALS addition.
• If you do not specify a data type, the default type C will apply to the field.
Slide
23 of
47
You use the CLEAR statement to reset any variable data object to the initial value
appropriate to its type.
• Each elementary field is initialized with a value appropriate to its type. You can
set an initial value for an elementary field yourself using the VALUES extension
of the DATA statement. Only a fixed data object can follow the VALUES
extension (a literal or a constant).
Slide
24 of
47
Assigning Values
Value assignment from one data object to another data object can be accomplished in the
following ways:
Or
• < object2> = < object1>.
Calculating Values
Wrong: A = (B+EXP(C))*E/SIN(3-G).
Slide
26 of
47
Sub-fields
You can address and change sub-areas of an elementary field by specifying the offset and
length of the sub-string. When an offset is not included, an offset of zero is implied and
the sub-field begins with the first character of field.
In ABAP/4, you can specify offset values for elementary data objects in all statements
which process these data objects. To do so, specify the name of a data object in a
statement as follows:
<f>[+<o>][(<l>)]
The operation of the statement is performed for the part of the field <f> that begins at
position <o>+1 (that is the first position immediately to the right of position <o>) and has
a length of <l>.
If the length <l> is not specified, the field is processed for all positions between <o> and
the end of the field.
• With some statements, the offset and length details may be given as variables.
• The plus sign (+) must NOT be preceded or followed by any spaces when
specifying a sub-field.
Slide
27 of
47
Calculating Dates
Date field values may be converted to numeric field values, and numeric field values may
be converted to date field values.
• If a date field is converted to a numeric field, the ABAP/4 system calculates the
number of days since 01/01/0001.
NOTE: This use of a four digit year value, makes the R/3 System “Year 2000”
compliant.
Input Parameters
• When you use the PARAMETERS statement, you can use the TYPE and LIKE
additions as you would when using the DATA statement.
• As you would use VALUE with DATA statements to assign an initial value, you
can use the addition DEFAULT with the PARAMETERS statement to set a
default value for the field. This value can be a literal, a constant, or a system field
which takes its value from the system when the report is processed (e.g. SY-
DATUM).
• Use the OBLIGATORY addition to cause a question mark (?) to initially appear
in the PARAMETERS textbox. This forces a user to enter a value on the selection
screen. However, R/3 requires the user to delete the question mark when entering
the desired, required value.
Slide
29 of
47
The names of the predefined data types are fixed. The names of the user-defined data
types are defined by the programmer in the program.
The TYPES statement does NOT create a new data object or variable, it specifies a new
type that can be used in creating a data object or variable.
Slide
30 of
47
• User-defined elementary data types make your programs easier to read and
maintain by giving them descriptive names that are easier to understand and more
recognizable.
• The TYPE statement never allocates data space in memory, whereas the DATA
statement always does.
• Elementary data types cannot be included in further components. Structured data
types, on the other hand, are made up freely of elementary and structured data
types.
• In structured data types there is a difference between field string types and table
types:
o Field string types (known as structures or records in other terminology)
can be made up of components of any type.
o Table types (known as arrays in other terminology) can be made up of
lines of any type.
• Field string types and table types at the highest level can themselves contain
further field string types and table types.
Slide
31 of
47
You can declare user defined data types in your ABAP/4 programs using the TYPES
statement.
• In doing so you can refer to:
o pre-defined or user defined data types using TYPE or
o the type of data objects within the program or ABAP/4 Dictionary objects
using LIKE.
• Note that you can use the additions TYPE and LIKE for any type declarations.
Slide
32 of
47
Elementary Types
You can specify a length for data types P, N, C and X. You enter this in parenthesis
following the data type name.
• If there is no length specified, the standard length for the data type applies.
• For data type P you can specify the number of decimal places (up to a maximum
of 14) using the DECIMALS addition.
• If you do not specify a data type, the default type C will apply to the field.
Slide
33 of
47
You can define field string types using the syntax TYPES: BEGIN OF <type>,..., END
OF <type>. You define the field string components with length and any type as you
would any other data object.
Slide
34 of
47
You can define data types in a type group in the ABAP/4 Dictionary instead of defining
them within an ABAP/4 program.
• The type group name in the ABAP/4 Dictionary has a maximum of 5 characters.
Type names within type group <typepool> must begin with <typepool> followed
by an underscore.
• The types in a type group must be declared in ABAP/4 programs with the TYPE-
POOLS command.
Slide
35 of
47
Field Strings
You define field strings with the syntax DATA: BEGIN OF <field string>, ... , END OF
<field string>
• Of course, you can also refer to a field string type using TYPE.
• You address the individual fields with the name of the field string followed by the
field name.
• Table work areas declared with the TABLES statements are field strings. Thus the
statement TABLES <dbtab> is the same as the statement DATA <dbtab> LIKE
<dbtab>. However, the TABLES statement also makes the database table known
in the ABAP/4 program as well. This is why a SELECT statement without a
preceding TABLES statement leads to a syntax error.
Slide
36 of
47
You define constants using the ABAP/4 keyword CONSTANTS. The VALUE addition
is required for constants. It defines their value.
• ABAP/4 recognizes two types of literals: number literals and text literals. The
latter is always enclosed in apostrophes or inverted commas (‘).
• Whole numbers (with preceding minus sign if they are negative) are stored as
number literals with either type I (up to and including nine digits) or type P (ten or
more digits).
• All other literals (character, numbers with decimal places, floating point numbers)
are stored as text literals with data type C. The ABAP/4 processor carries out a
type conversion if necessary (see the type conversion slide).
• If you want to include an apostrophe or inverted comma (‘) in a text literal, you
must enter it twice.
Slide
37 of
47
• In a subsequent lesson, you will learn about the following declarative statement:
Statement Action
SELECT-OPTIONS Definition of selection options
• You can display a comprehensive overview of the declarative statements in
ABAP/4 by pressing the Editor pushbutton and then choosing ABAP/4
Overview Overview of the ABAP/4 programming language
Classification of keywords by type.
Type Conversion
If you assign data objects of different types to one another, ABAP/4 carries out a type
conversion as long as a conversion rule has been defined for the types concerned.
• Type C fields are saved left justified. When you use convert to type C fields, the
field is filled up with blanks if it is too short, and truncated if it is too long (see
examples 1 and 2 above).
• When you convert a type C field to a type P field, only digits, a plus or minus sign
and a decimal point are permitted (see example 3 above).
• When you convert a packed field to a type C field, the leading zeros are converted
into spaces (see example 4 above).
Slide
40 of
47
• In each of the above cases, the ABAP/4 processor converts the field strings into
type C fields.
• Internal tables can only be converted into other internal tables. The appropriate
line types are then converted.