ABAP Dictionary Objects in Eclipse
ABAP Dictionary Objects in Eclipse
Eclipse
Table of Contents
Table of Contents 2
Overview 2
2
Overview
In the ABAP Dictionary Objects in Eclipse we are going to 👍
If your AS ABAP backend system has Release 7.50 or higher, you can use the new Eclipse
3
To create a new data element, open the New ABAP Repository Object dialog box
and choose Dictionary → Data Element. In the dialog box that follows, enter a
package for the new data element and its name, remembering to observe the
relevant naming conventions.
When you choose Next, you are prompted for a transport request (unless you are creating
a local object).
On the next screen, you fill out the details of the data element. The category is usually a
domain, but could also be a built-in ABAP Dictionary type, a reference to a Dictionary type,
or a reference to an object type (class or interface). Enter the name of a domain (value help
is available using Ctrl + Space) or, if you want to create a new domain, click on the label
Type Name. Enter the field labels as you would in the normal SAP GUI editor.
In the Additional Properties section you can assign a search help and a Set/Get Parameter
to the data element. Once again, you can create new objects by clicking the corresponding
field label.
4
1. Create a new data element to represent an airline code with the name
ZBC404_##_CARRIER, where ## is your group number. Assign the data element to your
package ZBC404_##.
4. Expand the Additional Propertiespanel and assign the search help H_SCARR to the data
element. Link the data element with the parameter CARRID of the search help (you can use
Solution
1. Create a new data element to represent an airline code with the name
ZBC404_##_CARRIER, where ## is your group number. Assign the data element to your
package ZBC404_##.
c) Enter your package ZBC404_## and the name of the data element
5
a) Enter a short, medium, long and heading field label.
4. Expand the Additional Properties panel and assign the search help H_SCARR to the data
element. Link the data element with the parameter CARRID of the search help (you can use
b) Enter H_SCARR in the Name field of the search help group box and CARRID in the
Parameter field.
declaring structures.
6
If your AS ABAP backend system has Release 7.50 or higher, you can create and edit
structures using a source-code based editor in Eclipse rather than the form-based editor in
the SAP GUI. This editor provides you with all of the features of the SAP GUI editor, allowing
you to create components typed according to data elements, built-in ABAP Dictionary types
such as CHAR, DEC, or NUMC, reference types, other structures, and internal tables. You
can also define foreign-key checks and assign search helps to structure components.
For semantic information about the structure or its components, such as its enhancement
category of the structure, or the semantic description of a foreign key relationship there is
The structure editor in ADT includes code completion which, as always, you invoke with the
The figure, Syntax For Creating Structures, shows the default code that ADT inserts into the
structure editor when you create a new structure. The definition of the structure begins
with the define type keyword. You define the components of the structure within the
braces. The structure definition contains both definitions and annotations. Definitions
7
describe a component and its type, annotations provide additional semantic information
You describe the type of a component using the form name : type. Annotations begin with
the @ symbol. If they relate to the entire structure, you place them before the structure
definition. If you need to create an annotation relating to a single component, you place it
before the component definition. Each component definition ends with a semicolon.
The two annotations belonging to the structure are its label, which corresponds to the
short text of the structure, and its enhancement category. This can have one of the
following values:
● #NOT_EXTENSIBLE
● #EXTENSIBLE_CHARACTER
● #EXTENSIBLE_CHARACTER_NUMERIC
● #EXTENSIBLE_ANY
● Elementary type
● Reference type
8
● Structured type
For structures and internal tables, you enter the name of an existing structured or internal
table type from the ABAP Dictionary. A reference type can refer to either an object type
To define the type of an elementary component, specify either the name of a data element
or a native ABAP Dictionary type. To specify an ABAP Dictionary type, use the namespace #
+abap. followed by the usual type name. If the type has a variable length, specify the length
in parentheses. For type dec, which also has a number of decimal places, specify the length
Just as in the SAP GUI-based editor, you can include one structure in another. In ADT, you
do this using the include keyword. Remember that each component in the structure must
9
Figure 7: Foreign Key Definitions in Structures
Structure fields can have a foreign key definition, which is useful if you use the structure
fields in your user interface. You specify the foreign key relationship using the with foreign
key addition. The compulsory elements of the foreign key relationship are the check table
(in this case scarr) and the assignment of key values, which you include in a where
expression.
A foreign key definition can also have further semantic details that are normally optional,
but in certain special cases obligatory. These are the cardinality of the foreign key, which is
specified in brackets. The cardinality [0..*,1] means, for example, that a value may be used
any number of times in the structure field (or not at all) and that it corresponds to a single
entry in the check table. This is the default, and by far the most common, cardinality. The
other semantic information is the foreign key type, which you specify as an annotation.
Note: For further information about foreign key relationships, refer to class BC430 — ABAP
Dictionary.
If you are going to use the fields of your structure on the user interface it is helpful to the
end user to have value help. Fields with a foreign-key relationship always have value help
automatically, but you can assign a search help to any structure field using the with value
help addition. The where expression assigns components from the structure to parameters
of the search help. This enables the system to show only the possible values that fit to
10
Figure 9: Annotation For Currency Fields
Structure components with the ABAP Dictionary type CURR (currency amount) must always
be linked to a corresponding component with ABAP Dictionary type CUKY (currency key).
Without this relationship, the system cannot ensure that the amount will be formatted with
the correct number of decimal places. Consequently, CURR component without this link
cause syntax errors. To specify the currency component, use the annotation
@Semantics.amount.currencyCode.
Create A Structure
Business Example You are a programmer for an SAP customer and work with the new ABAP
11
There is now a syntax error in your definition. You will correct this in the next step.
4. Use an annotation to the PRICE component to link it to the CURRENCY component. The
5. Create a foreign key relationship for component CARRID. The check table is SCARR.
6. Assign a value help to component CONNID. The search help object is called H_SPFLI.
Solution
1. Create a new structure called ZBC404_##_STRUC where ## is your group number. Assign
c) Enter your package ZBC404_## and the name of the structure ZBC404_##_STRUC.
d) Choose Next.
12
a) For each component, enter the name, then a colon (:), then the data type. End each
There is now a syntax error in your definition. You will correct this in the next step.
4. Use an annotation to the PRICE component to link it to the CURRENCY component. The
5. Create a foreign key relationship for component CARRID. The check table is SCARR.
a) Extend the definition of CARRID as follows: WITH FOREIGN KEY scarr WHERE mandt =
6. Assign a value help to component CONNID. The search help object is called H_SPFLI.
a) Extend the definition of CONNID as follows: WITH VALUE HELP h_spfli WHERE carrid =
a) Proceed as you would when checking and activating any Repository object.
13
Modelling Views with ABAP Core Data Services
In this section, we will learn how to model views with ABAP Core Data Services.
ABAP Core Data Services Core Data Services represent a new way of modeling data in the
ABAP Dictionary. Instead of writing complex joins in ABAP programs, you can now use the
SQL Data Definition Language (DDL) to describe joins or even entities, and then access
them using SELECT statements. In contrast to conventional database views, in which only
inner joins are allowed, you can use CDS views to implement left or right outer joins and
unions.
This table summarizes the differences between a conventional database view and a Core
Core Data Services are a part of the new Open SQL implementation in ABAP for Release
7.40; as such, they are available on all database platforms supported by SAP (and should
You define Core Data Services views using an Eclipse-based editor in ADT. There is not
To create a new view, choose New → ABAP Repository Object, then choose
Dictionary → DDL source.
The simplest possible view is a projection on a single table. In the example shown in the
following figure, Core Data Services Single Table View, there is also a simple arithmetic
expression.
14
Figure 10: Core Data Services Single Table View
Using CDS views, you can represent different kinds of joins. Instead of a join, you can also
define associations between tables, as shown in the following graphic. This has the
advantage that you can address related tables using a path expression rather than a
15
Figure 11: Core Data Services Views — Join Versus Association
The name of the view is also the name of a corresponding ABAP Dictionary type that you
can use to define structures and internal tables. To select data using a CDS view, you must
use the new Open SQL syntax, which has the following new features:
● Arithmetic expressions
● CASE distinction
● Access to Core Data Services views With regard to the new Open SQL syntax,
please note the following:
● All column lists (after SELECT, ORDER BY, GROUP BY) are comma separated
16
You are a programmer for an SAP customer and work with the new ABAP Development
Tools. Your current task is to build an application which displays flight information for
the three different flight classes – economy, business class and first class. The data is
spread across two tables, and you need to read the data from these tables for each
flight class. In order to achieve this, you create a CDS view using a join and a union. For
each flight, identified by the field combination CARRID, CONNID, FLDATE, you must
display three rows, one for each class. The output should look like this:
1. Create a new ABAP DDL Source called ZBC404_##_CDS, where ## is your group
number.
ZBC404_##_DDL.
3. Define the view as an inner join between SFLIGHT and SBOOK. Use the columns
4. Write a SELECT statement to select the columns shown in the table below. Remember
to add a WHERE clause to the statement to restrict the class to value 'Y' and ensure that
you only read non-cancelled bookings ( CANCELLED <> 'X' ). This statement reads the
total number of economy class bookings. To add the business and first class bookings,
use the UNION ALL function and copy the statement that you wrote, making sure that
you change the class to 'C' for business class and then 'F' for first class.
17
a) See code block below.
18
Write a program that reads data from the database using the CDS view that you created
b) Ensure that you are working in the correct project and enter the name of your
package ZBC404_##.
2. Declare an internal table with the line type of your CDS view ZBC404_##_DDL. It can
3. Define a selection screen with parameters for airline, flight number and flight date.
Use the fields CARRID, CONNID and FLDATE of your CDS view to define the parameter
types.
4. Use the view to select the data that the user requests. Remember that you must use
5. Use the ALV Object Model to display the data. Declare a variable with type REF TO
cl_salv_table.
6. Use the factory and display methods of the ALV Object Model to display the data.
19
a) See the code block below.
20