Application Development 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: 

BW End Routine Logic

Former Member
0 Kudos
283

I have written the following BW end routine but performance is too slow because of the number of loops.

I have introduced the third loop since we need the records in the specific order to populate ZCUST. Can someone advise on how I can optimize - can I get the results without introducing the third loop

Thanks

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

data: TEMP_RESULT_PACKAGE like RESULT_PACKAGE,

WA_RESULT_PACKAGE type TYS_TG_1,

WA type TYS_TG_1.

TEMP_RESULT_PACKAGE] = RESULT_PACKAGE[.

delete adjacent duplicates from RESULT_PACKAGE

comparing DIVISION DISTR_CHAN SALESORG CUST_SALES.

loop at RESULT_PACKAGE into WA_RESULT_PACKAGE.

clear WA.

loop at TEMP_RESULT_PACKAGE into WA

where DIVISION = WA_RESULT_PACKAGE-DIVISION

and DISTR_CHAN = WA_RESULT_PACKAGE-DISTR_CHAN

and SALESORG = WA_RESULT_PACKAGE-SALESORG

and CUST_SALES = WA_RESULT_PACKAGE-CUST_SALES.

if not WA-SHIP_TO is initial.

WA_RESULT_PACKAGE-SHIP_TO = WA-SHIP_TO.

endif.

if not WA-CUST_HIE01 is initial.

WA_RESULT_PACKAGE-CUST_HIE01 = WA-CUST_HIE01.

endif.

if not WA-CUST_HIE02 is initial.

if not WA-BILLTOPRTY is initial.

WA_RESULT_PACKAGE-BILLTOPRTY = WA-BILLTOPRTY.

endif.

if not WA-PAYER is initial.

WA_RESULT_PACKAGE-PAYER = WA-PAYER.

endif.

if not WA-/BIC/OSSLSREP is initial.

WA_RESULT_PACKAGE-/BIC/ZSREP = WA-/BIC/ZSREP.

endif.

if not WA-/BIC/OSBRO is initial.

WA_RESULT_PACKAGE-/BIC/ZBRO = WA-/BIC/ZBRO.

endif.

if not WA-/BIC/OSCTREMP is initial.

WA_RESULT_PACKAGE-/BIC/ZREMP = WA-/BIC/ZREMP.

endif.

if not WA-/BIC/OSOPR is initial.

WA_RESULT_PACKAGE-/BIC/ZPRI = WA-/BIC/ZPRI.

endif.

endloop.

sort TEMP_RESULT_PACKAGE by DIVISION DISTR_CHAN SALESORG CUST_SALES /BIC/ZBRO /BIC/ZSREP /BIC/ZREMP.

clear WA.

loop at TEMP_RESULT_PACKAGE into WA

where DIVISION = WA_RESULT_PACKAGE-DIVISION

and DISTR_CHAN = WA_RESULT_PACKAGE-DISTR_CHAN

and SALESORG = WA_RESULT_PACKAGE-SALESORG

and CUST_SALES = WA_RESULT_PACKAGE-CUST_SALES.

IF NOT WA-/BIC/ZCUST IS INITIAL.

WA_RESULT_PACKAGE-/bic/ZCUST = WA-/BIC/ZCUST.

ENDIF.

endloop.

modify RESULT_PACKAGE from WA_RESULT_PACKAGE.

clear WA_RESULT_PACKAGE.

endloop.

1 ACCEPTED SOLUTION

hendrik_brandes
Contributor
0 Kudos
116

Hi,

I have to suggestions for you:

1. use typed field-symbols for every loop

2. I try to understand, what you are doing: you will at least be sure, that every necessary/key infoobject is filled with the same value from your result_package.

I would try to separate it in two steps:

1) build up your temp_result_package and make your assignments.

2) do only a efficient read-table (sorted/hashed with key DIVISION DISTR_CHAN SALESORG CUST_SALES /BIC/ZBRO /BIC/ZSREP /BIC/ZREMP and field-symbols) on your inside your loop.

3. by using field-symbols, your modify table is obsolete and costs a lot of time.

Kind regards,

Hendrik

2 REPLIES 2

hendrik_brandes
Contributor
0 Kudos
117

Hi,

I have to suggestions for you:

1. use typed field-symbols for every loop

2. I try to understand, what you are doing: you will at least be sure, that every necessary/key infoobject is filled with the same value from your result_package.

I would try to separate it in two steps:

1) build up your temp_result_package and make your assignments.

2) do only a efficient read-table (sorted/hashed with key DIVISION DISTR_CHAN SALESORG CUST_SALES /BIC/ZBRO /BIC/ZSREP /BIC/ZREMP and field-symbols) on your inside your loop.

3. by using field-symbols, your modify table is obsolete and costs a lot of time.

Kind regards,

Hendrik

Ryan-Crosby
Active Contributor
0 Kudos
116

Hi,

Why wouldn't you simply execute this sort statement before the main processing loop and add the logic for ZCUST into the loop with the temporary copy of the internal table? Looking at your code it appears you are executing this sort for every loop pass instead of doing it once and continually reading the records in sorted order.

sort TEMP_RESULT_PACKAGE by DIVISION DISTR_CHAN SALESORG CUST_SALES /BIC/ZBRO /BIC/ZSREP /BIC/ZREMP.

Regards,

Ryan Crosby