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: 

Clear 2 records without disturbing the sum

Former Member
0 Kudos

Hey Folks,

I have a requiremnet where i have a table

itab

field1 field2 field3 field4

12 45 60 57

23 56 78 90

-


35 101 138 147

I need the table t be modified like this

itab

field1 field2 field3 field4

0 0 0 0

0 0 0 0

-


35 101 138 147

I need to clear the 2 records without disturbing the sum.

how wud i achieve this.

thanks in advance.

Regards

Rock

Edited by: Alvaro Tejada Galindo on Feb 7, 2008 9:22 AM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

check this code...


DATA : BEGIN OF itab OCCURS 0,
        f1(4) TYPE p,
        f2(4) TYPE p,
        f3(4) TYPE p,
        f4(4) TYPE p,
       END OF itab.

DATA : itab2 LIKE itab OCCURS 0 WITH HEADER LINE.

itab-f1 = 20.
itab-f2 = 10.
itab-f3 = 30.
itab-f4 = 40.
APPEND itab.

itab-f1 = 11.
itab-f2 = 14.
itab-f3 = 23.
itab-f4 = 24.
APPEND itab.

LOOP AT itab.
  AT LAST.
    SUM.
    MOVE-CORRESPONDING itab TO itab2.
    APPEND itab2. "totals will be stored in itab2.
  ENDAT.
ENDLOOP.

CLEAR itab[]. "clear first internal table.

8 REPLIES 8

Former Member
0 Kudos

you do one thing that make a new field in table and then move components of sum to that like

move oldsum to newsum.

now whatever you do with your old fields this field is unaffected.

after deleting contents of new back to old

move newsum to oldsum.

<REMOVED BY MODERATOR>

vivek

Edited by: Alvaro Tejada Galindo on Feb 7, 2008 9:24 AM

0 Kudos

Hey Vivek,

Could you help me with an example on this.

0 Kudos

YOU DO ONE THING -


make a table of same fields.

now move your sum to this table .

this can be done by -


append sum into it_newtab.

now whatever u do to ur old table ur new table is unaffected

plz reward if useful

vivek

Former Member
0 Kudos

check this code...


DATA : BEGIN OF itab OCCURS 0,
        f1(4) TYPE p,
        f2(4) TYPE p,
        f3(4) TYPE p,
        f4(4) TYPE p,
       END OF itab.

DATA : itab2 LIKE itab OCCURS 0 WITH HEADER LINE.

itab-f1 = 20.
itab-f2 = 10.
itab-f3 = 30.
itab-f4 = 40.
APPEND itab.

itab-f1 = 11.
itab-f2 = 14.
itab-f3 = 23.
itab-f4 = 24.
APPEND itab.

LOOP AT itab.
  AT LAST.
    SUM.
    MOVE-CORRESPONDING itab TO itab2.
    APPEND itab2. "totals will be stored in itab2.
  ENDAT.
ENDLOOP.

CLEAR itab[]. "clear first internal table.

0 Kudos

Hey folks,

I have already summed up the records i need to just clear the 2 records without disturbing the sum.

0 Kudos

then use clear after u have added them

clear:f1 f2.

0 Kudos

Hey,

but how to clear only those 2 records without disturbing the sum..

0 Kudos

tats what i said

f1

f2

f3

f1=10

f2=20

fe= f1+f2

f3= 30.

after this clear f1 nd f2