0% found this document useful (0 votes)
81 views

ABAP Dictionary Objects in Eclipse

Uploaded by

Jamila Hamdi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

ABAP Dictionary Objects in Eclipse

Uploaded by

Jamila Hamdi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

ABAP Dictionary Objects in

Eclipse
Table of Contents

Table of Contents 2

Overview 2

ABAP Dictionary Objects in Eclipse 3


Working With Data Elements 3
Create A Data Element 4

Working With Structures 6


The Structure Editor 6
Syntax For Creating Structures 7
Create A Structure 11

Modelling Views with ABAP Core Data Services 13


Create a Core Data Service 15

2
Overview
In the ABAP Dictionary Objects in Eclipse we are going to 👍

● Work With Data Elements in ADT

● Work With Structures in ADT

● Model views with ABAP Core Data Services

ABAP Dictionary Objects in Eclipse

Working With Data Elements


We are going to learn how to use the new data element editor in ADT.

The Data Element Editor

If your AS ABAP backend system has Release 7.50 or higher, you can use the new Eclipse

editor for data elements.

Figure 1: Creating A New Data Element

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).

Figure 2: The Data Element Editor

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.

Create A Data Element


Business Example You are a programmer for an SAP customer and work with the new ABAP

Development Tools. Your current task is to create a data element.

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_##.

2. Use the type S_CARR_ID for the data element.

3. Enter appropriate field labels.

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

the value help to do this).

5. Link the data element with the Set/Get Parameter CAR.

6. Activate the data element.

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_##.

a) Open the New Repository Objectdialog box (Ctrl + Shift + N).

b) Choose Dictionary → Data Element

c) Enter your package ZBC404_## and the name of the data element

ZBC404_##_CARRIER. d) Choose Next.

e) Choose the appropriate transport request and press Finish.

2. Use the type S_CARR_ID for the data element.

a) Enter the type in the Type Name field.

3. Enter appropriate field labels.

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

the value help to do this).

a) Click the + symbol to the left of Additional Properties.

b) Enter H_SCARR in the Name field of the search help group box and CARRID in the

Parameter field.

5. Link the data element with the Set/Get Parameter CAR.

a) Enter CAR in the Parameter ID field. 6. Activate the data element.

Working With Structures


We are going to learn how to use the new structure editor in ADT and the syntax for

declaring structures.

The Structure Editor

Figure 3: The Structure Editor

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

a set of annotations that begin with the @ character.

The structure editor in ADT includes code completion which, as always, you invoke with the

keyboard shortcut Ctrl + Space.

Syntax For Creating Structures

Figure 4: Syntax Of A Structure Definition

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

either about an individual component or about the entire structure.

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

Figure 5: Types Of Structure Components

There are various ways of defining the type of a structure component:

● Elementary type

● Reference type

8
● Structured type

● Internal table 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

(class or interface) or a data 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

(in digits) and the number of decimal places separated by a comma.

Figure 6: Including Structures

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

have a unique name.

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.

Possible values are #KEY, #NON_KEY, and #TEXT_KEY.

Note: For further information about foreign key relationships, refer to class BC430 — ABAP

Dictionary.

Figure 8: Search Help For A Structure Field

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

other entries that the user has already made.

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

Development Tools. Your current task is to create a structure.

1. Create a new structure called ZBC404_##_STRUC where ## is your group number.

Assign it to your package BC404.

2. Delete the line component_to_be_changed : abap.string(0); from the structure definition.

3. Add the following components to your structure:

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

code completion will help you to find the right annotation.

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.

7. Check and activate your structure.

Solution

1. Create a new structure called ZBC404_##_STRUC where ## is your group number. Assign

it to your package BC404.

a) Open the New Repository Objectdialog box (Ctrl + Shift + N).

b) Choose Dictionary → Structure.

c) Enter your package ZBC404_## and the name of the structure ZBC404_##_STRUC.

d) Choose Next.

e) Choose the appropriate transport request and press Finish.

2. Delete the line component_to_be_changed : abap.string(0); from the structure definition.

3. Add the following components to your structure:

12
a) For each component, enter the name, then a colon (:), then the data type. End each

component definition with a semicolon (;).

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

code completion will help you to find the right annotation.

a) Before the definition of PRICE, enter the following: @Semantics.amount.currencyCode :

'zbc404_##_struc.currency'. Remember to replace ## with your group number.

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 =

zbc404_##_struc.client AND carrid = zbc404_##_struc.carrid.

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 =

bc404_##_struc.carrid AND connid = zbc404_##_struc.connid.

7. Check and activate your structure.

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

Data Services view:

Table 1: Conventional Database Versus Core Data Services Views

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

not, for example, be confused with platform-specific SAP HANA views).

You define Core Data Services views using an Eclipse-based editor in ADT. There is not

currently an equivalent editor in the SAP GUI-based ABAP Workbench.

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

A further notation that you might encounter is:

DEFINE VIEW zview AS SELECT c1, c2, c3 FROM dbtab

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

complex join condition.

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

● Right outer joins

● 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

● All ABAP variables must be preceded by the escape character @

Create a Core Data Service


Business Example

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.

2. Add the annotation @AbapCatalog.sqlViewName. Use the view name

ZBC404_##_DDL.

3. Define the view as an inner join between SFLIGHT and SBOOK. Use the columns

CARRID, CONNID, and FLDATE to define the join condition.

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.

Write a Program that uses the CDS View

18
Write a program that reads data from the database using the CDS view that you created

in the previous exercise.

1. Create a new executable program called ZBC404_##_CONSUME_CDS.

a) Choose File → New → ABAP Program.

b) Ensure that you are working in the correct project and enter the name of your

package ZBC404_##.

c) Enter the program name ZBC404_##_CONSUME_CDS and choose Continue.

d) Select your transport request and choose Finish.

2. Declare an internal table with the line type of your CDS view ZBC404_##_DDL. It can

be a standard table with default key.

a) See the code block below.

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.

a) See the code block below.

4. Use the view to select the data that the user requests. Remember that you must use

the new Open SQL syntax.

a) See the code block below.

5. Use the ALV Object Model to display the data. Declare a variable with type REF TO

cl_salv_table.

a) See the code block below.

6. Use the factory and display methods of the ALV Object Model to display the data.

19
a) See the code block below.

20

You might also like