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

Control Break

Former Member
0 Likes
780

HI

What happens if I use control break statement in between select & endselect?

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
746

Only <b>ON CHANGE OF</b> can be used in select statement, other control breaks cannot be used

select matnr from mara into v_matnr.
 ON CHANGE OF MATNR.
   write : / v_matnr.
 ENDON.
endselect.

5 REPLIES 5
Read only

Former Member
0 Likes
746

Hi,

They are used only with respect to Internal Tables (not between Select...endselect)to calculate Totals for Qty and Amount fields based on certain key fields

see the doc;

AT - Control break with internal tables

Variants

1. AT NEW f.

2. AT END OF f.

3. AT FIRST.

4. AT LAST.

Effect

In a LOOP which processes a dataset created with EXTRACT , you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT . The sequence of statements which lies between them is then executed if a control break occurs.

You can use these key words for control break processing with extract datasets only if the active LOOP statement is proceesing an extract dataset.

The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted .

At the start of a new control level (i.e. immediately after AT ), the following occurs in the output area of the current LOOP statement:

All default key fields (on the right) are filled with "*" after the current control level key.

All other fields (on the right) are set to their initial values after the current control level key.

Between AT and ENDAT , you can use SUM to insert the appropriate control totals in the number fields (see also ABAP/4 number types ) of the LOOP output area (on the right) after the current control level key. Summing is supported both at the beginning of a control level ( AT FIRST , AT NEW f ) and also the end of a control level ( AT END OF f , AT LAST ).

At the end of the control level processing (i.e. after ENDAT ), the old contents of the LOOP output area are restored.

Notes

When calculating totals, you must ensure that the totals are inserted into the same sub-fields of the LOOP output area as those where the single values otherwise occur. If there is an overflow, processing terminates with a runtime error.

If an internal table is processed only in a restricted form (using the additions FROM , TO and/or WHERE with the LOOP statement), you should not use the control structures for control level processing because the interaction of a restricted LOOP with the AT statement is currenly not properly defined.

With LOOP s on extracts, there are also special control break control structures you can use.

DATA: sflight_tab TYPE SORTED TABLE OF sflight

WITH UNIQUE KEY carrid connid fldate,

sflight_wa LIKE LINE OF sflight_tab.

SELECT *

FROM sflight

INTO TABLE sflight_tab.

LOOP AT sflight_tab INTO sflight_wa.

AT NEW connid.

WRITE: / sflight_wa-carrid,

sflight_wa-connid.

ULINE.

ENDAT.

WRITE: / sflight_wa-fldate,

sflight_wa-seatsocc.

AT END OF connid.

SUM.

ULINE.

WRITE: / 'Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

SKIP.

ENDAT.

AT END OF carrid.

SUM.

ULINE.

WRITE: / 'Carrier Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

NEW-PAGE.

ENDAT.

AT LAST.

SUM.

WRITE: / 'Overall Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

ENDAT.

ENDLOOP.

reward if useful

regards,

Anji

Message was edited by:

Anji Reddy Vangala

Read only

Former Member
0 Likes
747

Only <b>ON CHANGE OF</b> can be used in select statement, other control breaks cannot be used

select matnr from mara into v_matnr.
 ON CHANGE OF MATNR.
   write : / v_matnr.
 ENDON.
endselect.

Read only

Former Member
0 Likes
746

Hi,

It doesnt allow to write at new or at end of between select and endselect.

It gives error saying that at end or at new should be used between loop...endloop.

But it allows you to make use ON change of between select endselect.

<b>ON CHANGE OF</b> f.

Executes the processing block enclosed by the "ON CHANGE OF f" and "ENDON" statements whenever the contents of the field f change (control break processing).

Normally, you use the statement to manipulate database fields during GET events or SELECT/ENDSELECT processing.

ON CHANGE OF is unsuitable for recognizing control levels in loops of this type because it always creates a global auxiliary field which is used to check for changes. This global auxiliary field is only changed in the relevant ON CHANGE OF statement. It is not reset when the processing enters loops or subroutines, so unwanted effects can occur if the loop or subroutine is executed again. Also, since it is set to its initial value when created (like any other field), any ON CHANGE OF processing will be executed after the first test, unless the contents of the field concerned happen to be identical to the initial value.


DATA T100_WA TYPE T100.
SELECT * FROM T100
INTO T100_WA
WHERE SPRSL = SY-LANGU AND
MSGNR < '010'
ORDER BY PRIMARY KEY.
ON CHANGE OF T100_WA-ARBGB.
ULINE.
WRITE: / '***', T100_WA-ARBGB, '***'.
ENDON.
WRITE: / T100_WA-MSGNR, T100_WA-TEXT.
ENDSELECT.

Displays all messages with their numbers in the logon language, provided the number is less than '010'.

Each time the message class changes, it is output.

AT END OF f.

f is a sub-field of an internal table or extract dataset (EXTRACT) which is being processed with LOOP, i.e. the variants 1 and 2 only make sense within a LOOP.

Both "AT NEW f." and "AT END OF f. " introduce processing blocks which are concluded by " ENDAT.".

These processing blocks are processed whenever the contents of a field f or a sub-field defined before f change as a result of processing with LOOP. "AT NEW f." begins a new group of (table) lines with the same contents as the field f while "AT END OF f." concludes such a group.

Within the AT ... ENDAT processing of internal tables, all argument fields following f are filled with "*".

Examples

1. AT for sub-fields of an internal table

DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.
...
LOOP AT COMPANIES.
AT NEW NAME.
NEW-PAGE.
WRITE / COMPANIES-NAME.
ENDAT.
WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.
AT END OF NAME.
SUM.
WRITE: / COMPANIES-NAME, COMPANIES-SALES.
ENDAT.
ENDLOOP.

Message was edited by:

Santosh Kumar Patha

Read only

Former Member
0 Likes
746

Hi,

We can not use the Control break statments with in the Select and endselect. We need to use these statments with in the LOOP and ENDLOOP.

If you use the Control break statments with in the Select then this will give you an error message.

Regards

Sudheer

Read only

Former Member
0 Likes
746

U cant Use Control break events with select ... endselect . They are meant for internal tables only.