Skip to Content
0
Former Member
Jan 09, 2013 at 04:51 PM

Changing source_package

527 Views

Hi,

I have a DSO with materials and seasons:

0material

0af_sean

material and season are keys but I can have one material with different seasons

Goal: Create a new DSO with a unique material and season where season is selected by the smallest one, I mean:

Material | Season

121323 | 4

121323 | 1

345234 | 2

985645 | 3

345234 | 5

Result will be:

Material | Season

121323 | 1

345234 | 2

985645 | 3

So, I have created this ABAP in Start routine

*$*$ begin of 2nd part global - insert your code only below this line *

TYPES: Begin of T_temp,

MATNR TYPE C LENGTH 18,

SAISO TYPE C LENGTH 4,

END OF T_temp.


DATA: iT_temp TYPE standard table of T_temp, wa_temp like line of iT_temp.

*$*$ begin of routine - insert your code only below this line *-*

data: wa_SOURCE_PACKAGE type _ty_s_SC_1.

DATA: ITAB type STANDARD TABLE OF _ty_s_SC_1.

* Delete duplicate data from source package

ITAB = SOURCE_PACKAGE[].

SORT ITAB BY MATERIAL AF_SIZE AF_SEAN DESCENDING.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING MATERIAL AF_SIZE AF_SEAN.


clear SOURCE_PACKAGE.


SOURCE_PACKAGE[] = ITAB[].

LOOP AT SOURCE_PACKAGE into wa_SOURCE_PACKAGE.

if wa_SOURCE_PACKAGE-MATERIAL is not initial.

move wa_SOURCE_PACKAGE-MATERIAL to wa_temp-MATNR.

move wa_SOURCE_PACKAGE-AF_SEAN to wa_temp-SAISO.


append wa_temp TO iT_temp.

endif.

ENDLOOP.

In the Field routine for Season I have:

sort iT_temp by saiso.

read table iT_temp into wa_temp with key matnr = SOURCE_FIELDS-MATERIAL.

if sy-subrc = 0.
RESULT = wa_temp-saiso.
endif.

This results in a really bad performance process, can it be optimized? I am not a guru in ABAP, so I am asking for help.

I even don't know if it works, 'cause I can have the same material with different seasons in two or more different packages (source_package), right?

Thank you