Application Development 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: 

what happen if we use control break statements in btw select and endselect

Former Member
0 Kudos

what happen if we use control break statements in btw select and endselect

1 ACCEPTED SOLUTION

anversha_s
Active Contributor
0 Kudos

ON CHANGE OF 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 <b>GET events or SELECT/ENDSELECT</b> 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.

The AT statements refer to the field COMPANIES-NAME.

Reward Points if it helps

Anver

5 REPLIES 5

Former Member
0 Kudos

Hi,

Sorry. You cannot use this in between SELECT ... ENDSELECT

they are made to be used in LOOP.... ENDLOOP.

anversha_s
Active Contributor
0 Kudos

ON CHANGE OF 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 <b>GET events or SELECT/ENDSELECT</b> 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.

The AT statements refer to the field COMPANIES-NAME.

Reward Points if it helps

Anver

Former Member
0 Kudos

Hi

It will raise an error stating that control break statements should be used only within loop and endloop.

Regards

Haritha

Former Member
0 Kudos

Hi,

control break stmts are generally used to find sum,avg count etc done on grouping the fields.

for anything to be done, first we have to select the data into an internal table,then manipulate the data as reqd.

after fetching the data into internal table,

you shud sort the data first then do accordingly.

but using control break stmts inside select endselect,

i feel it as meaningless.

Regards,

Sowjanya.

Former Member
0 Kudos

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 ON change of between select endselect.

Best Regards,

Vibha

*Please mark all the helpful answers