zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Working with EXIT, STOP, CONTINUE and RETURN in SAP ABAP详解编程语言

SAP编程语言 详解 in with and ABAP return
2023-06-13 09:11:52 时间
Learn how to use STOP, EXIT, CONTINUE and RETURN commands in SAP ABAP, difference between STOP, EXIT, CONTINUE and RETURN in SAP ABAP.

In our day to day ABAP programming implementations, we may need to use exit, continue, stop and return statements, this article will help you to understand what are exit, stop, continue and return statements? And when do we use them.

EXIT

The behavior of EXIT keyword is depends on where you use it.

If you use EXIT keyword inside IF .. ENDIF., it will comes out of the program. If you use EXIT inside LOOP .. ENDLOOP., it will come out of loop. If you use EXIT inside FORM .. ENDFORM., it will comes out of form (subroutine).

Example program os using EXIT keyword

REPORT ZSAPN_EXIT. 

DATA: IT_MARA TYPE TABLE OF MARA, 

 WA_MARA TYPE MARA. 

PARAMETERS: P_MATNR TYPE MARA-MATNR. 

START-OF-SELECTION. 

 SELECT SINGLE * FROM MARA INTO WA_MARA WHERE MATNR = P_MATNR. 

 IF WA_MARA IS INITIAL. 

 EXIT. “exit program 

 ENDIF. 

 WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL. 

STOP

STOP is a statement which is used to stop processing an event block, ex: If I have two events START-OF-SELECTION and END-OF-SELECTION in my program, If I use STOP keyword in START-OF-SELECTION, the keyword will exits start-of-selection and goes to END-OF-SELECTION.

See the difference between below two programs.


CONTINUE

CONTINUE is a statement, which is used to skip execution of a record inside loop.. endloop, do..endo, while..endwhile etc. This keyword will only be used in loops.

REPORT ZSAPN_CONTINUE. 

DATA: IT_MARA TYPE TABLE OF MARA, 

 WA_MARA TYPE MARA. 

START-OF-SELECTION. 

 SELECT * FROM MARA INTO TABLE IT_MARA UP TO 50 ROWS. 

 LOOP AT IT_MARA INTO WA_MARA. 

 IF WA_MARA-MTART = HALB. "Don’t print if material type is HALB 

 CONTINUE. “Skip the record and go for next record 

 ENDIF. 

 WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL. 

 ENDLOOP. 

In the above program, the output will not display materials of type ‘HALB’ because loop skips the records with HALB material type.

RETURN

RETURN is a statement which is used to stop processing of current block immediately.

Execute and see the difference between the below two programs.


Result: NO OUTPUT RESULT: SOME RECORDS as program execution stops after ‘HALB’ material type.

20136.html

cgo