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: 

internal table control events and difference

Former Member
0 Kudos

hi

i want to know abt internal table contrl events like at new at end of etc

there are abt five events please let me know all five and diffrence between all and where can we use sum for this events also there is a fifth event please let me know its name and difference from at new

at new

at endof

at last

at first

? fifth?

regards

nishant

1 ACCEPTED SOLUTION

paruchuri_nagesh
Active Contributor
0 Kudos

hi

look at this program

REPORT zinternaltable.

TYPES:BEGIN OF itab,

num TYPE i,

name(10) TYPE c,

amt type i,

END OF itab.

DATA : wa_itab TYPE itab,

it_itab TYPE STANDARD TABLE OF itab.

DATA : v_lines TYPE i.

wa_itab-num = 1.

wa_itab-name = 'nag'.

wa_itab-amt = 1000.

append wa_itab TO it_itab.

wa_itab-num = 1.

wa_itab-name = 'nag'.

wa_itab-amt = 2000.

append wa_itab TO it_itab.

wa_itab-num = 1.

wa_itab-name = 'nag'.

wa_itab-amt = 1500.

append wa_itab TO it_itab.

wa_itab-num = 2.

wa_itab-name = 'sri'.

wa_itab-amt = 500.

append wa_itab tO it_itab.

wa_itab-num = 2.

wa_itab-name = 'sri'.

wa_itab-amt = 600.

append wa_itab TO it_itab.

wa_itab-num = 2.

wa_itab-name = 'sri'.

wa_itab-amt = 700.

append wa_itab TO it_itab.

wa_itab-num = 3.

wa_itab-name = 'ganesh'.

wa_itab-amt = 1200.

append wa_itab TO it_itab.

wa_itab-num = 3.

wa_itab-name = 'ganesh'.

wa_itab-amt = 1300.

append wa_itab TO it_itab.

wa_itab-num = 3.

wa_itab-name = 'ganesh'.

wa_itab-amt = 1400.

append wa_itab TO it_itab.

wa_itab-num = 4.

wa_itab-name = 'suresh'.

wa_itab-amt = 900.

append wa_itab TO it_itab.

wa_itab-num = 4.

wa_itab-name = 'suresh'.

wa_itab-amt = 300.

append wa_itab TO it_itab.

sort it_itab.

LOOP AT it_itab INTO wa_itab.

at first.

write 😕 'details of sales order:'.

uline.

endat.

at new num.

write 😕 'serial num:', wa_itab-num.

uline.

endat.

WRITE 😕 wa_itab-num , wa_itab-name , wa_itab-amt.

at end of num.

uline.

sum.

write 😕 'total amount:',wa_itab-amt.

uline.

endat.

*

at last.

sum.

uline.

write:/ 'grand total:',wa_itab-amt.

endat.

ENDLOOP.

describe table it_itab lines v_lines.

another control break statement is

on change of: u can use this one out side of the loop

means in select endselect u can use this one

reward for use ful points

Regards

Nagesh.Paruchuri

3 REPLIES 3

paruchuri_nagesh
Active Contributor
0 Kudos

hi

look at this program

REPORT zinternaltable.

TYPES:BEGIN OF itab,

num TYPE i,

name(10) TYPE c,

amt type i,

END OF itab.

DATA : wa_itab TYPE itab,

it_itab TYPE STANDARD TABLE OF itab.

DATA : v_lines TYPE i.

wa_itab-num = 1.

wa_itab-name = 'nag'.

wa_itab-amt = 1000.

append wa_itab TO it_itab.

wa_itab-num = 1.

wa_itab-name = 'nag'.

wa_itab-amt = 2000.

append wa_itab TO it_itab.

wa_itab-num = 1.

wa_itab-name = 'nag'.

wa_itab-amt = 1500.

append wa_itab TO it_itab.

wa_itab-num = 2.

wa_itab-name = 'sri'.

wa_itab-amt = 500.

append wa_itab tO it_itab.

wa_itab-num = 2.

wa_itab-name = 'sri'.

wa_itab-amt = 600.

append wa_itab TO it_itab.

wa_itab-num = 2.

wa_itab-name = 'sri'.

wa_itab-amt = 700.

append wa_itab TO it_itab.

wa_itab-num = 3.

wa_itab-name = 'ganesh'.

wa_itab-amt = 1200.

append wa_itab TO it_itab.

wa_itab-num = 3.

wa_itab-name = 'ganesh'.

wa_itab-amt = 1300.

append wa_itab TO it_itab.

wa_itab-num = 3.

wa_itab-name = 'ganesh'.

wa_itab-amt = 1400.

append wa_itab TO it_itab.

wa_itab-num = 4.

wa_itab-name = 'suresh'.

wa_itab-amt = 900.

append wa_itab TO it_itab.

wa_itab-num = 4.

wa_itab-name = 'suresh'.

wa_itab-amt = 300.

append wa_itab TO it_itab.

sort it_itab.

LOOP AT it_itab INTO wa_itab.

at first.

write 😕 'details of sales order:'.

uline.

endat.

at new num.

write 😕 'serial num:', wa_itab-num.

uline.

endat.

WRITE 😕 wa_itab-num , wa_itab-name , wa_itab-amt.

at end of num.

uline.

sum.

write 😕 'total amount:',wa_itab-amt.

uline.

endat.

*

at last.

sum.

uline.

write:/ 'grand total:',wa_itab-amt.

endat.

ENDLOOP.

describe table it_itab lines v_lines.

another control break statement is

on change of: u can use this one out side of the loop

means in select endselect u can use this one

reward for use ful points

Regards

Nagesh.Paruchuri

Former Member
0 Kudos

<b>CONTROL STATEMENTS.</b>

Control Break Statements

Control break statements are used to create statement blocks which process only specific table lines the LOOP – ENDLOOP block.

You open such a statement block with the control level statement AT and close it with the control level statement ENDAT. The syntax is as follows:

Table should be sorted when you use control-break statements

You can break the sequential access of internal tables by using these statements.

Syntax:

At first.

<Statement block>

Endat.

This is the first statement to get executed inside the loop (remember control break statements are applicable only inside the loop)

So in this block you can write or process those statements which you want to get executed when the loop starts.

At New carrid.

Write:/ carrid.

Endat.

In this case whenever the new carrid is reached, carrid will be written.

At End of carrid.

Uline.

Endat.

In this case whenever the end of carrid is reached, a line will be drawn.

At Last.

Write:/ ‘Last Record is reached’.

Endat.

Processing of statements within this block is done when entire processing of entire internal table is over. Usually used to display grand totals.

You can use either all or one of the above control break statements with in the loop for processing internal table.

At end of carrid.

Sum.

Endat.

In above case the statement SUM (applicable only within AT-ENDAT) will sum up all the numeric fields in internal table and result is stored in same internal table variable.

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

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.

Check the below thread for more details.

Regards,

maha

0 Kudos

hi maha

what is the difference between on change of and at new?

regards

rinku