cancel
Showing results for 
Search instead for 
Did you mean: 

A start /end routine to delte/exclude fields with same values

Former Member
0 Kudos

Hello ,

I'm new to start/end routine, and I would appreciate if some helps with a routine to do the following clean up:

I have a table with the following fields:

Product Id (PROD_ID), Assignment Number (ASSNo), Document Number (DOC_NO), Balance.

The routine would perform the following :

Loop into the table, find all the records for which product ID are the same, then:

If more than one record has the same ASSNo and the sum (balance) = 0, delete them, otherwise keep one of the record and the balance.

IF product Id is the same, and the Assno are different, but they records have the same DOC_NO, and the sum (balance) = 0, delete them, otherwise keep one of the record and the balance.

if no records with the same PROD_ID, then load everything .

Thanks in advance for your help.

JHN

Accepted Solutions (0)

Answers (1)

Answers (1)

kohesco
Active Contributor
0 Kudos

DATA : it_beh_ver LIKE SOURCE_PACKAGE,
it_beh_dienst LIKE source_package,
it_result LIKE source_package,
wa_result LIKE LINE OF it_result,
sum TYPE I,

count_ver type I

vount_dienst type I.
it_beh_ver[] = SOURCE_PACKAGE[].
it_beh_dienst[] = SOURCE_PACKAGE[].
FIELD-SYMBOLS: <ver> LIKE <SOURCE_FIELDS>,
<dienst> LIKE <SOURCE_FIELDS>.
SORT it_beh_Ver BY BEH_AANID BEH_VER.
DELETE ADJACENT DUPLICATES FROM it_beh_Ver COMPARING BEH_AANID BEH_VER.
SORT it_beh_dienst BY BEH_AANID BEH_VER.
DELETE ADJACENT DUPLICATES FROM it_beh_dienst COMPARING BEH_AANID BEH_dienst.
DELETE ADJACENT DUPLICATES FROM source_package COMPARING BEH_AANID.
LOOP AT SOURCE_PACKAGE ASSIGNING <SOURCE_FIELDS>.
CLEAR: sum, wa_result, count_ver, count_dienst.
UNASSIGN <ver>.
LOOP AT it_beh_ver ASSIGNING <ver>.
sum = sum + <ver>-record."replace by balance

count_ver = count_ver +1.
ENDLOOP.
If sum <> 0.
MOVE <ver> TO wa_result."it will always be the last record updated
APPEND wa_result TO it_result.
ENDIF.
UNASSIGN <dienst>.
LOOP AT it_beh_dienst ASSIGNING <dienst>.
sum = sum + <dienst>-record."replace by balance

count_dienst = count_dienst +1.
ENDLOOP.
If sum <> 0.
MOVE <dienst> TO wa_result."it will always be the last record updated
APPEND wa_result TO it_result.
ENDIF.
IF count_ver IS INITIAL AND count_dienst IS INITIAL.
MOVE <source_fields> TO wa_result."update of single record
APPEND wa_result TO it_result.
ENDIF.
ENDLOOP.
REFRESH source_package.
source_package[] = it_result[].