Eclipse Preferences allow you to make general settings about how you want Eclipse to operate. You can access Preferences by choosing Window → Preferences.
The figure, Eclipse Preferences, shows you the Source Code Editors section of the Eclipse Preferences window.
If ABAP Development Tools are installed, there is a specific section for settings related to ABAP Development. Settings that can be controlled here include the following:
- Whether the system ID is displayed in the Editor tab page, and, if so, where
- Settings relating to Debugging, for example, whether system programs are debugged
- Settings specific to source code, for example, whether brackets are automatically closed, and whether the automatic syntax check is performed
- Settings related to editors, for example, font size and color options
In case you want to discard the settings that you have made, there is a Restore Defaults button.
You can adjust the properties of a specific ABAP project, just as you can adjust preferences for Eclipse in general. To do this, choose Properties from the project’s context menu. One useful collection of settings is found under ABAP Development → Editors → Source Code Editors → Formatter (as shown in the figure, ABAP Format Settings).
The options that are displayed here roughly correspond to the settings that can be made using the Pretty Printer in the ABAP Workbench. You can control the code style of the formatter, including whether source code is indented (for example, when programming an IF or CASE construct), and whether keywords and identifiers are in uppercase or lowercase.
When you have made and applied these settings in the project properties, the formatting can be applied by choosing SHIFT + F1 (on your keyboard) to format the code in the source code editor.
Creating a Hello World App
The main user interface technology that you will use in modern ABAP programming is SAP Fiori Elements. However, ADT provides you with a console that allows you to create output quickly and simply in test applications.
- 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) so that the user can use it in a particular way.
- Use the Filter field to restrict the number of entries in the list.
- Double-click the interface (IF_OO_ADT_CLASSRUN).
- When you return to the ABAP Class dialog box, the new interface appears.
- Choose Next.
- Next, assign the class to a Transport Request.
- Under Choose from Requests in which you are involved, mark the request that you used to create your package.
- Choose Finish.
The interface IF_OO_ADT_CLASSRUN allows you to run a class in 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
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
ADT 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. ADT 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. To do this, 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. During the activation, the system compiles the object into a form that the ABAP runtime system can understand.
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
There are four key functions that you must know when you are writing code in the ABAP Editor.
SAVE – This option saves your code but does not check the syntax for correctness or activate the program. It is good practice to save your work regularly.