Skip to Content
0
Former Member
Mar 01, 2010 at 10:28 AM

Need Help in code optimization

13 Views

Hi Experts,

Its a performance issue. I used simple program to find the combinations based on the input.

For Example if input is : 123,

then the possible combinations are,

23 - without 1.

13 - without 2.

12 - without 3.

123

1

2

3

Like wise i need to find the combination for each input. I developped the code and its working fine upto

13 digit input[1234567890123].

But for then 13 digit it took long time to find the combination. Im in the need of reduce the of execution.

Please find the code below. The Do.. End do is used or input. If Do 3 times means the input is 123. if do 15 times means the input is [123456789012345].

{}

DATA : lv_input_str TYPE string VALUE '1111'.

TYPES : BEGIN OF ls_ret_tab,

docno TYPE vbeln,

price TYPE netpr,

END OF ls_ret_tab.

TYPES : BEGIN OF it_tab,

index TYPE sy-index,

docno TYPE vbeln,

price TYPE netpr,

END OF it_tab.

DATA : lt_ret_tab TYPE TABLE OF ls_ret_tab WITH HEADER LINE,

it_tab TYPE STANDARD TABLE OF it_tab WITH HEADER LINE.

DATA : BEGIN OF gt_main OCCURS 0,

index TYPE sy-index,

level TYPE i,

table LIKE TABLE OF it_tab,

total TYPE netpr,

diffe TYPE netpr,

END OF gt_main.

DATA : t1 TYPE i,

t2 TYPE i,

t3 TYPE i.

START-OF-SELECTION.

DO 13 TIMES.

it_tab-index = sy-index.

APPEND it_tab.

ENDDO.

CLEAR t1.

GET RUN TIME FIELD t1.

PERFORM get_possible_values.

gt_main-index = 0.

gt_main-table = it_tab[].

APPEND gt_main.

SORT gt_main BY table.

  • SORT gt_main BY total DESCENDING.

DELETE ADJACENT DUPLICATES FROM gt_main COMPARING table.

GET RUN TIME FIELD t2.

END-OF-SELECTION.

DATA : lines TYPE i.

t3 = t2 - t1.

WRITE :/ 'time', t3.

LOOP AT gt_main.

WRITE :/5 gt_main-index, 20 gt_main-total.

LOOP AT gt_main-table INTO it_tab.

  • WRITE :/15 it_tab-docno.

WRITE :/15 it_tab-index.

ENDLOOP.

ENDLOOP.

FORM get_possible_values.

DATA : l_lines TYPE i.

DESCRIBE TABLE it_tab LINES l_lines.

IF l_lines <= 1.

"Append Return Table.

EXIT.

ELSE.

PERFORM get_all_values TABLES it_tab.

ENDIF.

ENDFORM. " GET_POSSIBLE_VALUES

FORM get_all_values TABLES it_tab STRUCTURE it_tab.

DATA : lv_pos TYPE i,

lv_pos1 TYPE i.

DATA : it_com TYPE STANDARD TABLE OF it_tab WITH HEADER LINE,

lv_input_str_index TYPE i,

it_main_temp LIKE TABLE OF gt_main WITH HEADER LINE,

lt_tab TYPE STANDARD TABLE OF it_tab WITH HEADER LINE..

CLEAR : lv_input_str_index.

STATICS : l_level TYPE i.

DATA : l_lines TYPE i.

DESCRIBE TABLE it_tab LINES l_lines.

DO l_lines TIMES.

lv_input_str_index = lv_input_str_index + 1.

REFRESH it_com.

LOOP AT it_tab.

IF sy-tabix EQ lv_input_str_index.

CONTINUE.

ENDIF.

APPEND it_tab TO it_com.

it_main_temp-total = it_main_temp-total + it_tab-price.

ENDLOOP.

READ TABLE gt_main WITH KEY table = it_com[].

IF sy-subrc NE 0.

it_main_temp-index = lv_input_str_index.

it_main_temp-table = it_com[].

APPEND it_main_temp.

ENDIF.

CLEAR : it_main_temp-total.

ENDDO.

SORT it_main_temp BY table.

DELETE ADJACENT DUPLICATES FROM it_main_temp[] COMPARING table.

APPEND LINES OF it_main_temp[] TO gt_main.

LOOP AT it_main_temp.

DESCRIBE TABLE it_main_temp-table[] LINES l_lines.

IF l_lines <= 1.

CONTINUE.

ELSE.

PERFORM get_all_values TABLES it_main_temp-table[].

ENDIF.

ENDLOOP.

ENDFORM. " GET_ALL_VALUES

{}

Thanks,

Helps will be appreciated.

Edited by: Nandini on Mar 1, 2010 11:28 AM