Feature Request: Replace EXIT with RETURN outside of loops
IF foo = 42.
EXIT.
ENDIF.
LOOP AT bar ASSIGNING FIELD-SYMBOL(<bar>).
IF <bar> = 42.
EXIT.
ENDIF.
ENDLOOP.
WRITE 'SOMETHING'.
The first EXIT should be replaced with RETURN (https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenexit_procedure_guidl.htm) the second one should not be replaced.
Hi Jan,
that's a very nice idea – and shouldn't be too difficult to implement!
Kind regards, Jörg-Michael
Note that replacing EXIT with RETURN inside an INCLUDE should probably be avoided. I've seen a lot of code where an INCLUDE is wrapped inside an a "DO 1 TIMES...ENDDO" to enable "return-like" behavior via use of EXIT. In this situation, replacing the EXIT with RETURN would also exit the Report and prevent execution of any subsequent code.
Example, replacing EXIT in sample below is not desireable:
REPORT Customer_Report.
DO 1 TIMES.
INCLUDE zcustomer_enhancement.
ENDDO.
INCLUDE functions01.
INCLUDE zcustomer_enhancement.
if is_enhancement_active( lv_company_code ) = abap_false.
exit.
endif.
"Enhancement logic below for company codes where it is activated.....
It's not pretty, but I understand why this technique is used because you can avoid having to wrap the whole code inside a big IF-condition.
Hi Samuli,
good point, thanks! I think like the rule "Convert CHECK outside loop to IF NOT ... RETURN", ABAP cleaner should only do changes here if it can actually "see" the METHOD statement (which it wouldn't in an include).
Kind regards, Jörg-Michael