Home > ABAP > Selecting MKPF-MSEG

Selecting MKPF-MSEG

March 11th, 2009

Selecting data from MKPF and MSEG can be quite tricky.. It will take forever to get just a few rows if you make the wrong selection.

Before you select anything from the table, you need to make sure your selections are in the table’s indexes and make as many conditions possible to restrict an exhaustive selection from the database.

I tried using select in select, get the mkpf in an internal table and then getting the mseg using for all entries, all took a long time… it just didn’t work the way I wanted to be.

And here’s my latest code as an example, and I’m satisfied with it.


PARAMETER: P_MATNR LIKE MARA-MATNR,
P_WERKS LIKE MSEG-WERKS.

SELECT-OPTIONS: SL_BUDAT FOR MKPF-BUDAT.

select <specify the fields you need> into corresponding fields of table <internal table>
from MKPF as F inner join MSEG as E
on ( F~MANDT = E~MANDT AND
F~MBLNR = E~MBLNR AND
F~MJAHR = E~MJAHR )
where F~MANDT = SY-MANDT
AND F~MBLNR GT D_MBLNR
AND MATNR = P_MATNR
AND WERKS = P_WERKS
AND F~MJAHR GE SL_BUDAT-LOW(4)
AND BUDAT GE SL_BUDAT-LOW
AND BUDAT LE SL_BUDAT-HIGH.

And you’ll get your data in no time… Enjoy!

vera ABAP

  1. No comments yet.
  1. No trackbacks yet.