on 02-26-2013 12:40 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
Hi Sebastian,
Here is a pseudo version of the code that I can suggest. Try it and let us know if you face any problem.
Declare three internal tables of same structure.
data:it_1, 2 and 3 type table of xyz.
it_1 = main table (MT)
sort it_1 by handling_code
loop at it_1 ito wa_it_1
at new handling_code
if it_2 is not initial.
"We have our 2nd internal table ready for the calculation here. This table contains records for only one handling_code.
read it_2 where count = 1.
if sy-subrc <> 0. "This means all the records have only zero.
delete it_2 where the index > 1."may be use a loop here. This will leave only the first record.
else.
read it_2 where count = 0.
if sy-subrc <> 0. "This means all the records have only one.
"do nothing here as we need all the records.
else. "we have a mix of 0 and 1.
delete it_2 where count = 0.
endif.
endif.
append it_2 to it_3. "It_3 is our target package
Clear it_2.
else
append wa_it_1 to it_2."For new handling code we just append it to it_2. First append occurs here.
endat.
append wa_it_1 to it_2. "2nd, 3rd and next occurrences are appended here.
end loop.
MT=it_3. "In the end assign your result to required Internal Table.
Regards,
Sujit.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sujit,
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
Here is the exact code which works!!
DATA: ls_source TYPE y_source_fields,
ls_target TYPE y_target_fields.
DATA: IT_XX_TAB1 TYPE STANDARD TABLE OF y_target_fields
WITH NON-UNIQUE KEY CRM_OBJ_ID,
IT_XX_TAB2 TYPE STANDARD TABLE OF y_target_fields
WITH NON-UNIQUE KEY CRM_OBJ_ID.
LOOP AT it_source INTO ls_source.
MOVE-CORRESPONDING ls_source TO ls_target.
IF ls_source-RSTT_COUNT = '0'.
APPEND ls_source TO IT_XX_TAB1.
ELSEIF ls_source-RSTT_COUNT = '1'.
APPEND ls_source TO IT_XX_TAB2.
ENDIF.
ENDLOOP.
* alle Sätze mit dem Zähler = 1 übernehmen
et_target = IT_XX_TAB2 .
* Sätze mit 0 übernehmen nur wenn kein Vorgangsnummer mit 1 vorhanden
SORT IT_XX_TAB1 BY CRM_OBJ_ID.
DELETE ADJACENT DUPLICATES FROM IT_XX_TAB1
COMPARING CRM_OBJ_ID.
LOOP AT IT_XX_TAB1 INTO ls_target.
READ TABLE IT_XX_TAB2 TRANSPORTING NO FIELDS
WITH TABLE KEY CRM_OBJ_ID = ls_target-CRM_OBJ_ID.
IF sy-subrc <> 0.
APPEND ls_target TO et_target.
ENDIF.
ENDLOOP.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.