Application Development and Automation 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: 
Read only

how to exit a form

Former Member
0 Likes
12,160

hi

is there a way to exit a form if some condition not happend ?

for example if a flag_var eq 0 i want the form to end

thanks

1 ACCEPTED SOLUTION
Read only

faisalatsap
Active Contributor
0 Likes
4,237

Hi, Ami bardogo

Test the following Sample code hope will solve out your problem,

TYPES: BEGIN OF t_test,
  sr_no TYPE i,
  name(35),
  flag(1),
END OF t_test.


DATA: it_test TYPE STANDARD TABLE OF t_test WITH HEADER LINE.

DO 5 TIMES.
  it_test-sr_no = sy-index.
  it_test-name = 'SDN'.
  APPEND it_test TO it_test.
ENDDO.
CLEAR: it_test.
it_test-flag = 'X'.

MODIFY it_test FROM it_test INDEX 4. " Set Flag on line number 4 of itab

PERFORM test.
*&---------------------------------------------------------------------*
*&      Form  test
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM test.
  LOOP AT it_test INTO it_test. " It will display three lines because before printing the 4th line it will exit from form
    IF it_test-flag = 'X'.
      RETURN. " you can use both Return and Exit Both are working here.
*      EXIT.
    ENDIF.
    WRITE : / it_test-sr_no , it_test-name.

  ENDLOOP.

ENDFORM.                    "test

Please Reply if any Issue.

Kind Regards,

Faisal

4 REPLIES 4
Read only

Former Member
0 Likes
4,237

Hi:

if ur condition is true then

RETURN.

endif.

Use the keyword RETURN.

Read only

valter_oliveira
Active Contributor
0 Likes
4,237

http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9b2535c111d1829f0000e829fbfe/frameset.htm

ABAP Programming->Running ABAP Programs->Subroutines->Terminating Subroutines


IF <condition>.
  EXIT.
ENDIF.

Or as Tahir said.


IF <condition>.
  RETURN.
ENDIF.

Regards,

Valter Oliveira

Read only

Former Member
0 Likes
4,237

Refer SAP help:

http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9b2535c111d1829f0000e829fbfe/frameset.htm

USE CHECK or EXIT statement to terminate a FORM ... ENDFORM...

Understand that CHECK or EXIT just terminate the immediate control block.

If you do EXIT in a loop like LOOP.. ENDLOOP, DO.. ENDDO etc, only the loop will be terminated and control continues with the statement after ENDLOOP or ENDDO statement. CHECK on the other hand just skips that particular iteration of the loop and the loop continues with the next iteration, if any.

you can do

CHECK <boolean expression>.

OR

IF <boolean expression>.
   EXIT.
ENDIF.

Read only

faisalatsap
Active Contributor
0 Likes
4,238

Hi, Ami bardogo

Test the following Sample code hope will solve out your problem,

TYPES: BEGIN OF t_test,
  sr_no TYPE i,
  name(35),
  flag(1),
END OF t_test.


DATA: it_test TYPE STANDARD TABLE OF t_test WITH HEADER LINE.

DO 5 TIMES.
  it_test-sr_no = sy-index.
  it_test-name = 'SDN'.
  APPEND it_test TO it_test.
ENDDO.
CLEAR: it_test.
it_test-flag = 'X'.

MODIFY it_test FROM it_test INDEX 4. " Set Flag on line number 4 of itab

PERFORM test.
*&---------------------------------------------------------------------*
*&      Form  test
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM test.
  LOOP AT it_test INTO it_test. " It will display three lines because before printing the 4th line it will exit from form
    IF it_test-flag = 'X'.
      RETURN. " you can use both Return and Exit Both are working here.
*      EXIT.
    ENDIF.
    WRITE : / it_test-sr_no , it_test-name.

  ENDLOOP.

ENDFORM.                    "test

Please Reply if any Issue.

Kind Regards,

Faisal