Skip to Content
author's profile photo Former Member
Former Member

Looping to retrieve data takes long time,

Hi All,

I have this following piece of code which takes a long time to retriwve the whole data that i need.

I need to get the MSEG-MKPF data into the I_MSEG table for the given selections and when ever this data is not available, i should store the material number in another table i_mvke_summ.

loop at i_mvke.

*     SELECT MSEG MOVEMENT ACTIVITY RECORDS
    select mseg~matnr mseg~kunnr mseg~werks mkpf~budat
           mseg~mblnr mseg~menge mseg~bwart mseg~shkzg
           mseg~zeile mseg~charg mkpf~xblnr 
           appending table i_mseg
           from ( mkpf inner join mseg on
                  mseg~mblnr =  mkpf~mblnr and
                  mseg~mjahr =  mkpf~mjahr )
            where mkpf~budat ge s_date-low
              and mseg~matnr =  i_mvke-matnr
              and mseg~werks in s_werks
              and mseg~sobkz in r_sobkz
              and mseg~kunnr in r_kunnr.
    if sy-subrc ne 0.
      i_mvke_summ = i_mvke.                        
      append i_mvke_summ.                         
    endif.

  endloop.

Please advice me on any other way of doing this.

How can i use "For all Entries" and also be able to get the data about the missing materials into the i_mvke_summ table. All i need is the materials which do not have MSEG records in to the i_mvke_summ table.

Thanks in advance..!

Jr.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 02, 2006 at 05:13 PM

    Hi,

    Try this..Use FOR ALL ENTRIES and get all the data and then loop at i_mvke and get the records that are not in mseg..

    • SELECT MSEG MOVEMENT ACTIVITY RECORDS

    select msegmatnr msegkunnr msegwerks mkpfbudat

    msegmblnr msegmenge msegbwart msegshkzg

    msegzeile msegcharg mkpf~xblnr

    appending table i_mseg

    from ( mkpf inner join mseg on

    msegmblnr = mkpfmblnr and

    msegmjahr = mkpfmjahr )

    <b> FOR ALL ENTRIES IN I_MVKE</b>

    where mkpf~budat ge s_date-low

    and mseg~matnr = i_mvke-matnr

    and mseg~werks in s_werks

    and mseg~sobkz in r_sobkz

    and mseg~kunnr in r_kunnr.

    if sy-subrc ne 0.

    <b> i_mvke_summ[] = i_mvke[]. </b>

    endif.

    <b>LOOP AT I_MVKE.

    READ TABLE I_MSEG WITH KEY MATNR = I_MVKE-MATNR.

    if sy-subrc ne 0.

    i_mvke_summ = i_mvke.

    append i_mvke_summ.

    endif.

    ENDLOOP.</b>

    Hope this helps..

    Thanks

    Naren

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 02, 2006 at 05:10 PM

    Select in side a loop will take a long time,

    instead you better use all entries and loop , then use the read statement to the second table.. it will give better performance.

    and delete records as per your condition.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 02, 2006 at 05:14 PM

    Do like this:

    if not i_mvke[] is initial.

    select msegmatnr msegkunnr msegwerks mkpfbudat

    msegmblnr msegmenge msegbwart msegshkzg

    msegzeile msegcharg mkpf~xblnr

    appending table i_mseg

    from ( mkpf inner join mseg on

    msegmblnr = mkpfmblnr and

    msegmjahr = mkpfmjahr )

    for all entries in i_mvke

    where mkpf~budat ge s_date-low

    and mseg~matnr = i_mvke-matnr

    and mseg~werks in s_werks

    and mseg~sobkz in r_sobkz

    and mseg~kunnr in r_kunnr.

    if sy-subrc = 0.

    loop at i_mvke.

    read table i_mseg with key matnr = i_mvke-matnr.

    if sy-subrc ne 0.

    i_mvke_summ = i_mvke.

    append i_mvke_summ.

    endif.

    endloop.

    endif.

    Regards,

    Prakash.

    endif.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 02, 2006 at 05:32 PM

    Keep the select outside of the loop and use for all entries.

    Loop the main internal table i_mvke.

    Now read the above internal table.

    endloop.

    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.