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

Minor programming problem

Former Member
0 Likes
770

hello, i have written this piece of code in which I am taking the result data in to IT1 then I have to do the comparison and add my keyfigures for duplicate records and delete one of the duplicate records. I am not sure how to add my keyfigures for duplicated records and delete the duplicate record in WA_IT2. can someone help?

For example: if i have the following records in WA_IT2, i want to combine those records.

Plant Division Calmonth Keyfigure1 Keyfigure2

US1 90 12/2009 1 2

US1 90 12/2009 1 3

I want it to look like:

US1 90 12/2009 2 5

IT1 is my first internal table and WA_IT1 is work area for my first internal table

IT2 is my second interbal table and WA_IT2 is work area for my second internal table

APPEND ls_target TO IT1.

sort IT1 by plant division calmonth.

CLEAR WA_IT2.

loop at IT1 INTO WA_IT1.

if wa_IT2 is initial.

WA_IT2 = WA_IT1.

****the first time the above code will execute because WA_IT2 will have nothing in it. The second time it will do the comparison which is as follows:

ELSE.

if WA_IT1-plant = WA_IT2-plant and

WA_IT1-division = WA_IT2-division and

WA_IT1-calmonth = WA_IT2-calmonth.

IF SY-SUBRC = 0

  • add key figures.

else.

append WA_IT2 to et_target.

ENDIF.

ENDIF.

endloop.

append WA_IT2 to et_target.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
743

If understood, you want group (SUM) of fields in the records. For this, use the command COLLECT statement.

Or check the records one by one using loop (for example).

Adriano

6 REPLIES 6
Read only

Former Member
0 Likes
743

To add the Key Figures of the Duplicate Records use COLLECT Statement.

To delete the Duplicate Records use Delete Adjacent Duplicates.

Read only

Former Member
0 Likes
743

thanks ajay, can you please add it in my code?i don't have any idea where and how to do this.

Read only

0 Likes
743

Hi,

To learn it....try by urself.........in case you are not able to do it.......we would help you out but first work on the given hints....

Read only

Former Member
0 Likes
743

Hi,


US1        -field1
90          -field2
12/2009 -field3
1          -field4
3         -field5

Loop at it1.

read it2 with field1 field2 field3.
if sy-subrc = 0.
it2-field4  = it2-field4  + it1-field4  .
it2-field5  = it2-field5  + it1-field5  .
modify it2 from it2 transporting field4 field5 .
else.
move it1 to it2.
append it2 .
endif.
endloop.

Regards,

Prabhudas

Read only

Former Member
0 Likes
743

Something like this?

Plant Division Calmonth Keyfigure1 Keyfigure2

US1 90 12/2009 1 2

US1 90 12/2009 1 3

I want it to look like:

US1 90 12/2009 2 5

IT1 is my first internal table and WA_IT1 is work area for my first internal table

IT2 is my second interbal table and WA_IT2 is work area for my second internal table

APPEND ls_target TO it1.

SORT it1 BY plant division calmonth.
CLEAR wa_it2.
LOOP AT it1 INTO wa_it1.

  IF wa_it2 IS INITIAL.
    wa_it2 = wa_it1.

**** the first time the above code will execute because WA_IT2
**** will have nothing in it. The second time it will do the comparison which is as follows:

  ELSE.
    IF wa_it1-plant = wa_it2-plant AND
    wa_it1-division = wa_it2-division AND
    wa_it1-calmonth = wa_it2-calmonth.

      IF sy-subrc = 0

      COLLECT it2.
        DELETE ADJACENT DUPLICATES FROM it2 COMPARING plant division calmonth.

      ENDIF.


    ELSE.
      APPEND wa_it2 TO et_target.
    ENDIF.
  ENDIF.
ENDLOOP.
APPEND wa_it2 TO et_target.

Moderator message - Please format your code and use code tags to make it easier to read

Edited by: Rob Burbank on May 4, 2009 5:09 PM

Read only

Former Member
0 Likes
744

If understood, you want group (SUM) of fields in the records. For this, use the command COLLECT statement.

Or check the records one by one using loop (for example).

Adriano