Skip to Content

Problem with select fetching data and processing

Hi Experts,

I am doing performance tuning for a program.

I am fetching data from EKET table based on EBELN , EBELP and EINDT field entries into I_EKET table.

Than I am processing the entries in I_EKET table as


SELECT EBELN EBELP EINDT

FROM EKET

INTO TABLE I_EKET

FOR ALL ENTRIES IN I_EKPO

WHERE EBELN EQ I_EKPO-EBELN

AND EBELP EQ I_EKPO-EBELP

AND EINDT IN S_EINDT.

IF I_EKET[] IS NOT INITIAL.

SORT I_EKET BY EBELN EBELP.

DELETE ADJACENT DUPLICATES FROM I_EKET COMPARING ALL FIELDS.


is it possible to write the sort and delete adjacent duplicates inside the select query itself.


Thanks,

RG

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 17, 2016 at 09:25 PM

    Hi Ramya G,

    I think following select statement will cover your duplicates:

    SELECT distinct EBELN EBELP EINDT

    FROM EKET

    INTO TABLE I_EKET

    FOR ALL ENTRIES IN I_EKPO

    WHERE EBELN EQ I_EKPO-EBELN

    AND EBELP EQ I_EKPO-EBELP

    AND EINDT IN S_EINDT.


    Distinct will filter your duplicates. BUT, distinct also has a low performance.

    (ABAP Performance tips - Contributor Corner [Read-only] - SCN Wiki)



    AND, if you are using a HANA database, it is possible that your data will be unsorted.

    (Best Practice Guide - Considerations for Custom ABAP Code During a Migration to SAP HANA)


    If your data needs to be sorted and you are on a HANA database, then you will have to use the order by statement.

    With a for all entry you can only use 'order by primary key'. However you do not use all the key fields in your select statement so it will not be possible to use the 'order by primary key'.

    So, I think the best way to solve this, is by removing the for all entries.

    I see that you are using a for all entries on EKPO. Did you do a select statement on EKPO before the select statement above? Maybe you can Join them, hereby avoiding the use of a 'for all entries' and nicely place the needed ekpo and eket data in one itab. And place a 'sort by ebeln, ebelp' and a 'group by ebeln ebelp...' in the joined select statement. This is of course only valid if you do not have a for all entries in you EKPO select statement.



    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 19, 2016 at 06:42 AM

    HI Ramya,

    Go for Secondary index to remove any duplicate entries while fetching data.

    Thanks,

    Paul

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.