‎2007 Sep 07 12:31 PM
Hello experts,
I am currently having a problem with my At New statement. It is treating every field of the itab as a new record even though it is the same.
For example,
on the first loop the field matnr has a value of mat-A then the at new will trigger.
then on the second loop matnr has a value of mat-B then again, At New will trigger.that is correct.
But on the third loop, the field matnr will have a value again of mat-B or Mat-A- the same as that of the second or first loop. So it must not trigger the At New statement but it does.
Any solutions?
MY CODING.....
SORT IT_FINAL BY MATNR.
LOOP AT IT_FINAL.
wa_final = it_final.
at new matnr.
it_final1-matnr = wa_final-matnr.
it_final1-maktx = wa_final-maktx.
it_final1-bdmng = VAL1.
APPEND it_final1.
clear : it_final, it_final1, wa_final.
endat.
ENDLOOP.
Thanks!
REGARDS,
NAVANEETH.
‎2007 Sep 07 12:34 PM
Hi
write the clear statement clear : it_final, it_final1, wa_final. after ENDAT.
remove the line wa_final = it_final.
now check...
thanks
vivekanand
‎2007 Sep 07 12:34 PM
Make MATNR as the first field of your internal table structure
Code is absolutely correct.
‎2007 Sep 07 12:37 PM
Hi,
I have used the matnr as first field only in the internal table
Regards,
Navaneeth.
‎2007 Sep 07 12:37 PM
Hi Navneeth..
Your code works perfectly..
Only when the MATNR is the First field in your internal Table.
<b><REMOVED BY MODERATOR></b>
Message was edited by:
Alvaro Tejada Galindo
‎2007 Sep 07 12:39 PM
hi,
fields which u give in AT NEW statement should be first fields to avoid unnecessary actions. so give all fields which u use in at new as starting fields and also clear the internal table after end at statement .
<b><REMOVED BY MODERATOR></b>
with regards,
Suresh Aluri.
Message was edited by:
Alvaro Tejada Galindo
‎2007 Sep 07 12:40 PM
RERESH : IT_FINAL1.
Use this statement before the LOOP AT IT_FINAL. statement.
‎2007 Sep 07 12:43 PM
Hi,
at new matnr.
it_final1-matnr = wa_final-matnr.
it_final1-maktx = wa_final-maktx.
it_final1-bdmng = VAL1.
APPEND it_final1.
In the above case , IF Matnr is the first field,
assigning the fields right hind side to the matnr (first field) will go for waste.
as <b>the * s only u could see</b>.
So try to read the fields into another work area and assign them here.
‎2007 Sep 07 12:46 PM
Hi
see this program you can understand each and every thing
* Using AT FIRST , AT NEW, AT THE END OF , AT LAST.
DATA: BEGIN OF ITAB OCCURS 0,
F1 TYPE I,
F2(6) TYPE C,
F3(10) TYPE N,
F4(16) TYPE P DECIMALS 2,
END OF ITAB.
DATA: SUB_TOT(10) TYPE P DECIMALS 3.
**--1
ITAB-F1 = 1.
ITAB-F2 = 'ONE'.
ITAB-F3 = 10.
ITAB-F4 = '1000.00'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = 1.
ITAB-F2 = 'ONE'.
ITAB-F3 = 20.
ITAB-F4 = '2000.00'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = 1.
ITAB-F2 = 'ONE'.
ITAB-F3 = 30.
ITAB-F4 = '3000.00'.
APPEND ITAB.
CLEAR ITAB.
*--2
ITAB-F1 = 2.
ITAB-F2 = 'TWO'.
ITAB-F3 = 10.
ITAB-F4 = '1000.00'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = 2.
ITAB-F2 = 'TWO'.
ITAB-F3 = 20.
ITAB-F4 = '2000.00'.
APPEND ITAB.
CLEAR ITAB.
*-- 3
ITAB-F1 = 3.
ITAB-F2 = 'THREE'.
ITAB-F3 = 10.
ITAB-F4 = '1000.00'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = 3.
ITAB-F2 = 'THREE'.
ITAB-F3 = 20.
ITAB-F4 = '2000.00'.
APPEND ITAB.
CLEAR ITAB.
SORT ITAB BY F1.
LOOP AT ITAB.
AT FIRST.
WRITE: /35 ' MATERIAL DETAILS:'.
ULINE.
ENDAT.
AT NEW F1.
WRITE: / 'DETAILS OF MATERIAL:' COLOR 7 , ITAB-F1.
ULINE.
ENDAT.
WRITE: / ITAB-F1, ITAB-F2, ITAB-F3, ITAB-F4.
SUB_TOT = SUB_TOT + ITAB-F4.
AT END OF F1.
ULINE.
WRITE: / 'SUB TOTAL :' COLOR 3 INVERSE ON, SUB_TOT COLOR 3 INVERSE ON.
CLEAR SUB_TOT.
ENDAT.
AT LAST.
SUM.
ULINE.
WRITE: 'SUM:', ITAB-F4.
ULINE.
ENDAT.
ENDLOOP.<b><REMOVED BY MODERATOR></b>
Message was edited by:
Alvaro Tejada Galindo
‎2007 Sep 07 12:59 PM
Hi navaneethan krishnan ,
Here are points yyou need to handle when you use AT NEW(Contril statements).
1. Sort the itab which you r looping at
2. The order of fields makes effect
3.suppose if there are F1,F2,...F10 Fields, and If you put AT NEW F5.
Then At new will trigger if any of field value before F5 changed
4.Proper End AT is used
Hope These ponts will definitely help you.
Regards,
Rama chary.Pammi
‎2007 Sep 07 11:59 PM
Hi navaneethan,
it is important to understand SAP's concept of Control Level Processing using statements AT NEW f and AT END OF f.
Originally this was defined for the obsolete technique of extracts and that is where the documentation can be found.
[<a href="http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db9f1f35c111d1829f0000e829fbfe/content.htm">Control Level Processing</a>]
The documentation for extract datasets applies exactly to internal tables:
The table mus be sorted to get control levels defined. 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 internal table is not sorted, the AT - ENDAT block is never executed.
Please have a look at the graphical demonstration of Control level processing in this document: <a href="http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb381a358411d1829f0000e829fbfe/content.htm">Processing Table Entries in Loops</a>
Regards,
Clemens
BTW: Too bad we have anonymous MOD