Application Development and Automation 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: 
Read only

Need an optimized version for my code.

aris_hidalgo
Contributor
0 Likes
455

Hello experts,

I am currently enhancing my report so that when we transport it to production it will

optimized at its best. In one part of my report, there is this code inside a method:

FIELD-SYMBOLS: <fs_bsis_bsas> LIKE LINE OF it_bsis_bsas.

  • get currency

LOOP AT it_bsis_bsas ASSIGNING <fs_bsis_bsas>.

MOVE <fs_bsis_bsas>-waers TO wa_waers.

APPEND wa_waers TO it_waers.

<fs_bsis_bsas>-year_dum = <fs_bsis_bsas>-bldat+0(4).

ENDLOOP.

SORT it_waers BY waers.

DELETE ADJACENT DUPLICATES FROM it_waers.

Now, it gets the currencies from table it_bsis_bsas and puts them in a new itab. But

it loops through duplicate currencies and I only need to get one for each currency.

As you can see I am just deleting duplicate values using the DELETE ADJACENT statement.

Is there a faster alternative to this?

Also, In the loop I am moving the waers to a work area then appending it to the itab.

I is there a way to use field-symbols here so theres no need to for the append statement?

Comments and suggestions will be appreciated!

1 ACCEPTED SOLUTION
Read only

former_member186741
Active Contributor
0 Likes
434

iF YOU HAVE YOUR TABLE DEFINED LIKE THIS:

data it_waers type sorted table of ty_waers with unique key waers.

yOU CAN:

INSERT WA_WAERS INTO TABLE IT_WAERS.

This will only insert one entry per currency. Duplicates will not happen and it will not fall over when they are attempted to be added. So you don't need to sort or remove adj duplicates.

4 REPLIES 4
Read only

Former Member
0 Likes
434

Hi,

  • get currency

LOOP AT it_bsis_bsas ASSIGNING <fs_bsis_bsas>.

<b>AT NEW <fs_bsis_bsas>-waers.</b>MOVE <fs_bsis_bsas>-waers TO wa_waers.

APPEND wa_waers TO it_waers.

<fs_bsis_bsas>-year_dum = <fs_bsis_bsas>-bldat+0(4).

<b>ENDAT.</b>

ENDLOOP.

SORT it_waers BY waers.

<b>*DELETE ADJACENT DUPLICATES FROM it_waers. "Commented</b>

Best regards,

Prashant

Read only

0 Likes
434

How many records are we talking about here? How many records could there be in IT_BSIS_BSAS. If not that many, you will not see a difference in performance. You might want to focus your attention to the SELECT statements and make sure that they are optimized.

Another thing, instead of deleting out the records after building IT_WAERS, you can just not add them if it already exists. Inside your loop, read the IT_WAERS with key using BINARY SEARCH, if you get a hit, don't add it. Then you don't need to delete duplicates after the LOOP.

REgards

Rich Heilman

Read only

0 Likes
434

Hi guys,

Thanks for the helpful replies. the records really depends on the selection of the user. It can go from 100 records to a thousand. Below are the select statements in the report:

----


  • Selection screen *

----


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_bukrs TYPE t001-bukrs OBLIGATORY,

p_asof TYPE bsis-budat OBLIGATORY,

p_year TYPE bsis-gjahr OBLIGATORY.

SELECT-OPTIONS: s_hkont FOR bsis-hkont NO INTERVALS OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b1.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

  • PERCENTAGE = 0

text = 'Getting data...'

.

  • get records from BSIS

SELECT hkont zuonr gjahr belnr waers bldat blart dmbtr wrbtr shkzg

FROM bsis

INTO CORRESPONDING FIELDS OF TABLE it_bsis_bsas

WHERE bukrs = p_bukrs

AND hkont IN s_hkont

AND budat <= p_asof.

  • get records from BSAS

SELECT hkont zuonr gjahr belnr waers bldat blart dmbtr wrbtr shkzg

FROM bsas

APPENDING CORRESPONDING FIELDS OF TABLE it_bsis_bsas

WHERE bukrs = p_bukrs

AND hkont IN s_hkont

AND budat <= p_asof

AND augdt > p_asof.

  • if itab has no records, raise event

IF it_bsis_bsas[] IS INITIAL.

RAISE EVENT no_data EXPORTING hkont = s_hkont-low.

ENDIF.

Thanks again!

Read only

former_member186741
Active Contributor
0 Likes
435

iF YOU HAVE YOUR TABLE DEFINED LIKE THIS:

data it_waers type sorted table of ty_waers with unique key waers.

yOU CAN:

INSERT WA_WAERS INTO TABLE IT_WAERS.

This will only insert one entry per currency. Duplicates will not happen and it will not fall over when they are attempted to be added. So you don't need to sort or remove adj duplicates.