Two pseudo comments on one ABAP statement

Reading time:

2–3 minutes

This article discusses the following ABAP statement:

SELECT FROM <CDS>
       FIELDS *
       INTO TABLE @DATA(RESULT).

in this example <CDS> is a placeholder for a Core Data Service. The ABAP Test Cockpit (ATC) encounters two problems with these three lines when it checks them:

  1. All columns are selected (FIELDS *).
  2. There are no restrictions on the selection (missing WHERE clause).

In short, you want to read all columns and all rows via Core Data Service. Even though this isn’t recommended, it can be necessary from time to time.

A typical example of such a scenario is the one-time reading of customizing settings from a database table (persistent) into an internal table (transient), whose entries are then repeatedly read using TABLE EXPRESSIONS or READ TABLE in the subsequent program flow. This avoids constantly reading from the database with a SELECT SINGLE statement.

Since such a situation justifies the ABAP statement shown, you need to tell the ATC that everything is okay. But how?

Two pseudo comments are required:

  1. “#EC CI_ALL_FIELDS_NEEDED
  2. “#EC CI_NOWHERE

Their pragma counterparts don’t seem to exist (yet) according to the ABAP_SLIN_PRAGMAS report.

Where exactly do you write the pseudo comments? Here’s the solution, which I don’t think is really intuitive:

SELECT FROM <CDS>
       FIELDS *               "#EC CI_ALL_FIELDS_NEEDED
       INTO TABLE @DATA(RESULT). "#EC CI_NOWHERE

The two pseudo comments can also be positioned differently. The following code is also correct, but in my opinion just as unintuitive:

SELECT FROM <CDS>             "#EC CI_ALL_FIELDS_NEEDED
       FIELDS *               "#EC CI_NOWHERE
       INTO TABLE @DATA(RESULT). 

Surprisingly, writing the two pseudo comments on one line, at the end of the SELECT-statement, doesn’t work.

The ABAP documentation also points out that only one pseudo comment is allowed per line: “To hide multiple warnings from a statement with pseudo comments, the statement must be spread across multiple lines.

The following syntactically and semantically correct arrangement of the SELECT statement is therefore not possible if one wants to use pseudo comments.

SELECT FROM <CDS> FIELDS * INTO TABLE @DATA(RESULT).

You are forced to split the SELECT statement across multiple lines. While I often do this anyway, the pseudo comments here create a necessity.

I’ve learned something new again, even if it goes against my intuition. As always, when in doubt, read the documentation.


Thank you for reading. If you enjoyed the post, please share the article with your community. Thanks in advance.

Michael (a mind forever voyaging)