Dynamic Logical Condition

Basic form



... (source_text)

Effect

In Open SQL, you can dynamically specify, at runtime, the logical conditions of the WHERE clause , the HAVING clause, as well as the ON conditions of the FROM clause in a variable source_text as ABAP source text. The condition is true if the contents of the table fields satisfy the logical condition stored in the source_text variable.

Notes

  1. The logical conditions stored in source_text must have the same form as corresponding conditions in the ABAP source text. However, the operator must not be used in the form f1 IN itab1.

  2. source_text may be empty. The condition is then interpreted as the constant TRUE. In particular, caution is advised if you use the addition ... WHERE (source_text) together with a DELETE or UPDATE statement!

Notes

Performance:

  1. The syntax check cannot start until runtime. For this reason, specifying a logical condition at runtime requires a little more execution time than specifying it in the program text.

  2. Searching for variable names in the runtime environment requires effort. If you use an ABAP variable as the value, you should therefore define them in the current context, if possible.


Example

Display of flight connections after input of airline and flight number:


PARAMETERS: carr_id TYPE spfli-carrid,
            conn_id TYPE spfli-connid.

DATA:       where_clause TYPE  STRING,
            and(4),
            wa_spfli TYPE spfli.

IF carr_id IS NOT INITIAL.
  CONCATENATE 'CARRID = ''' carr_id '''' INTO where_clause.
  and = ' AND'.
ENDIF.
IF conn_id IS NOT INITIAL.
  CONCATENATE where_clause and ' CONNID = ''' conn_id ''''
    INTO where_clause.
ENDIF.

SELECT * FROM spfli INTO wa_spfli WHERE (where_clause).
  WRITE: / wa_spfli-carrid, wa_spfli-connid, wa_spfli-cityfrom,
           wa_spfli-cityto, wa_spfli-deptime.
ENDSELECT.

During the grammatical analysis of the source text in source_text, the following exceptions can occur:

Exceptions

Catchable Exceptions

CX_SY_DYNAMIC_OSQL_SEMANTICS

CX_SY_DYNAMIC_OSQL_SYNTAX

Additional help

Select Lines