Search code examples
abapopensql

Error DBIF_RSQL_INVALID_RSQL CX_SY_OPEN_SQL_DB in program


I get the following error: DBIF_RSQL_INVALID_RSQL CX_SY_OPEN_SQL_DB (Open SQL command is too big. Condition WHERE of the Open SQL command contains too many conditions). The error points to the following line:

select * from Z3T_MAILS into table t_full_mail UP TO 250 ROWS where ID in r_mid  and (p_dat_clause).

Other parts of code:

    DATA: p_dat_clause type STRING,
    t_full_mail type Z3TT_MAILS,
    r_mid       type range of Z3E_MAIL_ID.

 <...>

  if not NOT_READED is initial.
    p_clause = 'ISREAD = '''''.
  endif.

  if DATETO is initial.
    p_dateto = DATEFROM.
  else.
    p_dateto = DATETO.
  endif.
  if not DATEFROM is initial or not DATETO is initial.
    concatenate 'SEND_DATE >= ''' DATEFROM  ''' and SEND_DATE <= ''' p_dateto '''' into p_dat_clause.
  endif.

    <...>

      if MAILS is supplied  or  BODY is supplied  or  p_dat_clause ne ''.
        if not r_mid[] is initial.
          select * from Z3T_MAILS into table t_full_mail UP TO 250 ROWS where ID in r_mid  and (p_dat_clause).
        endif.
      endif.

I am new to ABAP and would appreciate any help!


Solution

  • That error happens when you use a range/select-option that has too many entries for the database to handle. The solution to this is always dependent on the use, but in any case you have to limit the number of entries in the range.

    In your case you only want up to 250 rows from the database anyway. So, if R_MID is filled with all rows containing a single ID you can check the number of lines in it (LINES( R_MID ) ) and limit it to 250 if there are more than that. In most systems this would get rid of the error.