Você está na página 1de 7

Control break processing is used to execute a piece of code whenever a specific condition in the data is detected during the

processing of internal table loop. The following control break statements are available with in LOOP and ENDLOOP.

AT FIRST / ENDAT AT LAST / ENDAT AT NEW / ENDAT AT END OF / ENDAT SUM ON CHANGE OF / ENDON

The code between AT NEW and ENDAT is executed only during the first loop pass. So it is used to write the headers or some other initialization processing. The code between AT LAST and ENDAT is executed only during the last loop pass. So it is used to write the totals or some report footers. ** *Data Declaration * *
DATA: gwa_spfli TYPE spfli. DATA: gt_spfli TYPE TABLE OF spfli.

*UP TO 5 ROWS addition selects only 5 rows from table SPFLI


SELECT * UP TO 5 ROWS FROM spfli INTO TABLE gt_spfli. LOOP AT gt_spfli INTO gwa_spfli.

AT FIRST.
WRITE:/ WRITE:/ WRITE:/ 29 ULINE. 'Start of Loop'. 'Flight Details'. 'Airline Code' COLOR 5,14 'Connection No.' COLOR 5, 'Departure City' COLOR 5, 44 'Arival City' COLOR 5.

ENDAT.
WRITE:/ gwa_spfli-carrid,14 gwa_spfli-connid, 29 gwa_spfli-cityfrom,44 gwa_spfli-cityto.

AT LAST.
ULINE. WRITE:/ 'End of Loop'.

ENDAT.

ENDLOOP.

Output

Between AT FIRST and ENDAT the work area will not contain any data. The default key fields are filled with asterisks(*) and the numeric fields are filled with zeros. The ENDAT restores the contents to the values they had prior to entering the AT FIRST. Changes to the work area within AT FIRST and ENDAT are lost. The same applies for AT LAST and ENDAT. ** *Data Declaration * *
DATA: gwa_spfli TYPE spfli. DATA: gt_spfli TYPE TABLE OF spfli.

*UP TO 5 ROWS addition selects only 5 rows from table SPFLI


SELECT * UP TO 5 ROWS FROM spfli INTO TABLE gt_spfli. LOOP AT gt_spfli INTO gwa_spfli. AT FIRST. WRITE:/ 'Flight Details'. WRITE:/ 'Airline Code' COLOR 5,14 'Connection No.' COLOR 5, 29 'Departure City' COLOR 5, 44 'Arival City' COLOR 5, 58 'Distance' COLOR 5.

WRITE:/ gwa_spfli-carrid,14 gwa_spfli-connid, 29 gwa_spfli-cityfrom,44 gwa_spflicityto, 58 gwa_spfli-distance.


ULINE. ENDAT. WRITE:/ gwa_spfli-carrid,14 gwa_spfli-connid, 29 gwa_spfli-cityfrom,44 gwa_spfli-cityto, 58 gwa_spfli-distance. AT LAST.

ULINE.

WRITE:/ gwa_spfli-carrid,14 gwa_spfli-connid, 29 gwa_spfli-cityfrom,44 gwa_spflicityto, 58 gwa_spfli-distance.


WRITE:/ 'End of Loop'. ENDAT. ENDLOOP.

Output

AT NEW and ENDAT is used to detect a change in the value of the field between the loop passes. The field that is specified in AT NEW is called control level. The code between AT NEW and ENDAT will be executed during the first loop pass and every time the value of the control level changes or any other field left to the control level changes. Between AT NEW and ENDAT all the fields in the work area that are right to the control level are filled with zeros and asterisks. Similarly The code between AT END OF and ENDAT will be executed during the last loop pass and every time the value of the control level changes or any other field left to the control level changes. ** *Data Declaration * *
DATA: gwa_spfli TYPE spfli. DATA: gt_spfli TYPE TABLE OF spfli. SELECT * UP TO 5 ROWS FROM spfli INTO TABLE gt_spfli. LOOP AT gt_spfli INTO gwa_spfli. AT FIRST. WRITE:/ 'Flight Details'. WRITE:/ 'Airline Code' COLOR 5,14 'Connection No.' COLOR 5, 29 'Departure City' COLOR 5, 44 'Arival City' COLOR 5,

58 'Distance' COLOR 5. ULINE. ENDAT.

AT NEW carrid. WRITE:/ gwa_spfli-carrid, : New Airline. ULINE. ENDAT.


WRITE:/14 gwa_spfli-connid, 29 gwa_spfli-cityfrom,44 gwa_spfli-cityto, 58 gwa_spfli-distance.

AT END OF carrid. ULINE. WRITE:/ End of Airline : , gwa_spfli-carrid. ULINE. ENDAT.


AT LAST. WRITE:/ 'End of Loop'. ENDAT. ENDLOOP.

Output

In AT FIRST and AT LAST event blocks the numeric values in the work area contains zeros. SUM statement calculates the totals of numeric fields and places the totals in the corresponding fields of work area. In AT NEW and AT END OF event blocks SUM statement finds all the rows within the control level and calculates the totals of numeric fields that are right to the control level and places the totals in the corresponding fields of work area.

** *Data Declaration * *
DATA: gwa_spfli TYPE spfli. DATA: gt_spfli TYPE TABLE OF spfli. SELECT * UP TO 5 ROWS FROM spfli INTO TABLE gt_spfli. LOOP AT gt_spfli INTO gwa_spfli. AT FIRST. WRITE:/ 'Flight Details'. WRITE:/ 'Airline Code' COLOR 5,14 'Connection No.' COLOR 5, 29 'Departure City' COLOR 5, 44 'Arival City' COLOR 5, 58 'Distance' COLOR 5. ULINE. ENDAT. AT NEW carrid. WRITE:/ gwa_spfli-carrid, ' : New Airline'. ULINE. ENDAT. WRITE:/14 gwa_spfli-connid,29 gwa_spfli-cityfrom, 44 gwa_spfli-cityto,58 gwa_spfli-distance. AT END OF carrid. ULINE.

SUM.
WRITE:/ gwa_spfli-carrid,58 gwa_spfli-distance. ULINE. ENDAT. AT LAST.

SUM.
WRITE:/ 'Total',58 gwa_spfli-distance. WRITE:/ 'End of Loop'. ENDAT. ENDLOOP.

Output

ON CHANGE OF behaves similar to AT NEW. The syntax is as follows.


ON CHANGE OF <control level1> [or <control level2> . .]. [ELSE.] ENDON.

** *Data Declaration * *
DATA: gwa_spfli TYPE spfli. DATA: gt_spfli TYPE TABLE OF spfli. SELECT * UP TO 5 ROWS FROM spfli INTO TABLE gt_spfli. LOOP AT gt_spfli INTO gwa_spfli. AT FIRST. WRITE:/ 'Flight Details'. WRITE:/ 'Airline Code' COLOR 5,14 'Connection No.' COLOR 5, 29 'Departure City' COLOR 5, 44 'Arival City' COLOR 5, 58 'Distance' COLOR 5. ULINE. ENDAT.

ON CHANGE OF gwa_spfli-carrid. WRITE:/ gwa_spfli-carrid, : New Airline. ULINE. ENDON.

WRITE:/14 gwa_spfli-connid,29 gwa_spfli-cityfrom, 44 gwa_spfli-cityto,58 gwa_spfli-distance. ENDLOOP.

Output

Below table summarizes the differences between AT NEW and ON CHANGE OF statements. AT NEW It can be used only in AT LOOP statement. Only one control field can be used. AT NEW is triggered when a field left to control level changes. Values in the fields to the right of control level contains asterisks and zeros. ELSE addition cannot be used. Changes to work area with AT NEW will be lost. ON CHANGE OF It can be used in any loop like SELECT, DO etc.. Multiple control fields separated by OR can be used. ON CHANGE OF is not triggered when a field left to control level changes. Values in the fields to the right of control level contains original values. ELSE addition can be used. Changes to work area with ON CHANGE OF will not be lost.

Você também pode gostar