ABAP 获取动态库存函数效率优化---zmb_select_sd_scheduled_stock

FUNCTION zmb_select_sd_scheduled_stock.
*“----------------------------------------------------------------------
"“本地接口:
*” IMPORTING
*” VALUE(X_KZWSO) LIKE MARA-KZWSM DEFAULT SPACE
*" TABLES
*" ZTAB4 STRUCTURE ZSZTAB4
*" IT_WERKS STRUCTURE /BEV2/ED_RG_S_WERKS
*" IT_MATNR STRUCTURE /CWM/R_MATNR
*"----------------------------------------------------------------------
DATA: lt_vbbe TYPE STANDARD TABLE OF vbbe,
lt_vbbs TYPE STANDARD TABLE OF vbbs.

FIELD-SYMBOLS: TYPE vbbe,
TYPE vbbs.
DATA: vbeda(2) TYPE c VALUE ‘A’, "Anfrage
vbedb(2) TYPE c VALUE ‘B’, "Angebot
vbedc(2) TYPE c VALUE ‘C’, "Auftrag
vbede(2) TYPE c VALUE ‘E’, "Lieferplan
vbedg(2) TYPE c VALUE ‘G’, "Kontrakt
vbedi(2) TYPE c VALUE ‘I’, "Kostenlose Lieferung
vbedj(2) TYPE c VALUE ‘J’. "Lieferung
TYPES: BEGIN OF lty_lips,
vbeln TYPE lips-vbeln,
posnr TYPE lips-posnr,
bwart TYPE lips-bwart,
shkzg TYPE t156-bwart,
END OF lty_lips.
DATA: lt_lips TYPE STANDARD TABLE OF lty_lips WITH HEADER LINE.

  • Aufbau Rangetabelle für Werk ---------------------------------------

  • CLEAR WERKS_RANGE.

  • REFRESH WERKS_RANGE.

  • LOOP AT XWERKS.

  • WERKS_RANGE = XWERKS.

  • APPEND WERKS_RANGE.

  • ENDLOOP.

  • – Ermitteln und kumulieren der Vertriebs-Einzelbedarfe auf die Ebene

  • – feinste Ebene von Werk/Lagerort/Charge ----------------------------
    DATA: loc_menge LIKE mseg-menge,
    loc_umvkz LIKE vbep-umvkz,
    loc_umvkn LIKE vbep-umvkn.

    CHECK it_werks[] IS NOT INITIAL
    AND it_matnr[] IS NOT INITIAL.

  • Optimization HANA
    SELECT vbtyp vbeln posnr etenr SUM( omeng ) AS omeng matnr charg werks werks lgort charg
    FROM vbbe INTO CORRESPONDING FIELDS OF TABLE lt_vbbe
    WHERE matnr IN it_matnr
    AND werks IN it_werks
    AND omeng > 0
    GROUP BY vbtyp vbeln posnr etenr matnr charg werks werks lgort charg.

    IF lt_vbbe[] IS NOT INITIAL.

    SELECT avbeln,aposnr, a~bwart, b~shkzg
    INTO CORRESPONDING FIELDS OF TABLE @lt_lips
    FROM lips AS a
    LEFT JOIN t156 AS b ON a~bwart = b~bwart
    FOR ALL ENTRIES IN @lt_vbbe
    WHERE a~vbeln = @lt_vbbe-vbeln
    AND a~posnr = @lt_vbbe-posnr
    .

    SORT lt_lips[] BY vbeln posnr shkzg.
    ENDIF.

    LOOP AT lt_vbbe ASSIGNING .
    CLEAR:ztab4, loc_umvkz, loc_umvkn, loc_menge.

  • IF NOT x_kzwso IS INITIAL. "ALRK014884 SW Begin

  •  IF -vbtyp EQ vbedi OR
    
  •     -vbtyp EQ vbedj.
    
  •      SELECT SINGLE
    
  •        VRKME UMVKZ UMVKN FROM LIPS
    
  •        INTO (ZTAB4-VRKME, LOC_UMVKZ, LOC_UMVKN)
    
  •       WHERE vbeln = -vbeln AND
    
  •             posnr = -posnr.
    
  •    ELSE.
    
  •      SELECT SINGLE
    
  •        VRKME UMVKZ UMVKN FROM VBEP
    
  •        INTO (ZTAB4-VRKME, LOC_UMVKZ, LOC_UMVKN)
    
  •       WHERE vbeln = -vbeln AND
    
  •             posnr = -posnr AND
    
  •             etenr = -etenr.
    
  •  ENDIF.
    
  •  loc_menge = -omeng.
    
  •    CALL FUNCTION 'MB_UNIT_CONVERSION'
    
  •         EXPORTING
    
  •              ERFME                = ZTAB4-VRKME
    
  •      matnr   = -matnr
    
  •              MENGE                = LOC_MENGE
    
  •              UMREN                = LOC_UMVKN
    
  •              UMREZ                = LOC_UMVKZ
    
  •      charg   = -charg
    
  •      werks   = -werks
    
  •         IMPORTING
    
  •              O_ERFMG              = ZTAB4-WMENG
    
  •         EXCEPTIONS
    
  •              OTHERS               = 7.
    
  • ENDIF. "ALRK014884 SW End
    ztab4-matnr = -matnr.
    ztab4-werks = -werks.
    ztab4-lgort = -lgort.
    ztab4-charg = -charg.
    *— Je nach Bedarfstyp setzen der entsprechenden Menge --------------
    CASE -vbtyp.
    WHEN vbeda.
    MOVE -omeng TO ztab4-vbmna.
    WHEN vbedb.
    MOVE -omeng TO ztab4-vbmnb.
    WHEN vbedc. " Kundenaufträge
    MOVE -omeng TO ztab4-vbmnc.
    WHEN vbede.
    MOVE -omeng TO ztab4-vbmne.
    WHEN vbedg.
    MOVE -omeng TO ztab4-vbmng.
    WHEN vbedi.
    MOVE -omeng TO ztab4-vbmni.
    WHEN vbedj. " Lieferungen an Kunden

  • Vernachlässigung von Retoureneinteilungen aus Konsistenzgründen

  • (z.B. enthält die VBBE nur Positionen, die auch Bedarfe erzeugen;

  • sauberer wäre an dieser Stelle jedoch die Aufsummierung gemäß des

  • Soll-/Habenkennzeichens):

  • Optimization HANA

  •    SELECT SINGLE bwart FROM lips INTO CORRESPONDING FIELDS OF lips WHERE vbeln EQ -vbeln
    
  •                              AND   posnr EQ -posnr.
    
  •    SELECT SINGLE shkzg FROM t156 INTO CORRESPONDING FIELDS OF t156 WHERE bwart EQ lips-bwart.
    
  •    IF t156-shkzg EQ 'H'.
    
  •      MOVE -omeng TO ztab4-vbmnj.
    
  •    ENDIF.
      READ TABLE lt_lips WITH KEY vbeln = -vbeln
                                  posnr = -posnr
                                  BINARY SEARCH.
      IF lt_lips-shkzg = 'H'.
        MOVE -omeng TO ztab4-vbmnj.
      ENDIF.
    

    ENDCASE.
    APPEND ztab4.
    ENDLOOP.

  • – Ermitteln und kumulieren der Vertriebs-Summenbedarfe auf die ------

  • – feinste Ebene von Werk/Lagerort/Charge ----------------------------

  • Optimization HANA
    SELECT matnr werks lgort charg vbtyp SUM( omeng ) AS omeng FROM vbbs INTO CORRESPONDING FIELDS OF TABLE lt_vbbs
    WHERE matnr IN it_matnr
    AND werks IN it_werks
    AND omeng > 0
    GROUP BY matnr werks lgort charg vbtyp.
    LOOP AT lt_vbbs ASSIGNING .
    CLEAR ztab4.
    ztab4-matnr = -matnr.
    ztab4-werks = -werks.
    ztab4-lgort = -lgort.
    ztab4-charg = -charg.
    *— Je nach Bedarfstyp setzen der entsprechenden Menge --------------
    CASE -vbtyp.
    WHEN vbeda.
    MOVE -omeng TO ztab4-vbmna.
    WHEN vbedb.
    MOVE -omeng TO ztab4-vbmnb.
    WHEN vbedc.
    MOVE -omeng TO ztab4-vbmnc.
    WHEN vbede.
    MOVE -omeng TO ztab4-vbmne.
    WHEN vbedg.
    MOVE -omeng TO ztab4-vbmng.
    WHEN vbedi.
    MOVE -omeng TO ztab4-vbmni.
    WHEN vbedj.
    MOVE -omeng TO ztab4-vbmnj.
    ENDCASE.
    APPEND ztab4.
    ENDLOOP.

ENDFUNCTION.

你可能感兴趣的:(ABAP,SAP,abap,SAP)