Hi ABAP community,
Content assist provides you a list with proposals which you can insert at the current cursor position. This can be, for example the following identifiers …
- CDS annotations
- Datasources such as CDS view entities, CDS DDIC-based views, database tables, and so on
- ABAP CDS keywords
In the following sample, you can see where you can trigger code completion in a data definition:
Simply choose Ctrl + Space at the relevant position in your source code if automatic code completion is not activated.
Code completion is enabled by default. To disable it in the preferences, see the section “Automatic Display of Proposals”.
For keywords …
Just start typing your code. If code completion finds a matching keyword, it will be displayed as proposal automatically:
Just press the tab key to take it over.
Alternatively, you can choose Ctrl + Space and takeover the keyword from the proposal list:
For CDS annotations and so on …
To reduce the number of proposals, enter asterisk (*) at the relevant position and choose Ctrl + Space. Note that the cursor position is relevant. The proposal will be added there.
The proposal list only displays the matching entries.
Did you know that content assist also helps you find the relevant value?
Note that you always position the cursor at the relevant position where you need assistance. Choose then Ctrl + Space and check the entries from the proposal list.
For datasources …
Not enough? You are also supported when adding datasources, for example a database table.
After adding a datasource, you can add all of its elements in one step. Did you know that? Simply choose Ctrl + Space to trigger content assist and choose “Insert all elements” from the proposal list.
Afterwards, all elements of the datasource will be added to your data definition.
When you have defined an association in your data definition, …
- the elements from the association target will also be automatically inserted. The /*Associations*/ comment highlights that the subsequent elements result from the association.
- you can also insert all elements from the association target. To do this, add a dot after the element, choose Ctrl + Space and choose Insert all elements from the list.
Automatic Display of Proposals
Content assist (inclusive code completion) is enabled by default. To disable automatic proposals, choose Window > Preferences > ABAP Development > Editors > Source Code Editors > Code Completion from the menu bar. Alternatively, you can directly enter “code completion” in the search field of the Preferences dialog.
Just deselect then the Automatically trigger code completion after typing ‘-‘, ‘~’, ‘->’ checkbox.
Defining Insertion or Overwrite
You can predefine how to take over proposals from the code completion list. In the Content Assist section from the latter preference page, choose one of the following radio buttons …
- Completion inserts to add the proposal to your input at the current cursor position
- Completion overwrites to remove your input with the chosen proposal
Note that this function only works when you keep Ctrl pressed and select the relevant proposal, your source code will be adapted as follows:
ADT inserts the proposal at the current cursor position.
So,you might need to remove your previous input to fix possible errors.
ADT completely overwrites the existing input in the whole line.
Flat or Structured Insertion
To predefine ABAP CDS-specific code completion, choose Window > Preferences > ABAP Development > Editors > Source Code Editors > CDS > Code Completion from the menu bar. Alternatively, you can directly enter “code completion” in the search field of the Preferences dialog.
For example, here you can define how to insert CDS annotations.
The annotation will be added in one line.
The annotation will be added indented across several lines.
When triggering content assist, you can use the element information popup to get more information about the element you want to add. This supports you to ensure adding the right element. Just select the relevant proposal and its element information popup will be opened.
In addition, you can navigate from here to associations, and so on.