Skip to Content
0
Aug 17, 2011 at 10:20 AM

Linking tables RSEG and BKPF causing low performance. Suggestions?

250 Views

Hi,

I am linking RSEG and BKPF but there is no direct link between these two tables except AWKEY but that is only first 16 char AWKEY of BKPF.

so i need to pick all entries from BKPF where BLART = 'RE' and BUDAT in DATE. Thus all the entries are coming in one internal table and then i loop through each entry and pick first 16 char of AWKEY and then link both the tables . But it is making the performance very low.

i want to select only those entries from BKPF which are related to my Purchase orders. is there any indirect way?

following is the code :

SELECT
  matnr
  werks
  ebeln
  belnr
  gjahr
  lfbnr
FROM rseg INTO TABLE itab11 FOR ALL ENTRIES IN it1 WHERE werks = it1-werks AND
  matnr = it1-matnr AND ebeln = it1-ebeln.

SELECT  "*ALL THE ENTRIES FROM BKPF ARE PICKED.*
  awkey
  gjahr
  belnr
FROM bkpf INTO TABLE itab13 WHERE blart = 'RE' AND budat IN s_date.


LOOP AT itab13 .
  itab14-awkey = itab13-awkey(16)   .  " *All the entries selected are looped through and first 16 char's are selected.*
  itab14-gjahr = itab13-gjahr.
  itab14-belnr = itab13-belnr.
  APPEND itab14.
ENDLOOP.

SORT itab11 BY belnr gjahr.
SORT itab14 BY awkey gjahr.

LOOP AT itab11.
  READ TABLE itab14 TRANSPORTING NO FIELDS WITH KEY awkey = itab11-belnr.
  IF sy-subrc = 0. 
    tabix = sy-tabix.
    LOOP AT itab14 FROM tabix WHERE awkey = itab11-belnr AND gjahr = itab11-gjahr .
      itab15-matnr = itab11-matnr.        
      itab15-belnr = itab14-belnr.  "* LOOPING THROUGH RSEG and SELECTING ENTRIES WHERE AWKEY = BKPF-AWKEY*
      itab15-werks = itab11-werks.
      itab15-ebeln = itab11-ebeln.
      itab15-gjahr = itab11-gjahr.
      itab15-awkey = itab14-awkey.
      itab15-lfbnr = itab11-lfbnr.
      APPEND itab15.
    ENDLOOP.
  ENDIF.
ENDLOOP.

how to link these two tables efficiently so tht performance can be improved ?

Edited by: VimalSharma on Aug 17, 2011 12:21 PM

<Added code tags>

Edited by: Suhas Saha on Aug 17, 2011 4:55 PM