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

code optimisation

Former Member
0 Likes
868

Experts

look at the below code , these statment is taking long

time to execute, problem is requirement is such that

i cannot go for primary key,can anybudy optimise

my code without losing any valuable data

SELECT VBAKVKORG VBAKVBTYP VBAKAUART VBAKVTWEG VBAK~SPART

VBAKKUNNR VBAKKVGR1 VBAKKVGR3 VBAPWERKS VBAP~MATNR

VBAPMVGR1 VBAPMVGR2 VBAPMVGR3 VBAPMVGR3 VBAP~MVGR4

VBAPMVGR5 VBEPVBELN VBEPPOSNR VBEPETENR VBEP~MBDAT

VBAPKDMAT VBEPEDATU

INTO CORRESPONDING FIELDS OF

TABLE INT_OPEN_SCH_LINES

FROM VBAK

INNER JOIN VBAP ON VBAKVBELN = VBAPVBELN

INNER JOIN VBEP ON VBEPPOSNR = VBAPPOSNR AND

VBEPVBELN = VBAKVBELN AND

VBEPVBELN = VBAPVBELN

WHERE VBAP~WERKS IN S_WERKS AND

VBAP~MATNR IN S_MATNR AND

VBAP~MATKL IN S_MATKL AND

VBAP~ABGRU IN S_ABGRU AND

VBAK~KUNNR IN S_KUNNR AND

VBEP~MBDAT = D0 AND

VBAK~VBTYP IN S_VBTYP AND

VBAK~AUART IN S_AUART AND

VBAK~KVGR3 IN S_KVGR3.

9 REPLIES 9
Read only

Former Member
0 Likes
829

Hi,

In se30 transaction you can look for

Tip&TRicks button on application toolbar

apart from below conventions

Follow below steps

1) Remove corresponding from select satement

2) Remove * from select

3) Select field in sequence as defined in database

4) Avoid unnecessary selects

i.e check for internal table not initial

5) Use all entries and sort table by key fields

6) Remove selects ferom loop and use binary search

7) Try to use secondary index when you don't have

full key.

😎 Modify internal table use transporting option

9) Avoid nested loop . Use read table and loop at itab

from sy-tabix statement.

10) free intrenal table memory wnen table is not

required for further processing.

11)

Follow below logic.

FORM SUB_SELECTION_AUFKTAB.

if not it_plant[] is initial.

it_plant1[] = it_plant[].

sort it_plant1 by werks.

delete adjacent duplicates from it_plant1 comparing werks

SELECT AUFNR KTEXT USER4 OBJNR INTO CORRESPONDING FIELDS OF TABLE I_AUFKTAB

FROM AUFK

FOR ALL ENTRIES IN it_plant1

WHERE AUFNR IN S_AUFNR AND

KTEXT IN S_KTEXT AND

  • WERKS IN S_WERKS AND

AUART IN S_AUART AND

USER4 IN S_USER4 AND

werks eq it_plant1-werks.

free it_plant1.

Endif.

ENDFORM. "SUB_SELECTION_AUFKTAB

Regards

Amole

Regards

Amole

Read only

Former Member
0 Likes
829

Table VAPMA is a secondary index table for sales order items based on material. Try that.

Rob

Read only

0 Likes
829

Like this:


SELECT  VBAK~VKORG VBAK~VBTYP VBAK~AUART VBAK~VTWEG VBAK~SPART
        VBAK~KUNNR VBAK~KVGR1 VBAK~KVGR3 VBAP~WERKS VBAP~MATNR
        VBAP~MVGR1 VBAP~MVGR2 VBAP~MVGR3 VBAP~MVGR3 VBAP~MVGR4
        VBAP~MVGR5 VBEP~VBELN VBEP~POSNR VBEP~ETENR VBEP~MBDAT
        VBAP~KDMAT VBEP~EDATU

  INTO CORRESPONDING FIELDS OF
        TABLE INT_OPEN_SCH_LINES
        
  FROM  vapma
    INNER JOIN vbap  ON vapma~vbeln = vbap~vbeln AND
                        vapma~posnr = vbap~posnr
    INNER JOIN vbak  ON vbap~vbeln  = vbak~vbeln
    INNER JOIN vbep  ON vbep~posnr  = vbap~posnr AND
                        vbep~vbeln = vbak~vbeln AND
                        vbep~vbeln = vbap~vbeln


  WHERE vapma~matnr IN s_matnr AND
        vbap~werks IN s_werks AND
        VBAP~MATKL IN S_MATKL AND
        VBAP~ABGRU IN S_ABGRU AND
        VBAK~KUNNR IN S_KUNNR AND
        VBEP~MBDAT = D0 AND
        VBAK~VBTYP IN S_VBTYP AND
        VBAK~AUART IN S_AUART AND
        VBAK~KVGR3 IN S_KVGR3.

Rob

Message was edited by: Rob Burbank

The WHERE claus was still incorrect. I changed it to select using MATNR from VAPMA (which was the whole point to start with).

Message was edited by: Rob Burbank

The JOINs still had problems. I've re-written them and actually tested it this time. It seems to work and runs reasonably quickly.

Message was edited by: Rob Burbank

Read only

0 Likes
829

  from  vbap        
    inner join VBAK  on vbap~vbeln = vbak~vbeln
    inner join vapma on vbap~matnr = vapma~vbeln
    INNER JOIN VBEP  ON VBEP~POSNR = VBAP~POSNR AND
               VBEP~VBELN = VBAK~VBELN AND
               VBEP~VBELN = VBAP~VBELN

I have a couple of issues with this

1. You are joing a material number to a order number

2. i think the last line is unnecesary

3. i am not of the value of using VAPMA


  from  vbap        
    inner join VBAK  on vbak~vbeln = vbap~vbeln
    INNER JOIN VBEP  ON 
               VBEP~VBELN = VBAP~VBELN AND
               VBEP~POSNR = VBAP~POSNR.

this seems to work on my system, anyway

Read only

0 Likes
829

You're right on the first two. I've changed the code. (This is what happens when you don't test.) But what's the problem with VAPMA?

Rob

Read only

0 Likes
829

i just dont see why you need it...

Read only

0 Likes
829

Because the original select isn't using any key fields in the WHERE clause. Adding VAPMA allows the use of its index on MATNR.

Perhaps the original poster would try it and let us know if it helps or not.

Rob

Read only

0 Likes
829

And of course, check that S_MATNR is not empty.

Rob

Read only

0 Likes
829

OK - I tried it. The modified code runs over 4000 times more quickly for a single material and about 9 times more quickly for a range of 100 materials.

They are about even at 1000 materials. (Index uusage becomes less important when selecting large volumes of data.)

Rob

Message was edited by: Rob Burbank