Ansicht
Dokumentation

ABAPDYNAMIC_LOGICAL_CONDITION - DYNAMIC LOGICAL CONDITION

ABAPDYNAMIC_LOGICAL_CONDITION - DYNAMIC LOGICAL CONDITION

PERFORM Short Reference   General Data in Customer Master  
This documentation is copyright by SAP AG.
SAP E-Book

Dynamic Logical Condition

Syntax



... (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

  • Cause: The database column whose values are to be averaged has no numeric type.
    Runtime Error: SAPSQL_HAVING_AVG_TYPE
  • Cause: The database column, whose values are to be used to work out the average, has no numeric type.
    Runtime Error: SAPSQL_HAVING_SUM_TYPE
  • Cause: A search string is not specified in a text literal.
    Runtime Error: SAPSQL_LIKE_VAL_TYPE
  • Cause: A token cannot be interpreted as a literal or as a valid variable name.
    Runtime Error: SAPSQL_WHERE_ILLEGAL_VALUE

CX_SY_DYNAMIC_OSQL_SYNTAX

  • Cause: After the lower comparison value of the operator BETWEEN, the keyword AND is missing.
    Runtime Error: SAPSQL_BETWEEN_MISSING_AND
  • Cause: The logical condition is bracketed incorrectly.
    Runtime Error: SAPSQL_HAVING_PARENTHESES
  • Cause: An unknown aggregate function was found.
    Runtime Error: SAPSQL_ILLEGAL_AGGREGATE
  • Cause: After the operator IS NULL, the keyword NULL does not follow.
    Runtime Error: SAPSQL_ILLEGAL_IS_NULL
  • Cause: In the operator IN, the brackets are incorrect.
    Runtime Error: SAPSQL_IN_ILLEGAL_LIST
  • Cause: The logical condition contains a text literal where the closing apostrophe (single quotation mark) is missing.
    Runtime Error: SAPSQL_LIKE_QUOTES
  • Cause: The logical condition ends unexpectedly.
    Runtime Error: SAPSQL_WHERE_MISSING_CONDITION
  • Cause: After the addition ESCAPE, there is no specification of the Escape character.
    Runtime Error: SAPSQL_WHERE_MISSING_ESCAPE
  • Cause: An operator is missing in the logical condition.
    Runtime Error: SAPSQL_WHERE_MISSING_OPERATOR
  • Cause: A literal or the name of an ABAP variable is missing in the logical condition.
    Runtime Error: SAPSQL_WHERE_MISSING_VALUE
  • Cause: The logical condition is bracketed incorrectly.
    Runtime Error: SAPSQL_WHERE_PARENTHESES
  • Cause: The logical condition contains a text literal where the closing apostrophe (single quotation mark) is missing.
    Runtime Error: SAPSQL_WHERE_QUOTES
  • Cause: An unknown operator is used in the logical condition.
    Runtime Error: SAPSQL_WHERE_UNKNOWN_OPERATOR


Additional help

Select Lines






BAL_S_LOG - Application Log: Log header data   BAL Application Log Documentation  
This documentation is copyright by SAP AG.

Length: 7850 Date: 20240418 Time: 070019     sap01-206 ( 65 ms )