You can make use of function code which is assigned to push button with “Exit” as function type and an event “AT SELECTION-SCREEN ON EXIT-COMMAND” to achieve this.
A call is made to this event to validate the fields on the screen and you can implement all logic here.