Wednesday 2 March 2022

Benefit From Content Assist and Code Element Information When Developing Data Models

This blog describes how to benefit from content assist and code element information when creating or editing data definitions using ABAP Development Tools (ADT) a.k.a. ABAP in Eclipse.

Content assist describes the Eclipse features that make your daily work easier. Code completion is one of these features. It proposes existing elements, keywords, or identifiers which might fit best at the current cursor position in your source code.

What Can I Insert Using Content Assist?

Code completion 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:

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

Simply choose Ctrl + Space at the relevant position in your source code if automatic code completion is not activated.

How To Use Content Assist?


Code completion is enabled by default. To disable it in the preferences, see the section “Automatic Display of Proposals”.

For keywords …

Start typing your code. If code completion finds a matching keyword, it will be displayed as proposal automatically:

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

Just press the tab key to take it over.

Alternatively, you can choose Ctrl + Space and takeover the keyword from the proposal list:

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

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.

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

The proposal list only displays the matching entries.

Did you know that content assist also helps you find the relevant value?

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

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.

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

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.

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

Afterwards, all elements of the datasource will be added to your data definition.

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

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.

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

How To Set the Relevant Preferences?


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.

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

Just deselect then the Automatically trigger code completion after typing ‘-‘, ‘~’, ‘->’ checkbox.

Defining Insertion or Overwrite

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

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:

Insertion

ADT inserts the proposal at the current cursor position.

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

So,you might need to remove your previous input to fix possible errors.

Overwrite

ADT completely overwrites the existing input in the whole line.

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

Flat or Structured Insertion

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

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.

Flat Insertion

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

The annotation will be added in one line.

Structured Insertion

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

The annotation will be added indented across several lines.

How To Benefit From Code Element Information?


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.

SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Preparation, SAP ABAP Jobs

In addition, you can navigate from here to associations, and so on.

Source: sap.com

No comments:

Post a Comment