Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP query help

Former Member
0 Kudos

hi folks,

I have a query that is giving me a Run time Error and reason is databse commit is being called before the databse selection is completed.

I understood the error but I do not know how to solve it.

select * from ZEDMSTR.

if sy-subrc = 0.

rec-businessunit = ZEDMSTR-ZBUSUNIT.

rec-tablename = ZEDMSTR-ZTABNAME.

rec-oldlegcode = ZEDMSTR-ZOLDLEGCODE.

rec-description = ZEDMSTR-ZDESCRIPTION.

rec-newlawsoncode = ZEDMSTR-ZNEWLAWCODE.

WRITE: ' tHE RECORDS GOT APPENDED INTO THE TABLE'.

else.

exit.

endif.

append rec.

endselect.

The table ZEDMSTR HAS FIVE FIELDS (SAME NUMBER DECLARED FOR THE INTERNL TABLE 'REC') AND I HAVE TO PULL ALL THE RECORDS OF ALL THE FIELDS FROM THE TABLE INTO REC.

My question is how can I modify the select query to eliminate the runtime exception and without the use of select...endselect. because I shall be reading over 40,000 records from the query and it may raise a performance issue.

Thanks in advance for your help folks.

Vinu

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Vinu,

DATA : REC TYPE TABLE OF ZEDMSTR.

SELECT * FROM ZEDMSTR INTO CORRESPONDING FIELDS OF TABLE REC.

If you don't want to declare REC like that declare the way you want, but declare another table like the way I have done and loop at the table and move the records into REC table using a WORKAREA.

Regards,

Ravi

Note : Please close the thread if this solves the issue.

4 REPLIES 4

Former Member
0 Kudos

Vinu,

DATA : REC TYPE TABLE OF ZEDMSTR.

SELECT * FROM ZEDMSTR INTO CORRESPONDING FIELDS OF TABLE REC.

If you don't want to declare REC like that declare the way you want, but declare another table like the way I have done and loop at the table and move the records into REC table using a WORKAREA.

Regards,

Ravi

Note : Please close the thread if this solves the issue.

0 Kudos

Thanks guys for the input it really helped and solved the problem. I shall reward the points.

Vinu

Former Member
0 Kudos

Vinu,

First, you don't need a SY-SUBRC check within a select end-select loop. Your check should be outside the loop. Are you getting this error while you are debugging? When you are debugging, a select endselect loop sometimes results in this dump. If you put your breakpoint after the endselect, you will not get this dump.


select * from ZEDMSTR.
  rec-businessunit = ZEDMSTR-ZBUSUNIT.
  rec-tablename = ZEDMSTR-ZTABNAME.
  rec-oldlegcode = ZEDMSTR-ZOLDLEGCODE.
  rec-description = ZEDMSTR-ZDESCRIPTION.
  rec-newlawsoncode = ZEDMSTR-ZNEWLAWCODE.
  append rec.
endselect.
if sy-subrc <> 0. <-- put your breakpoint here
  write:/ 'No records selected.'.
else.
  write:/ 'Records are appended.'.
endif.

Former Member
0 Kudos

If you have coded a select and want to test the value of sy-subrc, your test must come after the endselect. Why? The answer lies in the fact that the code between the select and endselect is executed once for each row returned from the database.

If zero rows are returned from the database, the code between select and endselect is never executed. Therefore, you must code the test for sy-subrc after the endselect.