简体   繁体   中英

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!

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.

I'm just guessing here but your range r_mid probably has hundreds of lines that look like this:

r_mid-sign   = 'I'.
r_mid-option = 'EQ'.
r_mid-low    = '123123123'.
r_mid-high   = ''.

So instead you could store those IDs in an internal table. You even might be able to use the internal table you're looping over to fill r_mid in the first place.

Your date variables on the other hand are actually well suited to be declared as a single range:

 r_date-sign   = 'I'.
 r_date-option = 'BT'. 
 r_date-low    = datefrom.
 r_date-high   = dateto.

Also note the documentation about ranges.

Finally you can write your query as follows:

SELECT *
   FROM z3t_mails
   INTO TABLE t_full_mail
   FOR ALL ENTRIES IN lt_mid
   WHERE id EQ lt_mid-id
   AND send_date IN r_date.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM