Week 1 Unit 5: Preparing Your ABAP Development Environment
In this hands-on exercise, you will create a very simple Hello World ABAP console app on the SAP Cloud Platform ABAP Environment. You can watch unit 6 of week 1: Creating your first ABAP Cloud Console App on the openSAP.com platform.
Hints and Tips
Speed up the typing by making use of the Code Completion feature (shortcut Ctrl+Space) and the prepared code snippets provided. You can easily open an object with the shortcut Ctrl+Shift+A, format your source code using the Pretty Printer feature Shift+F1 and toggle the fullscreen of the editor using the shortcut Ctrl+M.A great overview on ADT shortcuts can be foung here: Useful ADT Shortcuts
Please note that the placeholder
####
used in object names in the exercise description must be replaced with the suffix of your choice during the exercises. The suffix can contain a maximum of 4 characters (numbers and letters). The screenshots in this document have been taken with the suffix1234
and systemD20
. Your system id will beTRL
.Please note that the ADT dialogs and views may change in the future due to software updates - i.e. new and/or optimized features.
Follow the instructions below.
First, create a new ABAP package to group the various development objects that you're going to create during the whole course.
-
In the Project Explorer, right-click on your ABAP cloud project and choose New > ABAP Package from the context menu.
-
Maintain
ZRAP_####
as name (where####
is your chosen suffix) and a meaningful description (e.g.RAP Exercises
).
The Project and the Package have already been assigned. The Superpackage should be set toZLOCAL
as well.Choose Next to continue.
-
Assign a transport request.
For that, either select an existing transport request – if available – or choose Create a new request, enter a meaningful description and then choose Finish.The new package is now created.
-
Add your ABAP package to the Favorites Packages to make it easier to access.
For that, either (1) right-click on the relevant package and choose the context menu entry Add to Favorite Packages or (2) right-click on the Favorites Packages folder in the Project Explorer, choose the context menu entry Add Package..., filter the entries for the relevant package in the appearing dialog and press OK to add it.
You can now go ahead and create and implement your Hello World console app.
-
Right-click on your package and choose New > ABAP Class from the context menu.
-
Maintain
ZCL_HELLO_WORLD_####
as name (where####
is your chosen suffix) and a meaningful description (e.g.Hello world
) for the ABAP class. Add the ABAP interfaceIF_OO_ADT_CLASSRUN
which needs to be implemented in order to write outputs to the ABAP Console and choose Next. -
Assign the previously created transport request and choose Finish.
The ABAP class is now created and opened in the source-based class editor, ready for you to implement.
You can hover the appearing warning in the editor or have a look at it in the Problems view.
The reason for this warning is the currently missing implementation of the methodmain
. -
Set the cursor on the problematic statement, press CTRL+1 to open the Quick Assist view to check for proposals to solve this issue and choose the entry
Add implementation for main
_.You can make use of the ABAP Formatter (aka Pretty Printer) by pressing Shift+F1 on your keyboard to format the source code.
The settings of the ABAP Formatter can be adjusted under the ADT menu Windows > Preferences.
In the appearing dialog, search for “formatter”, click on Source Code Editors and then on ABAP Formatter.
Choose the relevant ABAP project in the appearing dialog and press OK to continue.
Adjust the settings as you wish in the ABAP Formatter dialog and then press Apply or Apply and Close to confirm the changes. These settings are project-specific and can be changed as you wish.You can also adjust the settings for the Code Completion (Ctrl+Space) for the ABAP and the CDS source code. For example, you can define whether a completion is simply inserted or overwrites the previous value.
For that, filter the entries for “code completion” in the Preferences dialog, then ajust the settings as you wish under **Source Code Editors > Code Completion** and under Source Code Editors > CDS > Code Completion.
Do not forget to always press Apply or Apply and Close to save the changes. -
You will use a string template to output the literal Hello world!.
Add the following codeline to the method implementation:out->write( |Hello world!| ).
-
Save
and activate
the changes.
Now, press F9 or right-click on the class and select Run As > ABAP Application (Console) from the context menu to execute the class.Check out the result in the ABAP Console view.
-
Let's enhance the current output with the user alias by using embedded expression.
On the SAP Cloud Platform ABAP environment, various system variables are no longer available due to the cloud environment or due to non-supported frameworks. Therefore, APIs (e.g. helper class
CL_ABAP_CONTEXT_INFO
) are provided to access released system variables like username, language and time.Enhance the current string template as follows:
out->write( |Hello world! ({ cl_abap_context_info=>get_user_alias( ) })| ).
-
Save
and activate
the changes.
Check out the enhanced output in the Console view.You can easily clear the Console view via its context menu entry Clear.
You have completed the exercise!
In this unit, you have learned
- How to use ABAP Development Tools (ADT) for Eclipse
- How to create ABAP packages and classes
- How to create a simple Hello World! console app
Find the source code for the created class in the /week1/sources folder:
Do not forget to replace all the occurrences of ####
with your chosen suffix in the copied source code.