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

At New statement problem

Former Member
0 Likes
3,163

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.

10 REPLIES 10
Read only

Former Member
0 Likes
1,034

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

Read only

Former Member
0 Likes
1,034

Make MATNR as the first field of your internal table structure

Code is absolutely correct.

Read only

0 Likes
1,034

Hi,

I have used the matnr as first field only in the internal table

Regards,

Navaneeth.

Read only

varma_narayana
Active Contributor
0 Likes
1,034

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

Read only

Former Member
0 Likes
1,034

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

Read only

Former Member
0 Likes
1,034

RERESH : IT_FINAL1.

Use this statement before the LOOP AT IT_FINAL. statement.

Read only

Former Member
0 Likes
1,034

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.

Read only

Former Member
0 Likes
1,034

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

Read only

Former Member
0 Likes
1,034

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

Read only

Clemenss
Active Contributor
0 Likes
1,034

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