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

reports

Former Member
0 Likes
680

hi ,

in reports wat is the use of at new statement.all the possible ways to use this event.pls help me.

thanx

loki

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
655

Hi..

lets say itab with fields

f1,f2,f3,f4.

a 1 b z

b 1 c s

b 1 f v

loop at itab.

<b>At new f2.

write: / itab-f1,itab-f2,itab-f3,itab-f4.

endat.</b>

endloop.

<b>output:</b>

a 1 * *

b 1 * *

because <b>AT NEW f2</b> will trigger for every and any change of the fields of left side to the fiield f2.

<b>You can not access the fields right side to it. they will appear as * s.</b>

6 REPLIES 6
Read only

Former Member
0 Likes
655

AT - control break

Variants:

1. AT NEW f.

2. AT END OF f.

3. AT FIRST.

4. AT LAST.

Variant 1

AT NEW f.

Variant 2

AT END OF f.

Effect

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.

Read only

Former Member
0 Likes
655

these are loop break statements..

they are at first

at new

at end of

at last.

at new mean if a new record come what u need to do..

as long as u have same record it goes on.. when a new record come it goes to at end of..

at end of states at end of new record what ur need to do.

before all these u need to sort the internal table

Read only

Former Member
0 Likes
656

Hi..

lets say itab with fields

f1,f2,f3,f4.

a 1 b z

b 1 c s

b 1 f v

loop at itab.

<b>At new f2.

write: / itab-f1,itab-f2,itab-f3,itab-f4.

endat.</b>

endloop.

<b>output:</b>

a 1 * *

b 1 * *

because <b>AT NEW f2</b> will trigger for every and any change of the fields of left side to the fiield f2.

<b>You can not access the fields right side to it. they will appear as * s.</b>

Read only

0 Likes
655

hi nagam,

it means 3rd record ownt display, or it displays.any how 3rd field and 4th field wont

display.just clarify this pls

thanx

loki

Read only

0 Likes
655

I will tell you one example ,please see the below code,

tables : vbap.

data : begin of i_vbap occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

matnr like vbap-matnr,

kwmeng like vbap-kwmeng,

netpr like vbap-netpr,

end of i_vbap.

data wa_vbap like line of i_vbap.

data v_flag type c.

select-options s_vbeln for vbap-vbeln obligatory.

start-of-selection.

select vbeln

posnr

matnr

kwmeng

netpr from vbap

into table i_vbap

where vbeln in s_vbeln.

sort i_vbap by vbeln posnr.

end-of-selection.

loop at i_vbap.

move i_vbap to wa_vbap.

at first.

write:/2 'Order #',15 'Item #',28 'Material #',50 'Qty', 70 'Net value'.

skip 1.

endat.

at new vbeln.

write:/2 wa_vbap-vbeln,15 wa_vbap-posnr,28 wa_vbap-matnr,

47 wa_vbap-kwmeng,65 wa_vbap-netpr.

v_flag = 'X'.

endat.

if v_flag ne 'X'.

write:/15 wa_vbap-posnr,28 wa_vbap-matnr,

47 wa_vbap-kwmeng,65 wa_vbap-netpr.

endif.

at end of vbeln.

sum.

skip 1.

write:/5 'Sub totals', 47 i_vbap-kwmeng,65 i_vbap-netpr.

skip 1.

endat.

at last .

skip 1.

sum.

write:/5 'Grand Totals',47 i_vbap-kwmeng,65 i_vbap-netpr.

endat.

clear v_flag.

endloop.

We have two events called At new which we will be using within Internal Table ,and one more command On change of ( This one we can use anywhere).

One note : if you are working on Internal table events ,then try to use work area and pass the values from internal table to work area.

At new Command will trigger from Left to Right,while on change of will trigger from right-left.

reward Points if it is Helpful.

Thanks

Seshu

Read only

Former Member
0 Likes
655

Hi,

When you sort an extract dataset, control levels are defined in it. For general information about

control levels, refer to Processing Internal Tables in Loops [Page 299] The control level hierarchy

of an extract dataset corresponds to the sequence of the fields in the HEADER field group. After

sorting, you can use the AT statement within a loop to program statement blocks that the system

processes only at a control break, that is, when the control level changes.

AT NEW <f> | AT END OF <f>.

...

ENDAT.

A control break occurs when the value of the field <f> or a superior field in the current record has

a different value from the previous record (AT NEW) or the subsequent record (AT END). Field

<f> must be part of the HEADER field group.

If the extract dataset is not sorted, the AT... ENDAT block is never executed. Furthermore, all

extract records with the value HEX 00 in the field <f> are ignored when the control breaks are

determined.

The AT... ENDAT blocks in a loop are processed in the order in which they occur. This sequence

should be the same as the sort sequence. This sequence must not necessarily be the sequence

of the fields in the HEADER field group, but can also be the one determined in the SORT

statement.

If you have sorted an extract dataset by the fields <f1>, <f2>, ..., the processing of the control

levels should be written between the other control statements as follows:

LOOP.

AT FIRST.... ENDAT.

AT NEW <f1>....... ENDAT.

AT NEW <f2>....... ENDAT.

...

AT <fgi>..... ENDAT.

<single line processing without control statement>

...

AT END OF <f2>.... ENDAT.

AT END OF <f1>.... ENDAT.

AT LAST..... ENDAT.

ENDLOOP.

You do not have to use all of the statement blocks listed here, but only the ones you require.

REPORT DEMO.

DATA: T1(4), T2 TYPE I.

FIELD-GROUPS: HEADER.

INSERT T2 T1 INTO HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

T1 ='BBCC'. T2 = 2. EXTRACT HEADER.

T1 ='AAAA'. T2 = 2. EXTRACT HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

T1 ='BBCC'. T2 = 2. EXTRACT HEADER.

T1 ='AAAA'. T2 = 1. EXTRACT HEADER.

T1 ='BBBB'. T2 = 1. EXTRACT HEADER.

T1 ='AAAA'. T2 = 3. EXTRACT HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

SORT BY T1 T2.

LOOP.

AT FIRST.

WRITE 'Start of LOOP'.

ULINE.

ENDAT.

AT NEW T1.

WRITE / ' New T1:'.

ENDAT.

AT NEW T2.

WRITE / ' New T2:'.

ENDAT.

WRITE: /14 T1, T2.

AT END OF T2.

WRITE / 'End of T2'.

ENDAT.

AT END OF T1.

WRITE / 'End of T1'.

ENDAT.

AT LAST.

ULINE.

ENDAT.

ENDLOOP.

This program creates a sample extract, containing the fields of the HEADER field

group only. After the sorting process, the extract dataset has several control breaks

for the control levels T1 and T2.

Regards,

Bhaskar