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

Problem with itab looping

Former Member
0 Likes
813

Hi, I have a set of data in an internal table, with fields a b c d e.

My requirement is rather confusing

-


      1. ( KEY refers to combination of a b c and d )

sort itab by a,b,c,d

loop at itab based on sort key ( a,b,c,d)

at break in KEY sum all e for the records with the SAME KEY.

if sum(e) > 0.

remove this set from itab

else.

keep them

endloop.

-


I am not sure how to proceed, can anyone help?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
792

Try this:

sort itab by a b c d.

loop at itab into wa_itab.

at end d.

sum.

if wa_itab-e > 0. " or compare with ur required threshold value'.

delete itab where a = wa_itab-a and b = wa_itab-b and c = wa_itab-c and d = wa_itab-d.

endif.

endat.

endloop.

7 REPLIES 7
Read only

Former Member
0 Likes
792

Hi,

Its little bit confusing.

Can u tell ur requirement briefly.

Thanks.

Read only

JozsefSzikszai
Active Contributor
0 Likes
792

roughly:

SORT iatb BY a b c d.
LOOP AT itab.
AT END OF d.
SUM.
IF itab-e > 0.
DELETE itab WHERE a = itab-a
                         AND b = itab-b
                         AND c = itab-c
                         AND d = itab-d.
ENDIF.
ENDAT.
ENDLOOP.

Read only

Former Member
0 Likes
793

Try this:

sort itab by a b c d.

loop at itab into wa_itab.

at end d.

sum.

if wa_itab-e > 0. " or compare with ur required threshold value'.

delete itab where a = wa_itab-a and b = wa_itab-b and c = wa_itab-c and d = wa_itab-d.

endif.

endat.

endloop.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
792

Hello,

sort itab by a,b,c,d

loop at itab based on sort key ( a,b,c,d)

at break in KEY sum all e for the records with the SAME KEY.

if sum(e) > 0.

remove this set from itab

else.

keep them

endloop.

You can try this code and check:


SORT itab BY a b c d.
LOOP AT itab INTO wa.
  wa1 = wa.
  v_sum_e = v_sum_e + wa-e.
  AT END OF d.
    IF v_sum_e > 0.
    ELSE.
      DELETE itab
      WHERE a = wa1-a AND b = wa1-b AND c = wa1-c AND d = wa1-d.
    ENDIF.
  ENDAT.
ENDLOOP.

Plz try & let us know.

BR,

Suhas

Read only

Pawan_Kesari
Active Contributor
0 Likes
792

assuming you can add a new_field at the end of itab structure this is the logic.


sort itab by abcd.

loop at itab.

   at end of d. "assuming fields in structure are defined in sequence abcd
     sum.
     if e > 0 .
         modify table itab and set 'X' to new_field where key = abcd.
     endif.
   endat.
endloop.

delete itab where new_field = 'X'

Read only

Former Member
0 Likes
792

Hi Suker,

try it this way:

Loop at itab into wa.
  At end of d.
    Sum.
    w_sum = wa-e.
    If w_sum > 0.
      Delete itab where ...
    Endif.
  Endat.
Endloop.

With luck,

Pritam.

Read only

0 Likes
792

Hi,

SORT itab BY a b c d.

LOOP AT itab INTO wa.

v_sum = v_sum + wa-e.

AT END OF d.

IF v_sum NE 0.

DELETE itab

WHERE a = wa-a AND b = wa-b AND c = wa-c AND d = wa-d.

ENDIF.

CLEAR v_sum.

ENDAT.

ENDLOOP.