2008 May 09 8:40 AM
hi
where we use control commands like at-new end at.
give some examples of real time
hi
where we use control commands like at-new end at.
give some examples of real time
2008 May 09 8:47 AM
2008 May 09 8:54 AM
Hi,
At New
It triggers for example: say vbak-vbeln , for every new vbeln , it generates new record
At First
this is triggered when the control is at first record.
AtLast
this is triggered atlast record .
at end of
this is triggered when the last record of a particular feild is reached.
for example at end of kunnr.
when the last record of kunnr is reached this is triggered.
PARAMETER p_x TYPE i OBLIGATORY. "no of records
-
STRUCTURE DECLARATION
-
TYPES : BEGIN OF st_knc1,
kunnr TYPE knc1-kunnr, "Customer Number
bukrs TYPE knc1-bukrs, "Company Code
um01u TYPE knc1-um01u , "Sales In Posting Period
END OF st_knc1.
-
INTERNAL TABLE DECLARATIONS
-
DATA : it_knc1 TYPE STANDARD TABLE OF st_knc1 ,
wa_knc1 TYPE st_knc1.
-
START-OF-SELECTION
-
START-OF-SELECTION.
SELECT kunnr bukrs um01u
FROM knc1
INTO TABLE it_knc1
UP TO p_x ROWS.
SORT it_knc1 BY kunnr.
LOOP AT it_knc1 INTO wa_knc1.
-
CONTROL BREAK STATEMENTS
-
AT FIRST.
WRITE:/'customer number'.
ENDAT.
AT NEW kunnr.
WRITE:/ 'NEW RECORD'.
ENDAT.
WRITE:/ wa_knc1-kunnr, 5(10) wa_knc1-bukrs, 20(10) wa_knc1-um01u CURRENCY 'INR' .
AT END OF kunnr.
WRITE:/'END OF NEW RECORD'.
SUM.
WRITE:/'SUB TOTAL' , wa_knc1-um01u CURRENCY 'INR'. "sub total
ENDAT.
AT LAST.
WRITE:/ 'LAST RECORD IS REACHED'.
SUM.
WRITE:/ 'GRAND TOTAL',wa_knc1-um01u CURRENCY 'INR'. "grand total
ENDAT.
ENDLOOP.
-
TOP-OF-PAGE
-
TOP-OF-PAGE.
WRITE:/40 text-000.
Reward Points for Helpfull Answers
Regards
Fareedas
2008 May 09 8:55 AM
Using the at new and at end of Statements
Use the at new and at end of statements to detect a change in a column from one loop pass to the next. These statements enable you to execute code at the beginning and end of a group of records.
Syntax for the at new and at end ff Statements
The following is the syntax for the at new and at end of statements.
sort by c.
loop at it.
at new c.
endat.
at end of c.
endat.
endloop.
where:
it is an internal table.
c is a component of it.
space represents any number of lines of code (even zero).
These statements can only be used within loop at; they cannot be used within select.
at new does not have to come before at end of. These statements can appear in any order.
These statements can appear multiple times within the same loop. For example, you could have two at new and three at end of statements within one loop and they can appear in any order.
These statements should not be nested inside of one another (that is, at end of should not be placed inside of at new / endat).
There are no additions to these statements.
Using at new
Each time the value of c changes, the lines of code between at new and endat are executed. This block is also executed during the first loop pass or if any fields to the left of c change. Between at and endat, the numeric fields to the right of c are set to zero. The non-numeric fields are filled with asterisks (*). If there are multiple occurrences of at new, they are all executed. at end of behaves in a similar fashion.
A control level is the component named on a control break statement; it regulates the control break. For example, in the following code snippet, f2 is a control level because it appears on the at new statement.
loop at it.
at new f2.
"(some code here)
endat.
endloop.
It is said that a control break is triggered if the control level changes. This means that when the contents of the control level change, the code between the at and endat is executed.
A control break is also triggered if any of the fields prior to the control level in the structure change. Therefore, you should define the internal table structure to begin with the fields that form your control levels. You must also sort by all fields prior to and including c.
Between at and endat, numeric fields to the right of the control level will be zero and non-numeric fields will be filled with asterisks.
The lines of code between at end of and endat are executed:
If the control level changes.
If any field prior to the control level changes.
If this is the last row of the table.
report ztx1309.
data: begin of it occurs 4,
f1,
f2,
end of it.
it = '1A'. append it. "Fill it with data
it = '3A'. append it.
it = '1B'. append it.
it = '2B'. append it.
sort it by f1.
loop at it.
at new f1.
write: / it-f1, it-f2.
endat.
endloop.
skip.
sort it by f2.
loop at it.
at new f2.
write: / it-f1, it-f2.
endat.
endloop.
skip.
sort it by f1 f2.
loop at it.
at new f1.
write: / it-f1.
endat.
at new f2.
write: /4 it-f2.
endat.
endloop.
free it.Using the at first and at last Statements
Use the at first and at last statements to perform processing during the first or last loop pass of an internal table.
Syntax for the at first and at last Statements
The following is the syntax for the at first and at last statements.
loop at it.
at first.
endat.
at last.
endat.
endloop.
where:
it is an internal table.
space represents any number of lines of code (even zero).
These statements can only be used within loop at; they cannot be used within select.
at first does not have to come before at last. The order of these statements can be interchanged.
These statements can appear multiple times within the same loop. For example, you could have two at first and three at last statements within one loop and they can appear in any order.
These statements should not be nested inside of one another (that is, at last should not be placed inside of at first and endat).
There are no additions to these statements.
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. If there are multiple occurrences of at first, they are all executed. at last behaves in a similar fashion.
Use at first for:
Loop initialization processing
Writing totals at the top of a report
Writing headings
Use at last for:
Loop termination processing
Writing totals at the bottom of a report
Writing footings
report ztx1307.
tables ztxlfc3.
data it like ztxlfc3 occurs 25 with header line.
select * from ztxlfc3 into table it where shbkz = 'Z'.
loop at it.
at first.
write: / 'Vendor',
12 'Cpny',
17 'Year',
22 'Bal C/F'.
uline.
endat.
write: / it-lifnr,
12 it-bukrs,
17 it-gjahr,
22 it-saldv.
at last.
write: / '----------',
12 '----',
17 '----',
22 '-------------------'.
endat.
endloop.
free it.I hope it helps.
Best Regards,
Vibha
Please mark all the helpful answers
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |