2013 Feb 26 12:30 PM
Hello Gurus,
I am trying to delete selective rows based on the following conditions:
As seen in the screenshot, the first column contains Handling Codes and the last column contains counter values.
If a Handling Code contains MULTIPLE rows with counter value '0', ONLY ONE row must be displayed. It could be the first or last. (0000379651)
If a Handling Code contains only a SINGLE row with counter value '0', it must be displayed. (0000379831)
If a Handling Code contains MULTIPLE rows with counter value '1', ALL rows must be displayed. (0000379834)
If a Handling Code contains MULTIPLE rows with counter values '1' and '0', ALL rows containing value '1' must be displayed and those containing '0' must be omitted. (0000380009)
Plainly said all highlighted rows have to be deleted/suppressed.
How can I achieve this in a routine which I am programming in an APD?
Pls Help. Many Thanks.
SD
Message was edited by: Kesavadas Thekkillath
Hello Gurus,
I am trying to delete selective rows based on the following conditions:
As seen in the screenshot, the first column contains Handling Codes and the last column contains counter values.
If a Handling Code contains MULTIPLE rows with counter value '0', ONLY ONE row must be displayed. It could be the first or last. (0000379651)
If a Handling Code contains only a SINGLE row with counter value '0', it must be displayed. (0000379831)
If a Handling Code contains MULTIPLE rows with counter value '1', ALL rows must be displayed. (0000379834)
If a Handling Code contains MULTIPLE rows with counter values '1' and '0', ALL rows containing value '1' must be displayed and those containing '0' must be omitted. (0000380009)
Plainly said all highlighted rows have to be deleted/suppressed.
How can I achieve this in a routine which I am programming in an APD?
Pls Help. Many Thanks.
SD
Message was edited by: Kesavadas Thekkillath
2013 Feb 26 1:09 PM
Hi Sebastian,
I am not going to write full code for this but I want to give you some hints.
I am missing also condition what happens if there are many 1 and many 0 for Handling Code (I guess we leave only rows with 1 and ignores rows with 0).
LOOP AT lt_table into ls_row.
AT NEW vorgangsnummer. " reset counters
l_zahler_zero_count = 0.
l_zahler_one_count = 0.
END AT.
IF ( ls_row-zahler = 0 ).
ADD 1 TO l_zahler_zero_count.
ELSEIF ( ls_row-zahler = 1).
ADD 1 TO l_zahler_one_count.
ENDIF.
IF ( ... ). " If your condition is fullfiled and row is needed then
APPEND ls_row TO lt_new_result_table.
ENDIF.
AT END OF vorgangsnummer. " optionally do summary action before we switch to new Handling Code
END AT.
ENDLOOP.
I let you build solution according to your own imagination
Regards
Adam
2013 Feb 26 1:28 PM
A possible approach:
1. sort your table on Vorgangsnummer and Zahler
2. remove any duplicates comparing those 2 fields
3. check the remaining contents in the table on occurences of both 0 and 1 for a Vorgangsnummer and delete the occurance of Vorgansnummer with Zahler 0
Just noticed you want to keep the rows with only Zahler 1.
1. copy all entries with Zahler 1 to a second table B
2. remove all entries with Zahler 1 from your original table
3. sort your original table on Vorgangsnummer and Zahler
4. remove any duplicates comparing Vorgangsnummer and Zahler
5. merge your original table with the contents from table B but make sure if there's a Vorgangsnummer in Zahler 0 in your orignal table, you remove that entry first.
2013 Feb 28 1:27 PM
Hi Maen,
thanks for your reply. I have used the following logic...
1. copied all records with counter value '0' in internal table it_1
2. deleted adjacent duplicates in it_1. Hence i am left with the desired records
3. copied all records with counter value '1' in internal table it_2
4. merged it_1 and it_2.
This logic works fine. The only problem is that in case of handling number 0000380009 I am left with 2 records i.e. one record with value '1' and the other with value '0'. How do I overcome this? I have attached the code.
Thanks,
SD
2013 Feb 28 2:07 PM
please replace your second merging loop with this.
loop at the table which contains all zero counters and check if the handling code is already exist in the table which contains all 1 counters. if sy-subrc equal 0 dont append the record else append the record.
LOOP AT IT_XX_TAB1 INTO STR_TAB1.
read table it_xx_tab2 into str_tab2 where str_tab1-<handling code>.
if sy-subrc NE 0.
assign the values and append record.
endif.
endloop.
2013 Feb 26 1:39 PM
No need to do anything here as you want all lines.
Get all counter ones in an internal table itab1.
Loop at itab1.
read main itab with handling code = itab1-handling code and counter = 0 .
.
if sy-subrc = 0.
delete entry from main itab where handling code = itab1-handling code and counter = 0.
endif.
endloop.
In the end append lines of the temp itabs that you used into a final output internal table.
2013 Feb 26 6:18 PM
Hi Sebastian,
Here u need to use the loop inside the loop where first loop handling code is compared with inner loop handling code and more over set a flag when counter becomes 0 for outer loop(first loop), if flag is set then only compare the first loop handling code with second loop handling code. Here the comparsion should be from second record onwards for inner loop. If both are matched the delete the record from internal table.
Regards,
B. Vineesh
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |