This website is not affiliated with, sponsored by, or approved by SAP AG.
Development (ABAP Development WorkBench, ABAP/4 programming)
11 posts • Page 1 of 1
I do a PERFORM to a routine. In that routine if a certain condtion exists, I want to exit out of the routine and go to the ENDFORM. Can this be done in ABAP?
select ..... from database table
if sy-dbcnt = 0.
stop doing any more code and drop out of the FORM.
Or use the else clause in the if statement, or re-write the if statement:
Multiple exit points from a function module or procedure is generally not good practice. There should be one entry point and one exit point for each routine, so:
EXIT will only leave the form when there is no other command structure (like a LOOP) open. In his example he suggested that he might be in a SELECT-ENDSELECT-loop, in which case EXIT would only leave that one, but not drop out of the form (meaning that after the loop, he would have to add more if-conditions that lead to additional EXIT(s) in order to leave the form).
The true answer to his question is not the EXIT command, but the RETURN command. RETURN exits the current FORM-Block no matter what, also leaving any current loops. RETURN does exactly what he wants. EXIT is equivalent only if he is not within a loop.
I disagree on that. SELECT... ENDSELECT is often a good way to program very well readable code. I remember the times of 3.1x-releases when SELECT...ENDSELECT was horribly slow, so that it was a good idea to do a SELECT INTO TABLE with a subsequent LOOP simply for performance reasons. I find that this is no longer necessary though, and SELECT...ENDSELECT is better readable than a JOIN or a subsequent LOOP.
As far as this thread is concerned, EXIT will not exit the current form in a LOOP as well (and you certainly agree that LOOPs are necessary in many cases). RETURN is the failsafe alternative.
We've certainly derailed this topic now!
My comment regarding select...endselect was an adjunct, not necessarily related to the EXIT issue.
I don't necessarily disagree with you. The best method to select from the database will indeed vary depending on factors such as volume of data and the level of subsequent processing required. There is a tradeoff between database performance and memory consumption.
For each iteration around a select-endselect loop you get two database accesses. For a select - into you only get two regardless of how many rows are returned. No contest in my book.
No doubt - I was just in no mood to start a debate!
11 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 9 guests