Stock overview and cost assignment - 4
* Get Cost of Goods Sold data
* Get the Material data
* Get WIP data
* Get Inventory data[@more@]
*&---------------------------------------------------------------------*
*& Form FRM_GET_SO_STOCK
*&---------------------------------------------------------------------*
* Extract Sales Order Stock
*----------------------------------------------------------------------*
FORM FRM_GET_SO_STOCK .
DATA:
LTD_EBEWH TYPE TABLE OF TYP_EBEW, " Material Valuation
LTH_EBEW LIKE LINE OF TD_EBEW,
LTH_EBEWH LIKE LINE OF LTD_EBEWH.
DATA:
LW_INDEX TYPE SY-TABIX.
* Extract Current stock
SELECT MATNR " Material Number
BWKEY " Valuation Area
BKLAS " Valuation Class
VBELN " Sales and Distribution Document Number
POSNR " Item number of the SD document
LFGJA " Fiscal Year of Current Period
LFMON " Current period (posting period)
LBKUM " Total Valuated Stock
SALK3 " Value of Total Valuated Stock
VERPR " Moving Average Price/Periodic Unit Price
STPRS " Standard price
PEINH " Price Unit
VPRSV " Price Control Indicator
INTO CORRESPONDING FIELDS OF TABLE TD_EBEW
FROM EBEW
WHERE BWKEY = P_WERKS " Valuation Area
AND MATNR IN S_MATNR " Material Number
AND ( BKLAS = C_2100
OR BKLAS = C_2110 ).
LOOP AT TD_EBEW INTO LTH_EBEW.
LW_INDEX = SY-TABIX.
IF LTH_EBEW-LFGJA > P_GJAHR
OR ( LTH_EBEW-LFGJA = P_GJAHR
AND LTH_EBEW-LFMON => P_PERID ).
REFRESH LTD_EBEWH.
"Extract Current stock
SELECT MATNR " Material Number
BWKEY " Valuation Area
BKLAS " Valuation Class
VBELN " Sales and Distribution Document Number
POSNR " Item number of the SD document
LFGJA " Fiscal Year of Current Period
LFMON " Current period (posting period)
LBKUM " Total Valuated Stock
SALK3 " Value of Total Valuated Stock
VERPR " Moving Average Price/Periodic Unit Price
STPRS " Standard price
PEINH " Price Unit
VPRSV " Price Control Indicator
INTO CORRESPONDING FIELDS OF TABLE LTD_EBEWH
UP TO 1 ROWS
FROM EBEWH
WHERE MATNR = LTH_EBEW-MATNR
AND BWKEY = LTH_EBEW-BWKEY
AND BKLAS = LTH_EBEW-BKLAS
AND ( LFGJA < P_GJAHR
OR ( LFGJA = P_GJAHR
AND LFMON <= P_PERID ) )
AND VBELN = LTH_EBEW-VBELN
AND POSNR = LTH_EBEW-POSNR
ORDER BY LFGJA DESCENDING
LFMON DESCENDING.
IF SY-SUBRC = 0.
READ TABLE LTD_EBEWH INTO LTH_EBEWH INDEX 1.
IF SY-SUBRC = 0.
MODIFY TD_EBEW FROM LTH_EBEWH INDEX LW_INDEX.
ENDIF.
REFRESH LTD_EBEWH.
CLEAR LTH_EBEWH.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " FRM_GET_SO_STOCK
*&---------------------------------------------------------------------*
*& Form FRM_GET_CONS_STOCK
*&---------------------------------------------------------------------*
* Extract Valuated Stock with Subcontractor(From OBEW/OBEWH)
*----------------------------------------------------------------------*
FORM FRM_GET_CONS_STOCK .
DATA:
LTD_OBEWH TYPE TABLE OF TYP_OBEW,
LTH_OBEW LIKE LINE OF TD_OBEW,
LTH_OBEWH LIKE LINE OF LTD_OBEWH.
DATA:
LW_INDEX TYPE SY-TABIX.
* Extract Current stock
SELECT MATNR " Material Number
BWKEY " Valuation Area
BKLAS " Valuation Class
LIFNR " Account Number of Vendor or Creditor
LFGJA " Fiscal Year of Current Period
LFMON " Current period (posting period)
LBKUM " Total Valuated Stock
SALK3 " Value of Total Valuated Stock
VERPR " Moving Average Price/Periodic Unit Price
STPRS " Standard price
PEINH " Price Unit
VPRSV " Price Control Indicator
INTO CORRESPONDING FIELDS OF TABLE TD_OBEW
FROM OBEW
WHERE BWKEY = P_WERKS " Valuation Area
AND MATNR IN S_MATNR " Material Number
AND ( BKLAS = C_2100
OR BKLAS = C_2110 ).
LOOP AT TD_OBEW INTO LTH_OBEW.
LW_INDEX = SY-TABIX.
IF LTH_OBEW-LFGJA > P_GJAHR
OR ( LTH_OBEW-LFGJA = P_GJAHR
AND LTH_OBEW-LFMON => P_PERID ).
* Extract Current stock
SELECT MATNR " Material Number
BWKEY " Valuation Area
BKLAS " Valuation Class
LIFNR " Account Number of Vendor or Creditor
LFGJA " Fiscal Year of Current Period
LFMON " Current period (posting period)
LBKUM " Total Valuated Stock
SALK3 " Value of Total Valuated Stock
VERPR " Moving Average Price/Periodic Unit Price
STPRS " Standard price
PEINH " Price Unit
VPRSV " Price Control Indicator
INTO CORRESPONDING FIELDS OF TABLE LTD_OBEWH
UP TO 1 ROWS
FROM OBEWH
WHERE MATNR = LTH_OBEW-MATNR
AND BWKEY = LTH_OBEW-BWKEY
AND BKLAS = LTH_OBEW-BKLAS
AND ( LFGJA < P_GJAHR
OR ( LFGJA = P_GJAHR
AND LFMON <= P_PERID ) )
AND LIFNR = LTH_OBEW-LIFNR
ORDER BY LFGJA DESCENDING
LFMON DESCENDING.
IF SY-SUBRC = 0.
READ TABLE LTD_OBEWH INTO LTH_OBEWH INDEX 1.
IF SY-SUBRC = 0.
MODIFY TD_OBEW FROM LTH_OBEWH INDEX LW_INDEX.
ENDIF.
REFRESH LTD_OBEWH.
CLEAR LTH_OBEWH.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " FRM_GET_CONS_STOCK
*&---------------------------------------------------------------------*
*& Form FRM_GET_NORMAL_STOCK
*&---------------------------------------------------------------------*
* Extract normal stock
*----------------------------------------------------------------------*
FORM FRM_GET_NORMAL_STOCK .
DATA:
LW_INDEX LIKE SY-TABIX,
LTH_MBEW LIKE LINE OF TD_MBEW,
LTD_MBEWH TYPE TABLE OF TYP_MBEW,
LTH_MBEWH LIKE LINE OF LTD_MBEWH.
* Extract normal stock
SELECT MBEW~MATNR "Material Number
MBEW~BWKEY "Valuation Area
MBEW~BKLAS "Valuation Class
MBEW~BWTAR "Valuation Type
MBEW~LFGJA "Fiscal Year of Current Period
MBEW~LFMON "Current period (posting period)
MBEW~LBKUM "Total Valuated Stock
MBEW~SALK3 "Value of Total Valuated Stock
MBEW~VPRSV "Price Control Indicator
MBEW~VERPR "Moving Average Price/Periodic Unit Price
MBEW~STPRS "Standard price
MBEW~PEINH "Price Unit
MARA~MTART
MARA~MEINS
INTO CORRESPONDING FIELDS OF TABLE TD_MBEW
FROM MBEW INNER JOIN MARA
ON MBEW~MATNR = MARA~MATNR
WHERE MBEW~BWKEY = P_WERKS
AND ( MBEW~BKLAS = C_2100
OR MBEW~BKLAS = C_2110 )
AND MBEW~MATNR IN S_MATNR.
LOOP AT TD_MBEW INTO LTH_MBEW.
LW_INDEX = SY-TABIX.
IF LTH_MBEW-LFGJA > P_GJAHR
OR ( LTH_MBEW-LFGJA = P_GJAHR
AND LTH_MBEW-LFMON > P_PERID ).
SELECT MBEWH~MATNR "Material Number
MBEWH~BWKEY "Valuation Area
MBEWH~BWTAR "Valuation Type
MBEWH~BKLAS "Valuation Class
MBEWH~LFGJA "Fiscal Year of Current Period
MBEWH~LFMON "Current period
MBEWH~LBKUM "Total Valuated Stock
MBEWH~SALK3 "Value of Total Valuated Stock
MBEWH~VPRSV "Price Control Indicator
MBEWH~VERPR "Moving Average Price/Periodic Unit Price
MBEWH~STPRS "Standard price
MBEWH~PEINH "Price Unit
MARA~MTART
MARA~MEINS
UP TO 1 ROWS
INTO CORRESPONDING FIELDS OF TABLE LTD_MBEWH
FROM MBEWH INNER JOIN MARA
ON MBEWH~MATNR = MARA~MATNR
WHERE MBEWH~MATNR = LTH_MBEW-MATNR
AND MBEWH~BWKEY = LTH_MBEW-BWKEY
AND MBEWH~BWTAR = LTH_MBEW-BWTAR
AND MBEWH~BKLAS = LTH_MBEW-BKLAS
AND ( MBEWH~LFGJA < P_GJAHR
OR ( MBEWH~LFGJA = P_GJAHR
AND MBEWH~LFMON <= P_PERID ) )
ORDER BY MBEWH~LFGJA DESCENDING
MBEWH~LFMON DESCENDING.
IF SY-SUBRC = 0.
READ TABLE LTD_MBEWH INTO LTH_MBEWH INDEX 1.
IF SY-SUBRC = 0.
MODIFY TD_MBEW FROM LTH_MBEWH INDEX LW_INDEX.
ENDIF.
REFRESH LTD_MBEWH.
CLEAR LTH_MBEWH.
ENDIF.
ENDIF.
CLEAR LTH_MBEW.
ENDLOOP.
ENDFORM. " FRM_GET_NORMAL_STOCK
*&---------------------------------------------------------------------*
*& Form FRM_GET_MCHB_STOCK
*&---------------------------------------------------------------------*
* Get normal batch stock
*----------------------------------------------------------------------*
FORM FRM_GET_MCHB_STOCK .
DATA:
LTD_MCHBH TYPE TABLE OF TYP_MCHB,
LTH_MCHB LIKE LINE OF TD_MCHB,
LTH_MCHBH LIKE LINE OF LTD_MCHBH.
DATA:
LW_INDEX TYPE SY-TABIX.
* Get normal batch stock
SELECT MATNR "Material
WERKS "Plant
LGORT "Strage Location
CHARG "Batch Number
LFGJA "Fiscal year
LFMON "Period
CLABS "Valuated Unrestricted-Use Stock
CUMLM "Stock in transfer (from one storage location to another)
CINSM "Stock in Quality Inspection
CEINM "Total Stock of All Restricted Batches
CSPEM "Blocked Stock
CRETM "Blocked Stock Returns
INTO CORRESPONDING FIELDS OF TABLE TD_MCHB
FROM MCHB
FOR ALL ENTRIES IN TD_MBEW
WHERE MATNR = TD_MBEW-MATNR
AND WERKS = P_WERKS.
LOOP AT TD_MCHB INTO LTH_MCHB.
LW_INDEX = SY-TABIX.
IF LTH_MCHB-LFGJA > P_GJAHR
OR ( LTH_MCHB-LFGJA = P_GJAHR
AND LTH_MCHB-LFMON > P_PERID ).
SELECT MATNR "Material
WERKS "Plant
LGORT "Strage Location
CHARG "Batch Number
LFGJA "Fiscal year
LFMON "Period
CLABS " Valuated Unrestricted-Use Stock
CUMLM " Stock in transfer (from one storage location to another)
CINSM " Stock in Quality Inspection
CEINM " Total Stock of All Restricted Batches
CSPEM " Blocked Stock
CRETM " Blocked Stock Returns
INTO TABLE LTD_MCHBH
FROM MCHBH
UP TO 1 ROWS
WHERE MATNR = LTH_MCHB-MATNR
AND WERKS = P_WERKS
AND CHARG = LTH_MCHB-CHARG
AND LGORT = LTH_MCHB-LGORT
AND ( LFGJA < P_GJAHR
OR ( LFGJA = P_GJAHR
AND LFMON <= P_PERID ) )
ORDER BY LFGJA DESCENDING
LFMON DESCENDING.
IF SY-SUBRC = 0.
READ TABLE LTD_MCHBH INTO LTH_MCHBH INDEX 1.
IF SY-SUBRC = 0.
* Update Qty by history data
* LTH_MCHBH-CLABS = LTH_MCHBH-CLABS +
* LTH_MCHBH-CUMLM +
* LTH_MCHBH-CINSM +
* LTH_MCHBH-CEINM +
* LTH_MCHBH-CSPEM +
* LTH_MCHBH-CRETM.
MODIFY TD_MCHB FROM LTH_MCHBH INDEX LW_INDEX.
ENDIF.
* ELSE.
** Update Qty by currence data
* LTH_MCHB-CLABS = LTH_MCHB-CLABS +
* LTH_MCHB-CUMLM +
* LTH_MCHB-CINSM +
* LTH_MCHB-CEINM +
* LTH_MCHB-CSPEM +
* LTH_MCHB-CRETM.
*
* MODIFY TD_MCHB FROM LTH_MCHB INDEX LW_INDEX.
ENDIF.
ENDIF.
REFRESH LTD_MCHBH.
CLEAR LTH_MCHBH.
CLEAR LTH_MCHB.
ENDLOOP.
ENDFORM. " FRM_GET_MCHB_STOCK
*&---------------------------------------------------------------------*
*& Form FRM_GET_NORMAL_STOCK
*&---------------------------------------------------------------------*
* Extract Special Stocks with Customer stock
*----------------------------------------------------------------------*
FORM FRM_GET_CUST_STOCK.
DATA:
LTD_MSKUH TYPE TABLE OF TYP_MSKU,
LTH_MSKU LIKE LINE OF TD_MSKU,
LTH_MSKUH LIKE LINE OF LTD_MSKUH.
DATA:
LW_INDEX TYPE SY-TABIX.
* Extract Current stock(Batch Stocks).
SELECT MATNR " Material Number
WERKS " Plant
CHARG " Batch Number
LFGJA " Fiscal Year of Current Period
LFMON " Current period (posting period)
KULAB " Valuated Unrestricted-Use Stock
KUINS " Stock in Quality Inspection
KUEIN " Total Stock of All Restricted Batches
KUUML " Stock in Transfer for Customer Consignment (Plant to Plant)
INTO CORRESPONDING FIELDS OF TABLE TD_MSKU
FROM MSKU
FOR ALL ENTRIES IN TD_MBEW
WHERE WERKS = P_WERKS " Plant
AND MATNR = TD_MBEW-MATNR. " Material Number
LOOP AT TD_MSKU INTO LTH_MSKU.
LW_INDEX = SY-TABIX.
IF LTH_MSKU-LFGJA > P_GJAHR
OR ( LTH_MSKU-LFGJA = P_GJAHR
AND LTH_MSKU-LFMON > P_PERID ).
* Extract Current stock(Batch Stocks) history.
SELECT MATNR "Material Number
WERKS "Plant
CHARG "Batch Number
LFGJA "Fiscal Year of Current Period
LFMON "Current period (posting period)
KULAB "Valuated Unrestricted-Use Stock
KUINS "Stock in Quality Inspection
KUEIN "Total Stock of All Restricted Batches
KUUML "Stock in Transfer for Customer Consignment (Plant to Plant)
INTO CORRESPONDING FIELDS OF TABLE LTD_MSKUH
UP TO 1 ROWS
FROM MSKUH
WHERE WERKS = P_WERKS "Plant
AND MATNR = LTH_MSKU-MATNR "Material Number
AND CHARG = LTH_MSKU-CHARG
AND ( LFGJA < P_GJAHR
OR ( LFGJA = P_GJAHR
AND LFMON <= P_PERID ) )
ORDER BY LFGJA DESCENDING
LFMON DESCENDING.
IF SY-SUBRC = 0.
READ TABLE LTD_MSKUH INTO LTH_MSKUH INDEX 1.
IF SY-SUBRC = 0.
* Update Qty by history data
* LTH_MSKUH-KULAB = LTH_MSKUH-KULAB +
* LTH_MSKUH-KUINS +
* LTH_MSKUH-KUEIN +
* LTH_MSKUH-KUUML.
MODIFY TD_MSKU FROM LTH_MSKUH INDEX LW_INDEX.
ENDIF.
* ELSE.
** Update Qty by currence data
* LTH_MSKU-KULAB = LTH_MSKU-KULAB +
* LTH_MSKU-KUINS +
* LTH_MSKU-KUEIN +
* LTH_MSKU-KUUML.
*
* MODIFY TD_MSKU FROM LTH_MSKU INDEX LW_INDEX.
ENDIF.
ENDIF.
REFRESH LTD_MSKUH.
CLEAR LTH_MSKUH.
CLEAR LTH_MSKU.
ENDLOOP.
ENDFORM. "FRM_GET_CUST_STOCK
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8356764/viewspace-1059577/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Stock overview and cost assignment - 1View
- Stock overview and cost assignment - 2View
- Stock overview and cost assignment - 3View
- Stock overview and cost assignment - 5View
- Stock overview and cost assignment - 6View
- SAP S/4 HANA OverviewView
- SAP WebClient UI overview頁面裡assignment block的可見性分析技巧WebclientUIViewBloC
- 4-Overview-Kubernetes APIViewAPI
- SAP MM Stock Tables and Stock Types
- stock Types
- Forget stock
- Algorithm assignment 1Go
- Credit block & Stock resevedBloC
- Flutter OverviewFlutterView
- Assignment Problem的若干思考
- cost量化分析
- 表連線cost
- bandit-switch cost
- dart class overviewDartView
- Stormstarter-OverviewORMView
- Overview of PartitioningView
- Overview of Database CheckpointsViewDatabase
- Overview of Unix ResourcesView
- oracle function overviewOracleFunctionView
- Item Import OverviewImportView
- Overview of Extents(11)View
- Overview of Partitioned IndexesViewIndex
- Overview of Tablespaces (38)View
- Overview of Views (174)View
- Overview of Datafiles (62)View
- Overview of Segments (22)View
- 高通USB overviewView
- MM Stock基礎知識
- [譯] Javascript開銷(Cost)JavaScript
- PostgreSQL Cost Based Vacuum探秘SQL
- OPTIMIZER_IDEX_COSTIDE
- Cost objects in SAP R/3Object
- oracle cost計算方式Oracle