exercise 3b: create table persistence and generate data

12
1 Building Extensions with SAP Extension Suite Exercise 3b: Create Table Persistence and Generate Data Exercise Scenario In this portion of the exercise, you will create table persistence and generate data for it. The ABAP trial system is a so called “shared instance” which means that this instance is public to all trial user on the BTP. So, please make sure that you pick a unique 4-digit number for your repository objects and please do not change any the other packages there. Estimated Time to Complete: 5 minutes Follow the steps below to complete the exercise. Steps and Instructions Additional Information Step 1: Create an ABAP Package The first step is to create an ABAP Package.

Upload: others

Post on 07-May-2022

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Exercise 3b: Create Table Persistence and Generate Data

1

Building Extensions with SAP Extension Suite

Exercise 3b: Create Table Persistence and Generate Data

Exercise Scenario

In this portion of the exercise, you will create table persistence and generate data for it.

The ABAP trial system is a so called “shared instance” which means that this instance is public to all trial user

on the BTP. So, please make sure that you pick a unique 4-digit number for your repository objects and please

do not change any the other packages there.

Estimated Time to Complete: 5 minutes

Follow the steps below to complete the exercise.

Steps and Instructions Additional Information

Step 1: Create an ABAP Package

The first step is to create an ABAP Package.

Page 2: Exercise 3b: Create Table Persistence and Generate Data

2

Steps and Instructions Additional Information

1 Expand the TRL_EN folder (you may be

prompted to select the Open Logon Page in

Browser option again), then the Favorite

Packages folder, and then right-click ZLOCAL.

A pop-up dialog appears.

2 Select New and then ABAP Package.

The New ABAP Package dialog appears.

Page 3: Exercise 3b: Create Table Persistence and Generate Data

3

Steps and Instructions Additional Information

3 Populate the fields with the following

information, replacing XXXX with a 4-digit

number of your choice, and then select the Next

button:

Name = ZTRAVEL_APP_XXXX

Description = Package for Travel XXXX

Add to favorite packages = Yes

Superpackage = ZLOCAL

Package Type = Development

The Selection of Transport Request page

appears.

Page 4: Exercise 3b: Create Table Persistence and Generate Data

4

Steps and Instructions Additional Information

4 Select the Create a new request option, enter

a Request Description, and then select the

Finish button.

Your package is added to the list of your Favorite

Packages.

Step 2: Create a Database Table

Next, you’ll create a table in your database.

1 Right-click the package you just created, select

New, and then Other ABAP Repository

Object.

The ABAP Repository Object dialog appears.

Page 5: Exercise 3b: Create Table Persistence and Generate Data

5

Steps and Instructions Additional Information

2 Scroll down to find and expand the Dictionary

folder, select Database Table, and then select

the Next button.

The Database Table dialog page appears.

3 Populate the fields with the following

information, replacing XXXX with the 4-digit

number you have been using, and then select

the Next button:

Name = ZTRAVEL_XXXX

Description = Database table for travel data

XXXX

The Selection of Transport Request page

appears

Page 6: Exercise 3b: Create Table Persistence and Generate Data

6

Steps and Instructions Additional Information

4 Select the Finish button.

The code for the table appears in a new tab.

Since we are working on the ABAP Cloud

Environment, we do not have access to graphical

editors like transaction SE11 to create and edit our

database objects. Database tables are created via

the code editor. This also allows you to copy and

paste entire database definitions.

The syntax is similar to the CDS-DDL syntax.

Above the define table statement, annotations are

used to define additional technical settings for the

current database table.

Between the curly brackets the tables fields are

specified as the following: (key) <field_name> :

<type>;

Page 7: Exercise 3b: Create Table Persistence and Generate Data

7

Steps and Instructions Additional Information

Type can refer to any ABAP or DDIC types in the

system. To define key fields, the key word “key”

can be used. Each element is separated by a

semicolon.

5 Replace the default code with the following,

changing the XXXX to match the 4-digit number

you have been using.

@EndUserText.label : 'Database table for travel

data XXXX'

@AbapCatalog.enhancementCategory :

#NOT_EXTENSIBLE

@AbapCatalog.tableCategory :

#TRANSPARENT

@AbapCatalog.deliveryClass : #A

@AbapCatalog.dataMaintenance :

#RESTRICTED

define table ztravel_xxxx {

key client : abap.clnt not null;

key mykey : sysuuid_x16 not null;

travel_id : /dmo/travel_id;

agency_id : /dmo/agency_id;

customer_id : /dmo/customer_id;

begin_date : /dmo/begin_date;

end_date : /dmo/end_date;

@Semantics.amount.currencyCode :

'ztravel_xxx.currency_code'

booking_fee : /dmo/booking_fee;

@Semantics.amount.currencyCode :

'ztravel_xxx.currency_code'

total_price : /dmo/total_price;

currency_code : /dmo/currency_code;

description : /dmo/description;

Here we are defining a database table which will

later contain our travel data.

The finished code should look like the following.

The full text can be found in the Exercise 3, table

code section of the Exercise Code Snippets.txt

file.

Page 8: Exercise 3b: Create Table Persistence and Generate Data

8

Steps and Instructions Additional Information

overall_status : /dmo/overall_status;

created_by : syuname;

created_at : timestampl;

last_changed_by : syuname;

last_changed_at : timestampl;

}

6 Select the Save icon on the toolbar or use

CTRL + S to save your file.

7 Select the Activate icon on the toolbar or use

CTRL + F3 to activate your file.

Step 3: Create an ABAP Class

Once the table is created, you can insert data into that table.

1 Right-click the package you just created, select

New, and then ABAP Class.

The New ABAP Class dialog appears.

Page 9: Exercise 3b: Create Table Persistence and Generate Data

9

Steps and Instructions Additional Information

2 Populate the fields with the following

information, replacing XXXX with the 4-digit

number you have been using, and then select

the Next button:

Name =

ZCL_GENERATE_TRAVEL_DATA_XXXX

Description = Class for generating travel

data

The Selection of Transport Request page

appears.

3 Select the Finish button.

The code for the class appears in a new tab.

Page 10: Exercise 3b: Create Table Persistence and Generate Data

10

Steps and Instructions Additional Information

4 Replace the default code with the text available

in the Exercise 3, class code section of the

Exercise Code Snippets.txt file, changing the

XXXX to match the 4-digit number you have

been using.

The finished code should look like the following.

5 Select the Save icon on the toolbar or use

CTRL + S to save your file.

6 Select the Activate icon on the toolbar or use

CTRL + F3 to activate your file.

Page 11: Exercise 3b: Create Table Persistence and Generate Data

11

Steps and Instructions Additional Information

7 Press the F9 key on your keyboard to run your

ABAP class.

The ABAP Console in the lower right should

indicate 3 entries were created successfully.

8 Expand the ZTRAVEL_APP_XXXX folder, then

the Dictionary folder, then the Database

Tables folder, then select ZTRAVEL_XXXX

item, and the press the F8 key on your

keyboard.

The data is displayed in a table on the right side of

the screen.

© 2021 SAP SE or an SAP affiliate company. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate

company.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an

SAP affiliate company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional

trademark information and notices.

Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.

National product specifications may vary.

These materials may have been machine translated and may contain grammatical errors or inaccuracies.

These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind,

and SAP SE or its affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP

affiliate company products and services are those that are set forth in the express warranty statements accompanying such products and services, if

any. Nothing herein should be construed as constituting an additional warranty.

In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related

presentation, or to develop or release any functionality mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated

Page 12: Exercise 3b: Create Table Persistence and Generate Data

12

companies’ strategy and possible future developments, products, and/or platform directions and functionality are all subject to change and may be

changed by SAP SE or its affiliated companies at any time for any reason without notice. The information in this document is not a commitment,

promise, or legal obligation to deliver any material, code, or functionality. All forward-looking statements are subject to various risks and uncertainties

that could cause actual results to differ materially from expectations. Readers are cautioned not to place undue reliance on these forward-looking

statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.