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: 

ON chnage of or At new

Former Member
0 Kudos
97

Hi ,

In one internal table I have SCN Number and Po Number.

if both changes then only i have to take total other wise i should not take total.

For this I used like this.

sort itab by scn po.

loop at itab.

ON change of itab-scn or itab-po .

itab1-scn = itab-scn.

itab1-po = itab-po.

itab1-total = sum.

clear sum.

endon.

sum = sum + itab-total.

endloop.

But here the problem it is adding the First record in the Itab1 and by taking the total zero.

How to solve it ...?

regards,

satya.

10 REPLIES 10

Former Member
0 Kudos
68

just keep a check

IF SY-TABIX NE 1.

Reward if useful

Regards

ANUPAM

kesavadas_thekkillath
Active Contributor
0 Kudos
68

data:wk_tabix type sy-tabix.

sort itab by scn po ascending.

loop at itab.

wk_tabix = sy-tabix.

at new po.

read table itab index wk_tabix.

if sy-subrc = 0.

itab1-po = itab-po.

itab1-total = sum.

clear sum.

endif.

endat.

endloop.

This will work.....here scn must be the firsat column in lopping table and PO as second field.

0 Kudos
68

Hi ,

here also the first row total gets zero.

kesavadas_thekkillath
Active Contributor
0 Kudos
68

paste that part of code here

kesavadas_thekkillath
Active Contributor
0 Kudos
68

sorry i forgot to include a line...

data:wk_tabix type sy-tabix.

sort itab by scn po ascending.

loop at itab.

wk_tabix = sy-tabix.

at new po.

read table itab index wk_tabix.

if sy-subrc = 0.

itab1-po = itab-po.

itab1-total = sum.

clear sum.

endif.

endat.

sum = sum + itab-total. <----


endloop.

here the sum will be calculated always.....and when at new triggers it gets stored in new itab and gets cleared.

0 Kudos
68

i got u r proble.....at the first record it will always take zero...because sum = 0. at first time.

so you have to store the value of itab-total into sum

so just try this.

data:wk_tabix type sy-tabix.

sort itab by scn po ascending.

loop at itab.

wk_tabix = sy-tabix.

at new po.

if wk_tabix = 1.

itab1-po = itab-po.

itab1-total = itab-total..

append itab1.

else.

read table itab index wk_tabix.

if sy-subrc = 0.

itab1-po = itab-po.

itab1-total = sum.

append itab1.

clear sum.

endif.

endif.

endat.

sum = sum + itab-total.

endloop.

0 Kudos
68

sorry again....try this

data:wk_tabix type sy-tabix.

sort itab by scn po ascending.

loop at itab.

wk_tabix = sy-tabix.

at new po.

read table itab index wk_tabix.

if sy-subrc = 0.

if wk_tabix = 1.

itab1-po = itab-po.

itab1-total = itab-total..

else.

itab1-po = itab-po.

itab1-total = sum.

endif.

append itab1.

clear sum.

endif.

endif.

endat.

sum = sum + itab-total.

endloop.

kesavadas_thekkillath
Active Contributor
0 Kudos
68

also include append itab1 in the at new block.

Former Member
0 Kudos
68

ort itab by scn po.

loop at itab.

ON change of itab-scn or itab-po .

IF SY-TABIX NE 1.

itab1-scn = itab-scn.

itab1-po = itab-po.

itab1-total = sum.

clear sum.

ENDIF.

endon.

sum = sum + itab-total.

endloop.

Try this buddy. i said it earlier. think u didnot get me.

Reward if useful

Regards

ANUPAM

Former Member
0 Kudos
68

Hi Satyanarayana,

try this example it ll help u..

in this code just replace the 'a' with 'scn' ,

'b' with 'po'

'c' with 'total',

'tot_c' with 'sum'

and remove 'd' and 'tot_d'..

*************************************************************************

&----


*& Report ZZXXXXXXX *

*& *

&----


*& *

*& *

&----


REPORT zzxxxxxxx .

DATA: BEGIN OF itab OCCURS 0,

x TYPE i,

a(2),

b(2),

c TYPE i,

d TYPE i,

END OF itab.

DATA: flag,

flag1,

main_flag,

tot_c type i,

tot_d type i.

DEFINE mac1.

itab-a = &1.

itab-b = &2.

itab-c = &3.

itab-d = &4.

append itab.

clear itab.

END-OF-DEFINITION.

mac1 'aa' 'xx' '11' '22'.

mac1 'aa' 'xx' '22' '11'.

mac1 'aa' 'yy' '33' '22'.

mac1 'bb' 'yy' '44' '33'.

mac1 'cc' 'yy' '55' '44'.

mac1 'cc' 'zz' '66' '66'.

SORT itab BY a b.

LOOP AT itab.

FORMAT COLOR 3 INTENSIFIED ON.

WRITE: /01 itab-a,05 itab-b,10 itab-c,20 itab-d.

FORMAT COLOR OFF.

CLEAR itab.

ENDLOOP.

clear: flag, flag1, main_flag.

LOOP AT itab.

AT end of a.

IF flag1 = 'X'.

main_flag = 'X'.

CLEAR: flag1,flag.

ELSE.

flag = 'X'.

ENDIF.

ENDAT.

AT end of b.

IF flag = 'X'.

main_flag = 'X'.

CLEAR: flag1,flag.

ELSE.

flag1 = 'X'.

ENDIF.

ENDAT.

WRITE: /01 itab-a,05 itab-b,10 itab-c,20 itab-d.

tot_c = tot_c + itab-c.

tot_d = tot_d + itab-d.

IF main_flag eq 'X'.

format color 6.

write: /10 tot_c,20 tot_d.

clear: tot_c, tot_d.

format color off.

ENDIF.

CLEAR: itab, main_flag.

ENDLOOP.

*************************************************************************

I hope it ll help u.. OR other wise ask me again...

If it helps gimme Awrd points plzz

Regards,

Naveen

Edited by: Naveen M on Dec 22, 2007 10:35 AM