‎2011 Apr 01 8:00 AM
Hi All,
i'm getting error 'SQL error in the database when accessing a table' when process below sql for no's of entries
data :qfrom type string , count type i.
"qfrom = 'DD01L INNER JOIN DD02L ON DD02LAS4LOCAL = DD01LAS4LOCAL AND DD02LAS4VERS = DD01LAS4VERS".
select count(*) into count from (qfrom) .
write: count.
but for other sql like below one it's working fine...
*qfrom = 'mara INNER JOIN mard ON mardmatnr = maramatnr AND mardpstat = marapstat'.
select count(*) into count from (qfrom) .
write: count.
Runtime Errors DBIF_RSQL_SQL_ERROR
Except. CX_SY_OPEN_SQL_DB
Regards,
Anuj jain
‎2011 Apr 01 9:27 AM
Hello Anuj,
This is because the COUNT(*) is returning a value which is longer than the INT4 data type it is expecting. If you restrict the selection by introducing a WHERE clause, then you won't get the dump:
DATA: dyn_from TYPE string,
dyn_where TYPE string,
gx_sql_err TYPE REF TO cx_sy_open_sql_error,
gv_text TYPE string.
dyn_from = `DD01L INNER JOIN DD02L ON DD02L~AS4LOCAL = DD01L~AS4LOCAL AND DD02L~AS4VERS = DD01L~AS4VERS`.
dyn_where = `DOMNAME LIKE 'Z%'`.
TRY .
SELECT COUNT(*) FROM (dyn_from) WHERE (dyn_where).
WRITE: / sy-dbcnt NO-GROUPING.
CATCH: cx_sy_open_sql_db INTO gx_sql_err,
cx_sy_dynamic_osql_semantics INTO gx_sql_err,
cx_sy_dynamic_osql_syntax INTO gx_sql_err.
ENDTRY.
IF gx_sql_err IS BOUND.
gv_text = gx_sql_err->get_text( ).
WRITE: / gv_text.
ENDIF.BR,
Suhas
‎2011 Apr 01 10:16 AM
That's ok Suhas...but can i get this value which is more than int4 length in any method without defined any where like
data: count type string.
SELECT COUNT(*) into count FROM (dyn_from) WHERE (dyn_where).
or we can not get any return value whose length is more than int4 becoz it's dependent on sy-dbcnt whose data type is int4.
Regards ,
Anuj jain
‎2011 Apr 01 10:32 AM
Hello Anuj,
A quick F1 on COUNT(*) will tell you that it expects a variable of type INT4.
BR,
Suhas
‎2011 Apr 01 10:36 AM
‎2011 Apr 01 11:06 AM