Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Need Help with selection

hi all.

In the below code i want to add material group wise selection and remove plant wise selection.

Can any one please help me out.

SELECTION-SCREEN BEGIN OF BLOCK b1    WITH FRAME TITLE text-001.
PARAMETERS : p_bklas like mbewh-bklas OBLIGATORY,
             p_bukrs LIKE mseg-bukrs OBLIGATORY.
SELECT-OPTIONS :  s_werks FOR t001k-bwkey,              " Plant
                                s_budat FOR mkpf-budat OBLIGATORY NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK b1.
SELECT bukrs bwkey  FROM t001k INTO TABLE it_werks
                  WHERE bukrs = p_bukrs
                  AND bwkey IN s_werks.
  if sy-subrc = 0.
    select ms~mblnr ms~mjahr mk~blart mk~budat ms~zeile ms~bwart
           ms~xauto ms~matnr ms~werks ms~charg ms~shkzg ms~dmbtr ms~menge
           ms~meins ms~bualt "ma~matkl
           from mkpf as mk
           inner join mseg as ms on
           mk~mandt = ms~mandt
           and mk~mblnr = ms~mblnr
           and mk~mjahr = ms~mjahr
           into corresponding fields of table it_mkpf3
           for all entries in it_werks
           where mk~budat in s_budat
             and ms~mjahr = v_myear
             and bukrs    = it_werks-bukrs
             and ms~werks = it_werks-bwkey.
    select matnr matkl from mara into table it_mara
           for all entries in it_mkpf3
           where matnr = it_mkpf3-matnr.
    loop at it_mkpf3 .
      read table it_mara with key matnr = it_mkpf3-matnr.
      it_mkpf-mblnr = it_mkpf3-mblnr.
      it_mkpf-mjahr = it_mkpf3-mjahr.
      it_mkpf-blart = it_mkpf3-blart.
      it_mkpf-budat = it_mkpf3-budat.
      it_mkpf-zeile = it_mkpf3-zeile.
      it_mkpf-bwart = it_mkpf3-bwart.
      it_mkpf-xauto = it_mkpf3-xauto.
      it_mkpf-matnr = it_mkpf3-matnr.
      it_mkpf-werks = it_mkpf3-werks.
      it_mkpf-charg = it_mkpf3-charg.
      it_mkpf-shkzg = it_mkpf3-shkzg.
      it_mkpf-dmbtr = it_mkpf3-dmbtr.
      it_mkpf-menge = it_mkpf3-menge.
      it_mkpf-meins = it_mkpf3-meins.
      it_mkpf-bualt = it_mkpf3-bualt.
      it_mkpf-matkl = it_mara-matkl.
      append it_mkpf.
    endloop.
    select matnr bwkey lbkum salk3 bklas lfgja lfmon
           from mbew
           into table it_mbew
           for all entries in it_werks
           where bwkey = it_werks-bwkey
           and   bklas = p_bklas.
    select  matnr bwkey lfgja lfmon  lbkum salk3  bklas
           from mbewh
           into table it_mbewh
           for all entries in it_mbew
           where  matnr = it_mbew-matnr
           and   bwkey = it_mbew-bwkey
           and   lfgja eq v_year
           and   lfmon ge v_period.
    sort  it_mbewh BY lfgja ASCENDING lfmon ASCENDING.
    select matnr matkl from mara into table it_mara1
           for all entries in it_mbew
           where matnr = it_mbew-matnr.
    if sy-subrc = 0.
      loop at it_mbew.
        read table it_mara1 with key matnr  = it_mbew-matnr.
        it_mardh-matnr = it_mbew-matnr.
        it_mardh-werks = it_mbew-bwkey.
        it_mardh-lfgja = it_mbew-lfgja.
        it_mardh-lfmon = it_mbew-lfmon.
        read table it_mbewh with key matnr = it_mbew-matnr
                                     bwkey = it_mbew-bwkey.
        if sy-subrc = 0 .
          it_mardh-bklas = it_mbewh-bklas.
          it_mardh-salk3 = it_mbewh-salk3.
          it_mardh-lbkum = it_mbewh-lbkum.
        else.
          it_mardh-bklas = it_mbew-bklas.
          it_mardh-salk3 = it_mbew-salk3.
          it_mardh-lbkum = it_mbew-lbkum.
        endif.
        it_mardh-matkl = it_mara1-matkl.
        append it_mardh.
        clear it_mardh.
        clear it_mbewh.
        clear it_mara1.
        clear it_mbew.
      endloop.
    endif.
    sort it_mardh by werks matnr.
    select bukrs belnr gjahr blart budat into table it_bkpf9
           from bkpf
           where bukrs = p_bukrs
           and   blart = 'RE'
           and   budat in s_budat
           or    bukrs = p_bukrs
           and   blart = 'PR'
           and   budat in s_budat.
    if sy-subrc = 0.
      select bukrs belnr gjahr buzei buzid shkzg dmbtr matnr werks
             from bseg
             into table it_bseg9
             for all entries in it_bkpf9
             where bukrs = it_bkpf9-bukrs
             and   belnr = it_bkpf9-belnr
             and   gjahr = it_bkpf9-gjahr
             and   werks in s_werks
             and   buzid = 'M'.
    endif.

  endif.
* END-OF-SELECTION.
END-OF-SELECTION.

Former Member
Not what you were looking for? View more on this topic or Ask a question