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.- Write your ABAP code in a class, and choose File → New → ABAP Class.
- A dialog box appears where you verify the project is correct.
- Enter the name of the package that you have already created.
- 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.
- 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.
- Use the Filter field to restrict the number of entries in the list.
- Double-click the interface (IF_OO_ADT_CLASSRUN).
- The new interface appears When you return to the ABAP Class dialog box.
- Choose Next.
- Next, assign the class to a Transport Request.
- Under Choose from Requests in which you are involved, and mark the request you used to create your package.
- Choose Finish.
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.
In your code block, you can use out->write( ) to display information in the console. The line
1out->write( "Hello World" ).
- 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
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.
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.
To run the class, select F9 on your keyboard, or right-click in the editor, and choose Run as → ABAP Application (Console). The output, "Hello World", appears in the console. If you cannot see the console view, choose Window → Show View → Other..., 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
Button | Keyboard Command | Description |
---|---|---|
CTRL + S | Save | |
CTRL + F2 | Check Syntax | |
CTRL + F3 | Activate | |
F9 | ABAP Application (Console) |