Skip to content

Latest commit

 

History

History
138 lines (88 loc) · 7.9 KB

unit6.md

File metadata and controls

138 lines (88 loc) · 7.9 KB

HANDS-ON EXERCISE FOR WEEK 1 UNIT 6: CREATING YOUR FIRST ABAP CLOUD CONSOLE APP

Previous Exercise

Week 1 Unit 5: Preparing Your ABAP Development Environment

Introduction

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 suffix 1234 and system D20. Your system id will be TRL.

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.

Step 1. Create a new ABAP package

First, create a new ABAP package to group the various development objects that you're going to create during the whole course.

  1. In the Project Explorer, right-click on your ABAP cloud project and choose New > ABAP Package from the context menu.

    create ABAP package 01

  2. 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 to ZLOCAL as well.

    Choose Next to continue.

    create ABAP package 02

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

    create ABAP package 03

    The new package is now created.

    create ABAP package 04

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

    Option 1 & 2: create ABAP package 04

Step 2. Create and implement the Hello World Console App

You can now go ahead and create and implement your Hello World console app.

  1. Right-click on your package and choose New > ABAP Class from the context menu.

    create Hello World 01

  2. 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 interface IF_OO_ADT_CLASSRUN which needs to be implemented in order to write outputs to the ABAP Console and choose Next.

    create Hello World 02

  3. Assign the previously created transport request and choose Finish.

    create Hello World 03

    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 method main.

    create Hello World 04

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

    create Hello World 04

    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.

  5. You will use a string template to output the literal Hello world!.
    Add the following codeline to the method implementation:

    out->write( |Hello world!| ).
  6. Save save icon and activate activate icon 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.

    Class Run As

    Check out the result in the ABAP Console view.

    create Hello World 05

  7. 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(  ) })| ).
  8. Save save icon and activate activate icon the changes.
    Check out the enhanced output in the Console view.

    create Hello World 06

    You can easily clear the Console view via its context menu entry Clear.

Summary

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

Solution

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.

Next excercise

Week 2: Developing a Read-Only List Report App