In this tutorial, wherever XXX
appears, use a number (e.g. 000
).
Step 1: Open Eclipse
Open Eclipse, and select New > ABAP Package.
Step 2: Create ABAP package
-
Maintain following information in the appearing dialog and click Next.
- Name:
Z_Booking_XXX
- Description: Package Booking

-
Move on with Next.

-
Select transport request and click Finish.

Step 3: Open ABAP repository object
Right-click on your package and navigate to New > Other ABAP Repository Object from the appearing context menu.
Step 4: Create database table
- Search for database table, select the appropriate entry and click Next.

- Maintain the required information and click Next.
- Name:
ZTBOOKING_XXX
- Description: Table Booking

-
On the next dialog, provide a transport request and click Finish.

-
Check result. An empty table is now created.

Step 5: Define database table
-
Define the table columns (client, booking, customername
, numberofpassengers
, …). Specify client and booking as key fields, and the field currencycode
as currency key for cost as displayed below. The table annotations (beginning with @) remain unchanged. For that, you can copy the database table definition provided below.
@EndUserText.label : 'Demo: Booking Data'
@AbapCatalog.enhancementCategory : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #LIMITED
define table ztbooking_xxx {
key client : abap.clnt not null;
key booking : abap.int4 not null;
customername : abap.char(50);
numberofpassengers : abap.int2;
emailaddress : abap.char(50);
country : abap.char(50);
dateofbooking : timestampl;
dateoftravel : timestampl;
@Semantics.amount.currencyCode : 'ztbooking_xxx.currencycode'
cost : abap.curr(15,2);
currencycode : abap.cuky;
lastchangedat : timestampl;
}
-
Save and activate the database table.

Step 6: Create ABAP class
-
Create a class in order to prefill
our created database table. Right-click on your package and navigate to New > ABAP Class in the appearing context menu.

-
Provide the required information and click Next.
- Name:
ZCL_GENERATE_BOOKINGS_XXX
- Description: Class to generate bookings

-
Provide a transport request and click Finish.

Step 7: Replace source code
-
Replace the source code of your class with the one provided below:
CLASS zcl_generate_bookings_xxx DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_generate_bookings_xxx IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA:it_bookings TYPE TABLE OF ztbooking_xxx.
* read current timestamp
GET TIME STAMP FIELD DATA(zv_tsl).
* fill internal table (itab)
it_bookings = VALUE #(
( booking = '1' customername = 'Buchholm' numberofpassengers = '3' emailaddress = 'tester1@flight.example.com'
country = 'Germany' dateofbooking ='20180213125959' dateoftravel ='20180213125959' cost = '546' currencycode = 'EUR' lastchangedat = zv_tsl )
( booking = '2' customername = 'Jeremias' numberofpassengers = '1' emailaddress = 'tester2@flight.example.com'
country = 'USA' dateofbooking ='20180313125959' dateoftravel ='20180313125959' cost = '1373' currencycode = 'USD' lastchangedat = zv_tsl )
).
* Delete the possible entries in the database table - in case it was already filled
DELETE FROM ztbooking_xxx.
* insert the new table entries
INSERT ztbooking_xxx FROM TABLE @it_bookings.
* check the result
SELECT * FROM ztbooking_xxx INTO TABLE @it_bookings.
out->write( sy-dbcnt ).
out->write( 'data inserted successfully!').
ENDMETHOD.
ENDCLASS.
-
Save and active your class.

Step 8: Run ABAP application
-
Run your class as an ABAP application (console) or press F9.

-
Check console output.

-
Switch back to your data definition and press F8 to see the inserted data.

-
Now check your result.
