Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP - Database Accesses →  Open SQL →  Open SQL - Read Accesses →  SELECT →  SELECT - cond →  WHERE - sql_cond 

sql_cond - (cond_syntax)

Other versions: 7.31 | 7.40 | 7.54

Syntax


... (cond_syntax) ...

Effect

A logical expression can be specified as a parenthesized data object cond_syntax that contains the syntax of a logical expression or is initial when the statement is executed. In this way, it is now possible to specify all logical expressions dynamically, with the exception of the evaluation of a subquery.

The logical expression in cond_syntax can also be combined using AND or OR or negated using NOT. The data object cond_syntax can be a character-like data object or a standard table without secondary table keys and with a character-like data object. The syntax in cond_syntax is, as in the ABAP Editor, not case-sensitive. When specifying an internal table, you can distribute the syntax over multiple rows.

The result of the logical expression (cond_syntax) is determined by the result of the contained logical expression. If cond_syntax is initial when the statement is executed, the logical expression is true.


Notes

  • It is possible to evaluate an internal table specified after FOR ALL ENTRIES in a logical expression since.

  • It is possible to check a selection table in a dynamic logical expression.

  • If cond_syntax is an internal table with a header line, the table body is evaluated, and not the header line.

  • Dynamic logic expressions can also be created interactively using free selections.

  • When a condition is specified dynamically, the syntax check can take place only at runtime. Therefore, specifying a logical condition at runtime needs more execution time than a corresponding specification in the program text.

  • The data objects specified in a dynamic condition should be declared in the same context, if possible, since searches in higher contexts at runtime are more unwieldy.

  • The class CL_ABAP_DYN_PRG contains methods that support the creation of correct and secure dynamic WHERE conditions.

Example

Creates a dynamic comparison from user input. In the case of incorrect syntax or incorrect semantics, exceptions are raised that are handled using the common superclass.

PARAMETERS: column   TYPE c LENGTH 8, 
            value  TYPE c LENGTH 30. 
DATA: spfli_wa TYPE spfli, 
      cond_syntax TYPE string. 

cond_syntax = column &&  ` = value`. 
TRY. 
    SELECT SINGLE * 
           FROM spfli 
           INTO spfli_wa 
           WHERE (cond_syntax). 
  CATCH cx_sy_dynamic_osql_error. 
    MESSAGE `Wrong WHERE condition!` TYPE 'I'. 
ENDTRY.