2009 Feb 01 11:05 AM
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
2009 Feb 01 12:23 PM
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
2009 Feb 01 11:09 AM
Hi:
if ur condition is true then
RETURN.
endif.
Use the keyword RETURN.
2009 Feb 01 11:57 AM
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
2009 Feb 01 12:03 PM
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.
2009 Feb 01 12:23 PM
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