Application Development 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: 

at end of field

Former Member
0 Kudos

I am looping into an internal table then giving

at end of <field1>

SUM

and i have field like

field1 field2

abc 100

abc 100

abc 200

def 100

def 200

Now my sums should be 400 then 300..

and theloop pass should enter at end of vtref only for the last time to sum the values..

but my loop is entering every time into at end of f1 and giving

wrong values..

any specfic reasons?

1 ACCEPTED SOLUTION

JozsefSzikszai
Active Contributor
0 Kudos

1. is the table sorted?

2. is field1 really the first field of the internal table?

14 REPLIES 14

GauthamV
Active Contributor
0 Kudos

hi,

try AT NEW field1 and SUM.

JozsefSzikszai
Active Contributor
0 Kudos

1. is the table sorted?

2. is field1 really the first field of the internal table?

Former Member
0 Kudos

Hi,

First sort the internal table and then use "ON change of "

or "at new" . this will help you out

and then delete the other rows

Thanks & Regards

Edited by: Ranjit Kumar on Oct 21, 2008 11:13 AM

0 Kudos

at new or onchange of will not work...because i need all addition of similar values

0 Kudos

>

> at new or onchange of will not work...because i need all addition of similar values

Hi Arvind ,

Use "Collect Statement

Thanks & Regards

Former Member
0 Kudos

Hi,

Check the following code:

data: begin of itab occurs 0,

fld1(5) type c,

fld2 type i,

end of itab.

itab-fld1 = 'abc'.

itab-fld2 = 100.

append itab.

itab-fld1 = 'abc'.

itab-fld2 = 100.

append itab.

itab-fld1 = 'abc'.

itab-fld2 = 200.

append itab.

itab-fld1 = 'def'.

itab-fld2 = 100.

append itab.

itab-fld1 = 'def'.

itab-fld2 = 200.

append itab.

loop at itab.

write:/ itab-fld1, itab-fld2.

at end of fld1.

sum.

uline.

write:/ itab-fld1, itab-fld2.

skip.

endat.

endloop.

Regards,

Bhaskar

Former Member
0 Kudos

Consider there are three fileds in the ITAB.

fld1,fld2 and fld3.

When you write AT END OF fld3, the loop pass will go inside this block whenever the value in fld1 or fld2 or fld3 changes.

Thats the reason why you are getting such result.

Try ON CHNAGE OF

Former Member
0 Kudos

Hi Aravind,

Try the below code.




DATA : BEGIN OF ITAB OCCURS 0,
          NAME(3),
          VALUE TYPE I,
       END OF ITAB.


ITAB-NAME = 'abc'.
ITAB-VALUE = 100.
APPEND ITAB.

ITAB-NAME = 'abd'.
ITAB-VALUE = 100.
APPEND ITAB.

ITAB-NAME = 'abc'.
ITAB-VALUE = 100.
APPEND ITAB.

ITAB-NAME = 'abd'.
ITAB-VALUE = 300.
APPEND ITAB.

SORT ITAB BY NAME.

LOOP at ITAB.
  AT END OF NAME.
    SUM.
    write 😕 itab-name , itab-value.
  ENDAT.
ENDLOOP.

Former Member
0 Kudos

Hello,

Better to use collect statement to add the sum for similar field values.

loop the internal table

Collect workarea to internal table

endloop.

Use this statement for u r internal table it will automatically add the sum for the similar field

abc 400

def 300

Your internal table contain these 2rows.

Former Member
0 Kudos

Hi

As per the code given by you, and the itab content

the output itab after the entire loop should be

field1 field2

abc 400

def 300

The output will be like this only if field1 is the 1st field of the itab.If not, the control enters into the at end stmt whenever data changes in the fields left of field1.

Please make sure of this point and proceed.

Please notify if this is not working

Regards

Winnie

Former Member
0 Kudos

Hi Arvind,

try it like this:

Sort itab by field1.

Loop at itab into wa.
  At end of field1.
    Sum.
    Write: wa-field1,  
              wa-field2. " Here you will get the sum of similar fields
  Endat.
Endloop.

With luck,

Pritam.

Subhankar
Active Contributor
0 Kudos

Hi Arvind,

Just sort the internal table by field1.

then place your same code .

loop

at end of <field1>

SUM

and i have field like

endloop.

I think it will help you.

Thanks and Regards

Subhankar

Former Member
0 Kudos

Hi VR ARVIND ,

Control break statement are very sensitive . make sure that this is the 1st field of an internal table .I thing you have more field before that which causes in each pass the previous values changes and in end of fire . and sort the ITAB with the control break Statements , before looping and Sum is work only for P I F field only.

Thanks ;

Tarak.

Former Member
0 Kudos

answered