2007 Feb 21 5:06 AM
hi all,
i want sample program by using this events,
1. AT NEW f.
2. AT END OF f.
3. AT FIRST.
4. AT LAST.
so that i can understand better .
hi all,
i want sample program by using this events,
1. AT NEW f.
2. AT END OF f.
3. AT FIRST.
4. AT LAST.
so that i can understand better .
2007 Feb 21 5:08 AM
Hi,
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.
Note
Runtime errors
SUM_OVERFLOW : Overflow when calculating totals with SUM .
Variant 1
AT NEW f.
Variant 2
AT END OF f.
Effect
f is a sub-field of an internal table processed with LOOP . The sequence of statements which follow it is executed if the sub-field f or a sub-field in the current LOOP line defined (on the left) before f has a differnt value than in the preceding ( AT NEW ) or subsequent ( AT END OF ) table line.
Example
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 .
Notes
If a control break criterion is not known until runtime, you can use AT NEW (name) or AT END OF (name) to specify it dynamically as the contents of the field name . If name is blank at runtime, the control break criterion is ignored and the sequence of statements is not executed. If name contains an invalid component name, a runtime error occurs.
By defining an offset and/or length, you can further restrict control break criteria - regardless of whether they are specified statically or dynamically.
A field symbol pointing to the LOOP output area can also be used as a dynamic control break criterion. If the field symbol does not point to the LOOP output area, a runtime error occurs.
Note
Runtime errors
AT_BAD_PARTIAL_FIELD_ACCESS : Invalid sub-field access when dynamically specifying the control break criterion.
AT_ITAB_FIELD_INVALID : When dynamically specifying the control break criterion via a field symbol, the field symbol does not point to the LOOP output area.
ITAB_ILLEGAL_COMPONENT : When dynamically specifying the control break criterion via (name) the field name does not contain a valid sub-field name.
Variant 3
AT FIRST.
Variant 4
AT LAST.
Effect
Executes the appropriate sequence of statements once during the first ( AT FIRST ) or last ( AT LAST ) loop pass.
Example
DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.
...
LOOP AT COMPANIES.
AT FIRST.
SUM.
WRITE: 'Sum of all SALES:',
55 COMPANIES-SALES.
ENDAT.
WRITE: / COMPANIES-NAME, COMPANIES-PRODUCT,
55 COMPANIES-SALES.
ENDLOOP.
Regards
Shiva
2007 Feb 21 5:10 AM
Hi,
Go through this example.
For further help go through the SAP help.
NODES: spfli, sflight.
FIELD-GROUPS: header, flight_info, flight_date.
START-OF-SELECTION.
INSERT: spfli-carrid spfli-connid sflight-fldate
INTO header,
spfli-cityfrom spfli-cityto
INTO flight_info.
GET spfli.
EXTRACT flight_info.
GET sflight.
EXTRACT flight_date.
END-OF-SELECTION.
SORT STABLE.
LOOP.
AT FIRST.
WRITE / 'Flight list'.
ULINE.
ENDAT.
AT flight_info WITH flight_date.
WRITE: / spfli-carrid , spfli-connid, sflight-fldate,
spfli-cityfrom, spfli-cityto.
ENDAT.
AT flight_date.
WRITE: / spfli-carrid , spfli-connid, sflight-fldate.
ENDAT.
AT LAST.
ULINE.
WRITE: cnt(spfli-carrid), 'Airlines'.
ULINE.
ENDAT.
ENDLOOP.
Regards,
Anji
2007 Feb 21 5:10 AM
Samara,
Pls. go through the explanation and example program.
*********************************************************************
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 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 ='BBBB'. T2 = 2. 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.
Pls. Mark if useful..........
2007 Feb 21 5:11 AM
Hi,
See the below program.
NODES: spfli, sflight.
FIELD-GROUPS: header, flight_info, flight_date.
START-OF-SELECTION.
INSERT: spfli-carrid spfli-connid sflight-fldate
INTO header,
spfli-cityfrom spfli-cityto
INTO flight_info.
GET spfli.
EXTRACT flight_info.
GET sflight.
EXTRACT flight_date.
END-OF-SELECTION.
SORT STABLE.
LOOP.
AT FIRST.
WRITE / 'Flight list'.
ULINE.
ENDAT.
AT flight_info WITH flight_date.
WRITE: / spfli-carrid , spfli-connid, sflight-fldate,
spfli-cityfrom, spfli-cityto.
ENDAT.
AT flight_date.
WRITE: / spfli-carrid , spfli-connid, sflight-fldate.
ENDAT.
AT LAST.
ULINE.
WRITE: cnt(spfli-carrid), 'Airlines'.
ULINE.
ENDAT.
ENDLOOP.
ALSO see
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.
Regards,
Sesh
2007 Feb 21 5:11 AM
Hi,
AT NEW f.
Variant 2
AT END OF f.
Effect
f is a sub-field of an internal table processed with LOOP . The sequence of statements which follow it is executed if the sub-field f or a sub-field in the current LOOP line defined (on the left) before f has a differnt value than in the preceding ( AT NEW ) or subsequent ( AT END OF ) table line.
Example
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 .
Notes
If a control break criterion is not known until runtime, you can use AT NEW (name) or AT END OF (name) to specify it dynamically as the contents of the field name . If name is blank at runtime, the control break criterion is ignored and the sequence of statements is not executed. If name contains an invalid component name, a runtime error occurs.
By defining an offset and/or length, you can further restrict control break criteria - regardless of whether they are specified statically or dynamically.
A field symbol pointing to the LOOP output area can also be used as a dynamic control break criterion. If the field symbol does not point to the LOOP output area, a runtime error occurs.
Note
Runtime errors
AT_BAD_PARTIAL_FIELD_ACCESS : Invalid sub-field access when dynamically specifying the control break criterion.
AT_ITAB_FIELD_INVALID : When dynamically specifying the control break criterion via a field symbol, the field symbol does not point to the LOOP output area.
ITAB_ILLEGAL_COMPONENT : When dynamically specifying the control break criterion via (name) the field name does not contain a valid sub-field name.
Variant 3
AT FIRST.
Variant 4
AT LAST.
Effect
Executes the appropriate sequence of statements once during the first ( AT FIRST ) or last ( AT LAST ) loop pass.
Example
DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.
...
LOOP AT COMPANIES.
AT FIRST.
SUM.
WRITE: 'Sum of all SALES:',
55 COMPANIES-SALES.
ENDAT.
WRITE: / COMPANIES-NAME, COMPANIES-PRODUCT,
55 COMPANIES-SALES.
ENDLOOP.
regards,
keerthi
2007 Feb 21 5:11 AM
Hi,
Please Go through this
REPORT ZPROBLEM68 no standard page heading
line-size 155
line-count 26 .
*Example for joins ---in class.
tables:vbak,vbap.
*vbak---Header data given in short text.
data:begin of itab occurs 0,
vbeln like vbak-vbeln,
erdat like vbak-erdat,
ernam like vbak-ernam,
posnr like vbap-posnr,
matnr like vbap-matnr,
werks like vbap-werks,
netwr like vbap-netwr,
end of itab.
data:v_lines type i.
data:v_netwr like vbap-netwr.
data:v_qnetwr like vbap-netwr.
start-of-selection.
select kvbeln kerdat kernam pposnr pmatnr pwerks p~netwr
into table itab from vbak as k inner join vbap as p
on kvbeln = pvbeln.
end-of-selection.
describe table itab lines v_lines.
write:/ 'No of records',v_lines color 1.
sort itab by vbeln.
loop at itab.
at first.
uline.
write:/2 'Sales document',
24 sy-vline,
25 'Date of creation',
44 sy-vline,
45 'Person who created',
64 sy-vline,
65 'Sales doc item',
84 sy-vline,
85 'Material no',
104 sy-vline,
105 'Plant',
124 sy-vline,
125 'Net value'.
uline.
endat.
at new vbeln.
write:/ 'Sales document'.
write:/2 itab-vbeln color 2.
endat.
v_netwr = v_netwr + itab-netwr.
v_qnetwr = v_qnetwr + itab-netwr.
write:/25 itab-erdat color 3,
44 sy-vline,
45 itab-ernam color 4,
64 sy-vline,
65 itab-posnr color 5,
84 sy-vline,
85 itab-matnr color 6,
104 sy-vline,
105 itab-werks color 7,
124 sy-vline,
125 itab-netwr color 3.
at end of vbeln.
write:/120 'Total', 130 v_netwr color 5.
endat.
at last.
uline.
write:/120 'Grand Total', 135 v_qnetwr color 7.
endat.
endloop.
<b>If helps please reward points.</b>
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |