2008 Feb 22 4:55 AM
any body have document on control structures pse send me
(at new,at end,on change of,at start ,at last)
any body have document on control structures pse send me
(at new,at end,on change of,at start ,at last)
2008 Feb 22 4:59 AM
At New.
Effect
Beginning or end of a group of lines with the same content in the component comp1 comp2 ... and in the components to the left of comp1 comp2 .... The components comp1 comp2 ... can be specified, as described in the section Specification of Components, with the limitation that access to object attributes is not possible here.
Example:
codeLOOP AT itab result ...
[AT NEW comp1.
...
ENDAT.
endloop.[/code]
On Change of:
Effect:
The statements ON CHANGE OF and ENDON, which are forbidden in classes, define a control structure that can contain a statement block statement_block. After ON CHANGE OF, any number of data objects dobj1, dobj2... of any data type can be added..
Example:
In a SELECT loop, a statement block should only be executed if the content of the column CARRID has changed.
codeDATA spfli_wa TYPE spfli.
SELECT *
FROM spfli
INTO spfli_wa
ORDER BY carrid.
...
ON CHANGE OF spfli_wa-carrid.
...
ENDON.
...
ENDSELECT.[/code]
2008 Feb 22 5:01 AM
If it is control break statements.... then here is the types and explanation
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.
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 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 < '
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.
2008 Feb 22 5:05 AM
hi,
Introduction Control Break Processing
These are the statements used.
at first / endat
at last / endat
at new / endat
at end of / endat
- Controls when the code that lies between them is executed. This type of control is called a control break.
- Purpose - execute the code between them whenever a specific condition in the data is detected during the processing of the loop.
Note: Before working with control breaks, You should sort the internal table in the same order as its columns are defined.
Using Control Levels:
Hierarchy of AT-ENDAT statement.
If the internal table has the columns <col1>,<col2>, and if it is sorted by the columns as they are defined, the loop is to be programmed as follows:
LOOP AT <itab>.
AT FIRST. ..ENDAT.
AT NEW <col1> .ENDAT.
AT NEW <col2> ENDAT.
.
<single line processing>
...
AT END OF <col2> ..ENDAT.
AT END OF <col1> ENDAT.
AT LAST ENDAT.
ENDLOOP.
at first and at last statements - syntax
loop at itab..
---
at first.
---
endat.
---
at last.
---
endat.
---endloop.
The first time through the loop, the lines of code between at first and endat are executed.
The last time through the loop, the lines of code between at last and endat are executed.
PURPOSE:
at first
Loop initialization processing
Writing totals at the top of a report
Writing headings
at last
Loop termination processing
Writing totals at the bottom of a report
conditions:
Can be used only within loop at .
Cannot be used within select.
Order of these statements can be interchanged
Should not be nested inside one another.
Writing footings
EXAMPLE
tables: PA0000.
data: itab1 like PA0000 occurs 10 with header line.
select * from PA0000 into table itab1 where stat2 = '3'.
loop at itab1.
at first.
write: / 'Personnel Number'.
write: / itab1-pernr.
at last.
write: / '----
endat.
endloop.
OUTPUT:
Personnel Number
0000001
0000002
______________
REGARDS,
Sreelakshmi.
endat.
2008 Feb 22 5:21 AM
HI,
1. ON CHANGE OF.
ENDON.
2. AT FIRST.
ENDAT.
3. AT LAST.
ENDAT.
4. AT NEW.
ENDAT.
5. AT END OF.
ENDAT.
1. ON CHANGE OF - ENDON.
-
This is also called as processing block within the LOOP-ENDLOOP statements.
Eg. code:
-
DATA IT_MARA LIKE MARA OCCURS 0 WITH HEADER LINE.
SELECT * FROM MARA INTO TABLE IT_MARA.
SORT IT_MARA BY MTART.
LOOP AT IT_MARA.
ON CHANGE OF IT_MARA-MTART.
SKIP 1.
WRITE 😕 'MATERIAL DETAILS BASED ON' COLOR 5, IT_MARA-MTART COLOR 5.
SKIP 1.
ENDON.
WRITE 😕 IT_MARA-MATNR, IT_MARA-MTART, IT_MARA-MBRSH, IT_MARA-MEINS.
ENDLOOP.
The statement written within the processing block ON CHANGE OF-ENDON gets printed out in LPS whenever the internal table loop encounters change in the field value.
2. AT FIRST-ENDAT:
-
Eg. code:
-
DATA IT_MARA LIKE MARA OCCURS 0 WITH HEADER LINE.
SELECT * FROM MARA INTO TABLE IT_MARA.
SORT IT_MARA BY MTART.
LOOP AT IT_MARA.
AT FIRST.
SKIP 1.
WRITE :/40(50) 'MATERIAL MASTER DETAILS' CENTERED COLOR 7.
SKIP 1.
ENDAT.
WRITE 😕 IT_MARA-MATNR, IT_MARA-MTART, IT_MARA-MBRSH, IT_MARA-MEINS.
ENDLOOP.
The statement specified within AT FIRST-ENDAT gets printed out in LPS during the first pass of the loop iteration.
3. AT LAST-ENDAT:
-
Eg. code:
-
DATA IT_KNC1 LIKE KNC1 OCCURS 0 WITH HEADER LINE.
SELECT * FROM KNC1 INTO TABLE IT_KNC1.
LOOP AT IT_KNC1.
WRITE 😕 IT_KNC1-GJAHR, IT_KNC1-UM01U.
AT LAST.
SUM.
SKIP 1.
WRITE 😕 'GRAND TOTAL OF THE TRANSACTION IS' COLOR 4, IT_KNC1-UM01U
COLOR 4.
ENDAT.
ENDLOOP.
4. AT NEW-ENDAT:
-
Eg. code:
-
DATA : BEGIN OF IT_KNC1 OCCURS 0,
GJAHR LIKE KNC1-GJAHR,
UM01U LIKE KNC1-UM01U,
END OF IT_KNC1.
SELECT GJAHR UM01U FROM KNC1 INTO TABLE IT_KNC1.
SORT IT_KNC1 BY GJAHR.
LOOP AT IT_KNC1.
AT NEW GJAHR.
SKIP 1.
WRITE 😕 'TOTAL NUMBER OF TRANSACTIONS MADE DURING THE YEAR' COLOR 3, IT_KNC1-GJAHR COLOR 3.
SKIP 1.
ENDAT.
WRITE 😕 IT_KNC1-GJAHR, IT_KNC1-UM01U.
ENDLOOP.
5. AT END OF - ENDAT:
-
Eg. code:
-
DATA : BEGIN OF IT_KNC1 OCCURS 0,
GJAHR LIKE KNC1-GJAHR,
UM01U LIKE KNC1-UM01U,
END OF IT_KNC1.
SELECT GJAHR UM01U FROM KNC1 INTO TABLE IT_KNC1.
SORT IT_KNC1 BY GJAHR.
LOOP AT IT_KNC1.
WRITE 😕 IT_KNC1-GJAHR, IT_KNC1-UM01U.
AT END OF GJAHR.
SUM.
SKIP 1.
WRITE 😕 'GRAND TOTAL OF TRANSACTION FOR THE YEAR' COLOR 4,
IT_KNC1-UM01U COLOR 4.
SKIP 1.
ENDAT.
ENDLOOP.
Hope it will be useful.
Regards,
Priya.
2008 Feb 22 5:21 AM
HI,
1. ON CHANGE OF.
ENDON.
2. AT FIRST.
ENDAT.
3. AT LAST.
ENDAT.
4. AT NEW.
ENDAT.
5. AT END OF.
ENDAT.
1. ON CHANGE OF - ENDON.
-
This is also called as processing block within the LOOP-ENDLOOP statements.
Eg. code:
-
DATA IT_MARA LIKE MARA OCCURS 0 WITH HEADER LINE.
SELECT * FROM MARA INTO TABLE IT_MARA.
SORT IT_MARA BY MTART.
LOOP AT IT_MARA.
ON CHANGE OF IT_MARA-MTART.
SKIP 1.
WRITE 😕 'MATERIAL DETAILS BASED ON' COLOR 5, IT_MARA-MTART COLOR 5.
SKIP 1.
ENDON.
WRITE 😕 IT_MARA-MATNR, IT_MARA-MTART, IT_MARA-MBRSH, IT_MARA-MEINS.
ENDLOOP.
The statement written within the processing block ON CHANGE OF-ENDON gets printed out in LPS whenever the internal table loop encounters change in the field value.
2. AT FIRST-ENDAT:
-
Eg. code:
-
DATA IT_MARA LIKE MARA OCCURS 0 WITH HEADER LINE.
SELECT * FROM MARA INTO TABLE IT_MARA.
SORT IT_MARA BY MTART.
LOOP AT IT_MARA.
AT FIRST.
SKIP 1.
WRITE :/40(50) 'MATERIAL MASTER DETAILS' CENTERED COLOR 7.
SKIP 1.
ENDAT.
WRITE 😕 IT_MARA-MATNR, IT_MARA-MTART, IT_MARA-MBRSH, IT_MARA-MEINS.
ENDLOOP.
The statement specified within AT FIRST-ENDAT gets printed out in LPS during the first pass of the loop iteration.
3. AT LAST-ENDAT:
-
Eg. code:
-
DATA IT_KNC1 LIKE KNC1 OCCURS 0 WITH HEADER LINE.
SELECT * FROM KNC1 INTO TABLE IT_KNC1.
LOOP AT IT_KNC1.
WRITE 😕 IT_KNC1-GJAHR, IT_KNC1-UM01U.
AT LAST.
SUM.
SKIP 1.
WRITE 😕 'GRAND TOTAL OF THE TRANSACTION IS' COLOR 4, IT_KNC1-UM01U
COLOR 4.
ENDAT.
ENDLOOP.
4. AT NEW-ENDAT:
-
Eg. code:
-
DATA : BEGIN OF IT_KNC1 OCCURS 0,
GJAHR LIKE KNC1-GJAHR,
UM01U LIKE KNC1-UM01U,
END OF IT_KNC1.
SELECT GJAHR UM01U FROM KNC1 INTO TABLE IT_KNC1.
SORT IT_KNC1 BY GJAHR.
LOOP AT IT_KNC1.
AT NEW GJAHR.
SKIP 1.
WRITE 😕 'TOTAL NUMBER OF TRANSACTIONS MADE DURING THE YEAR' COLOR 3, IT_KNC1-GJAHR COLOR 3.
SKIP 1.
ENDAT.
WRITE 😕 IT_KNC1-GJAHR, IT_KNC1-UM01U.
ENDLOOP.
5. AT END OF - ENDAT:
-
Eg. code:
-
DATA : BEGIN OF IT_KNC1 OCCURS 0,
GJAHR LIKE KNC1-GJAHR,
UM01U LIKE KNC1-UM01U,
END OF IT_KNC1.
SELECT GJAHR UM01U FROM KNC1 INTO TABLE IT_KNC1.
SORT IT_KNC1 BY GJAHR.
LOOP AT IT_KNC1.
WRITE 😕 IT_KNC1-GJAHR, IT_KNC1-UM01U.
AT END OF GJAHR.
SUM.
SKIP 1.
WRITE 😕 'GRAND TOTAL OF TRANSACTION FOR THE YEAR' COLOR 4,
IT_KNC1-UM01U COLOR 4.
SKIP 1.
ENDAT.
ENDLOOP.
Hope it will be useful.
Regards,
Priya.