Developing your First ABAP Application

Objective

After completing this lesson, you will be able to Explain ABAP Language at a Basic Level.

Create Simple ABAP Code in the ABAP Development Tools

Creating a Hello World App

The main user interface technology you will use in modern ABAP programming is SAP Fiori. However, ABAP Development Tools (ADT) provides a console that allows you to create output quickly and simply in test applications.

For more information on SAP Fiori, view the Learning Journey Learning the Basics of SAP Fiori at http://learning.sap.com.
  1. Write your ABAP code in a class, and choose FileNewABAP Class.
  2. A dialog box appears where you verify the project is correct.
  3. Enter the name of the package that you have already created.
  4. Enter a name for your Class, remembering to start with Z or Y. It can be up to 30 characters and letters A–Z, the digits 0–9, and the underscore symbol.
  5. Choose the Add option to add an interface to a class (in our example, it is IF_OO_ADT_CLASSRUN) to allow output to the console.
  6. Use the Filter field to restrict the number of entries in the list.
  7. Double-click the interface (IF_OO_ADT_CLASSRUN).
  8. The new interface appears When you return to the ABAP Class dialog box.
  9. Choose Next.
  10. Next, assign the class to a Transport Request.
  11. Under Choose from Requests in which you are involved, and mark the request you used to create your package.
  12. Choose Finish.
Screenshot of a newly created ABAP class showing the initial source code

The interface IF_OO_ADT_CLASSRUN allows you to run a class in ABAP Development Tools (ADT) using the F9 key. When you do this, the system executes the code between METHOD if_oo_adt_classrun~main and ENDMETHOD. In this code block, you can output information in the ADT console.

Screenshot of ABAP code that prints ‘Hello World’ to the console

In your code block, you can use out->write( ) to display information in the console. The line

Code Snippet
Copy code
Switch to dark mode
1
out->write( "Hello World" ).
prints "Hello World" to the console. Crucially, you do not have to know at this point how it works; you just have to type in the code, ensuring the following:

  • There is no space between write and the opening parenthesis
  • There is at least one space after the opening parenthesis
  • There is at least one space before the closing parenthesis
  • There is a period at the end of the line
Screenshot of the error symbol next to a syntax error in the source code editor view and the error description in the Problems view

ABAP Development Tools checks your code as you go along and flags up errors in the left-hand margin of the editor with a white cross on a red background.

You can see the corresponding error messages in the Problems view below the editor. ABAP Development Tools also displays the same message as a pop-up when you move the mouse over the error symbol in the editor.

Clicking on the Activate button will change the source code version from Inactive to Active

To run an ABAP object, you must activate it. Activating the object checks the syntax, saves the object, and generates a run-time version of the object. If there is a syntax error the object will not be activated. To activate an object, choose the Activate icon in the toolbar or use the keyboard shortcut Ctrl + F3 (on your keyboard). You can see whether an object is active or not by looking in the Properties view, which is usually located in the tab below the ABAP Editor.

Screenshot of the context menu with the Run as ABAP Application button after right clicking the source code next to a screenshot of the output message ‘Hello World’ in the Console view

To run the class, select F9 on your keyboard, or right-click in the editor, and choose Run asABAP Application (Console). The output, "Hello World", appears in the console. If you cannot see the console view, choose WindowShow ViewOther..., and select the Console view.

Using the Eclipse Editor

Here are some important key functions when writing code in the ABAP Editor.

Key Functions in the ABAP Editor

ButtonKeyboard CommandDescription
CTRL + SSave
CTRL + F2Check Syntax
CTRL + F3Activate
F9ABAP Application (Console)

Create a Hello World Application

Business Example

You are a programmer for an SAP customer and work with the new ABAP Development Tools. You want to create an ABAP class in Eclipse, then activate it and run it as an ABAP application.

We will assign this class to the package created before. Let the class implement interface IF_OO_ADT_CLASSRUN so that you can use the class as the main program for an Eclipse console app.

Note

In this exercise XX refers to your number.

Steps

  1. In your package created previously, create a new ABAP class with the name, ZCL_XX_HELLO_WORLD. Ensure that it uses the interface, IF_OO_ADT_CLASSRUN. When you are prompted to assign the class to a transport request, use the transport request that you created in the previous exercise.

    1. Choose FileNewABAP Class.

    2. Enter your package, ZS4D100_XX, where XX is your number. 

    3. Enter the name, ZCL_XX_HELLO_WORLD, where XX is your number, and enter a description for your class.

    4.  Choose Add... (next to the Interfaces group box).

    5. Enter the filter text, IF_OO_ADT_CLASSRUN. Double-click the matching entry in the hit list.

    6. Choose Next.

    7. Select Choose from requests in which I am involved and your own transport request.

    8. Choose Finish.

  2. In the if_oo_adt_classrun~main( ) method, use out->write( ) to output the phrase Hello World.

    1. In the editor, enter the following coding between METHOD if_oo_adt_classrun~main and ENDMETHOD: out->write( | Hello World | ).

  3. Activate and test your class.

    1. Press Activate (Ctrl-F3).

    2. Press F9 to run the class.

  4. Check the output in the Console view of Eclipse.

    1. Check the Console view that should have opened as a new tab below the editor view.

    2. If the Console view is not visible, open it by choosing WindowShow viewOther. Double-click Console in the hit list.

      Code Snippet
      Copy code
      Switch to dark mode
      12345678910111213141516
      " Full Solution Code CLASS zcl_s4d100_hello_world_sol DEFINITION PUBLIC FINAL CREATE PUBLIC. PUBLIC SECTION. INTERFACES IF_OO_ADT_CLASSRUN. PROTECTED SECTION. PRIVATE SECTION. ENDCLASS. CLASS zcl_s4d100_hello_world_sol IMPLEMENTATION. METHOD if_oo_adt_classrun~main. out->write( | Hello World! | ). ENDMETHOD. ENDCLASS.

      Practice

Log in to track your progress & complete quizzes