Thursday 28 September 2017

ABAP: EXIT – Terminate loop unconditionally.

EXIT is used to come out of the loop, if you are from Java background, it is equivalent to break; statements in Java.

Z_HELLO_WORLD
*&---------------------------------------------------------------------*
*& Report Z_HELLO_WORLD
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_HELLO_WORLD.

DATA counter TYPE I VALUE -1.

WHILE counter < 10.
  counter = counter + 1.

  IF counter > 5.
    Write / 'Exiting from the loop'.
    EXIT.
  ENDIF.

  Write: / 'Value of counter : ', counter.
ENDWHILE.

Write / 'End of the loop'.


Previous                                                 Next                                                 Home

No comments:

Post a Comment