Stock overview and cost assignment - 1
* Get Cost of Goods Sold data
* Get the Material data
* Get WIP data
* Get Inventory data[@more@]
************************************************************************
* PROGRAM : 123456789
* CREATED BY : Ray
* DESCRIPTION : 1. Currently in C1 Department manage the sales,
* cost and Inventory by Production Line Type level
* which went through production line
* 2. Display Monthly total or balance Quantity and Amount
************************************************************************
************************************************************************
REPORT 111222333.
*----------------------------------------------------------------------*
* Tables
*----------------------------------------------------------------------*
TABLES: MARC,
/add/CT000401.
*----------------------------------------------------------------------*
* CONSTANTS
*----------------------------------------------------------------------*
CONSTANTS:
C_BU TYPE SCREEN-NAME VALUE 'P_BU',
C_CBU TYPE SCREEN-NAME VALUE 'P_CBU',
C_SBU TYPE SCREEN-NAME VALUE 'P_SBU',
C_PC TYPE SCREEN-NAME VALUE 'P_PC',
C_X TYPE CHAR1 VALUE 'X',
C_ZFRT TYPE MARA-MTART VALUE 'ZFRT',
C_2100 TYPE MBEW-BKLAS VALUE '2100',
C_2110 TYPE MBEW-BKLAS VALUE '2110',
C_BSX TYPE T030-KTOSL VALUE 'BSX',
C_A010 TYPE T030-KTOPL VALUE 'A010',
C_S TYPE MBEW-VPRSV VALUE 'S',
C_0000T TYPE CHAR6 VALUE '0000T_'.
CONSTANTS:
C_NORMAL_STOCK TYPE SOBKZ VALUE '1', "Normal Stock
C_SO_STOCK TYPE SOBKZ VALUE '2', "Sales Order Stock Valuation(EBEW/EBEWH)
C_CNCS_STOCK TYPE SOBKZ VALUE '3'. "Valuated Stock with Subcontractor(OBEW/OBEWH)
*----------------------------------------------------------------------*
* Types
*----------------------------------------------------------------------*
TYPES:
BEGIN OF TYP_MBEW,
MATNR LIKE MBEW-MATNR, "Material Number
BWKEY LIKE MBEW-BWKEY, "Valuation Area
BKLAS LIKE MBEW-BKLAS,
BWTAR LIKE MBEW-BWTAR,
LFGJA LIKE MBEW-LFGJA,
LFMON LIKE MBEW-LFMON,
LBKUM LIKE MBEW-LBKUM,
SALK3 LIKE MBEW-SALK3, "Value of Total Valuated Stock
VPRSV LIKE MBEW-VPRSV,
VERPR LIKE MBEW-VERPR,
STPRS LIKE MBEW-STPRS,
PEINH LIKE MBEW-PEINH,
MTART LIKE MARA-MTART,
MEINS LIKE MARA-MEINS,
END OF TYP_MBEW,
* Material Valuation
BEGIN OF TYP_EBEW,
MATNR LIKE EBEW-MATNR, " Material Number
BWKEY LIKE EBEW-BWKEY, " Valuation Area
BKLAS LIKE EBEW-BKLAS, " Valuation Class
VBELN LIKE EBEW-VBELN, " Sales and Distribution Document Number
POSNR LIKE EBEW-POSNR, " Item number of the SD document
LFGJA LIKE EBEW-LFGJA, " Fiscal Year of Current Period
LFMON LIKE EBEW-LFMON, " Current period (posting period)
LBKUM LIKE EBEW-LBKUM, " Total Valuated Stock
SALK3 LIKE EBEW-SALK3, " Value of Total Valuated Stock
VERPR LIKE EBEW-VERPR, " Moving Average Price/Periodic Unit Price
STPRS LIKE EBEW-STPRS, " Standard price
PEINH LIKE EBEW-PEINH, " Price Unit
VPRSV LIKE EBEW-VPRSV, " Price Control Indicator
END OF TYP_EBEW,
BEGIN OF TYP_OBEW,
MATNR LIKE OBEW-MATNR, " Material Number
BWKEY LIKE OBEW-BWKEY, " Valuation Area
BKLAS LIKE OBEW-BKLAS, " Valuation Class
LIFNR LIKE OBEW-LIFNR, " Account Number of Vendor or Creditor
LFGJA LIKE OBEW-LFGJA, " Fiscal Year of Current Period
LFMON LIKE OBEW-LFMON, " Current period (posting period)
LBKUM LIKE OBEW-LBKUM, " Total Valuated Stock
SALK3 LIKE OBEW-SALK3, " Value of Total Valuated Stock
VERPR LIKE OBEW-VERPR, " Moving Average Price/Periodic Unit Price
STPRS LIKE OBEW-STPRS, " Standard price
PEINH LIKE OBEW-PEINH, " Price Unit
VPRSV LIKE OBEW-VPRSV, " Price Control Indicator
END OF TYP_OBEW,
BEGIN OF TYP_MCHB,
MATNR LIKE MCHBH-MATNR,
WERKS LIKE MCHBH-WERKS,
LGORT LIKE MCHBH-LGORT,
CHARG LIKE MCHBH-CHARG,
LFGJA LIKE MCHBH-LFGJA, " Fiscal year
LFMON LIKE MCHBH-LFMON, " Period
CLABS LIKE MCHBH-CLABS, " Valuated Unrestricted-Use Stock
CUMLM LIKE MCHBH-CUMLM, " Stock in transfer (from one storage location to another)
CINSM LIKE MCHBH-CINSM, " Stock in Quality Inspection
CEINM LIKE MCHBH-CEINM, " Total Stock of All Restricted Batches
CSPEM LIKE MCHBH-CSPEM, " Blocked Stock
CRETM LIKE MCHBH-CRETM, " Blocked Stock Returns
END OF TYP_MCHB,
BEGIN OF TYP_MSKU,
MATNR LIKE MSKU-MATNR, " Material Number
WERKS LIKE MSKU-WERKS, " Plant
CHARG LIKE MSKU-CHARG, " Batch Number
LFGJA LIKE MSKU-LFGJA, " Fiscal Year of Current Period
LFMON LIKE MSKU-LFMON, " Current period (posting period)
KULAB LIKE MSKU-KULAB, " Valuated Unrestricted-Use Stock
KUINS LIKE MSKU-KUINS, " Stock in Quality Inspection
KUEIN LIKE MSKU-KUEIN, " Total Stock of All Restricted Batches
KUUML LIKE MSKU-KUUML, " Stock in Transfer for Customer Consignment (Plant to Plant)
END OF TYP_MSKU,
BEGIN OF TYP_MSKA,
MATNR LIKE MSKA-MATNR, " Material Number
WERKS LIKE MSKA-WERKS, " Plant
LGORT LIKE MSKA-LGORT, " Storage Location
CHARG LIKE MSKA-CHARG, " Batch Number
VBELN LIKE MSKA-VBELN, " Sales and Distribution Document Number
POSNR LIKE MSKA-POSNR, " Item number of the SD document
LFGJA LIKE MSKA-LFGJA, " Fiscal Year of Current Period
LFMON LIKE MSKA-LFMON, " Current period (posting period)
KALAB LIKE MSKA-KALAB, " Valuated Unrestricted-Use Stock
KAINS LIKE MSKA-KAINS, " Stock in Quality Inspection
KASPE LIKE MSKA-KASPE, " Blocked Stock
END OF TYP_MSKA,
BEGIN OF TYP_MSLB,
MATNR LIKE MSLB-MATNR, " Material Number
WERKS LIKE MSLB-WERKS, " Plant
CHARG LIKE MSLB-CHARG, " Batch Number
LIFNR LIKE MSLB-LIFNR, " Account Number of Vendor or Creditor
LFGJA LIKE MSLB-LFGJA, " Fiscal Year of Current Period
LFMON LIKE MSLB-LFMON, " Current period (posting period)
LBLAB LIKE MSLB-LBLAB, " Valuated Unrestricted-Use Stock
LBINS LIKE MSLB-LBINS, " Stock in Quality Inspection
LBEIN LIKE MSLB-LBEIN, " Total Stock of All Restricted Batches
LBUML LIKE MSLB-LBUML, " Stock in Transfer for Subcontracting (Plant to Plant)
END OF TYP_MSLB.
*----------------------------------------------------------------------*
* DATA
*----------------------------------------------------------------------*
DATA:
W_MATNR TYPE MARA-MATNR,
W_GJAHR TYPE BKPF-GJAHR,
W_PERID TYPE BKPF-MONAT,
W_BUTXT TYPE T001-BUTXT,
W_PARA TYPE SETNAMENEW.
DATA:
W_SACCOUNT LIKE T030-KONTS,
W_FACCOUNT LIKE T030-KONTS.
DATA:
RD_BWART TYPE RANGE OF MSEG-BWART,
RH_BWART LIKE LINE OF RD_BWART,
RD_ACCOUNT TYPE RANGE OF BSIS-HKONT,
RH_ACCOUNT LIKE LINE OF RD_ACCOUNT.
DATA:
BEGIN OF TH_SETLEAF,
VALFROM TYPE SETLEAF-VALFROM,
END OF TH_SETLEAF.
DATA:
TD_SETLEAF LIKE TABLE OF TH_SETLEAF.
DATA:
TD_MBEW TYPE TABLE OF TYP_MBEW,
TD_EBEW TYPE TABLE OF TYP_EBEW,
TD_OBEW TYPE TABLE OF TYP_OBEW,
TD_MCHB TYPE TABLE OF TYP_MCHB,
TD_MSKU TYPE TABLE OF TYP_MSKU,
TD_MSKA TYPE TABLE OF TYP_MSKA,
TD_MSLB TYPE TABLE OF TYP_MSLB,
TD_MATNR TYPE /add/SC0003,
TH_MATNR LIKE LINE OF TD_MATNR,
TD_TEMP401 TYPE TABLE OF /add/CT000401,
TD_CT000401 TYPE TABLE OF /add/CT000401.
*----------------------------------------------------------------------*
* PARAMETERS
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BLK0 WITH FRAME TITLE TEXT-000.
SELECTION-SCREEN BEGIN OF LINE .
SELECTION-SCREEN COMMENT 1(16) TEXT-005 FOR FIELD P_BUKRS.
PARAMETERS P_BUKRS TYPE T001-BUKRS OBLIGATORY.
SELECTION-SCREEN END OF LINE .
SELECTION-SCREEN BEGIN OF LINE .
SELECTION-SCREEN COMMENT 1(16) TEXT-009 FOR FIELD P_WERKS.
PARAMETERS P_WERKS TYPE T001W-WERKS OBLIGATORY.
SELECTION-SCREEN END OF LINE .
SELECTION-SCREEN BEGIN OF LINE .
SELECTION-SCREEN COMMENT 1(16) TEXT-006 FOR FIELD P_GJAHR.
PARAMETERS P_GJAHR TYPE BSEG-GJAHR OBLIGATORY.
SELECTION-SCREEN END OF LINE .
SELECTION-SCREEN BEGIN OF LINE .
SELECTION-SCREEN COMMENT 1(16) TEXT-007 FOR FIELD P_PERID.
PARAMETERS P_PERID TYPE BKPF-MONAT OBLIGATORY.
SELECTION-SCREEN END OF LINE .
SELECTION-SCREEN BEGIN OF LINE .
SELECTION-SCREEN COMMENT 1(13) TEXT-008 FOR FIELD S_MATNR.
SELECT-OPTIONS S_MATNR FOR W_MATNR.
SELECTION-SCREEN END OF LINE .
SELECTION-SCREEN SKIP.
* Material Conditons
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-012.
SELECTION-SCREEN BEGIN OF LINE .
PARAMETERS: RB_ALL RADIOBUTTON GROUP GRP1 DEFAULT 'X' USER-COMMAND RAD1.
SELECTION-SCREEN COMMENT 4(5) TEXT-014 FOR FIELD RB_ALL.
SELECTION-SCREEN END OF LINE .
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: RB_GS RADIOBUTTON GROUP GRP1 .
SELECTION-SCREEN COMMENT 4(12) TEXT-015 FOR FIELD RB_GS.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: RB_CGS RADIOBUTTON GROUP GRP1 .
SELECTION-SCREEN COMMENT 4(20) TEXT-016 FOR FIELD RB_CGS.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: RB_RMC RADIOBUTTON GROUP GRP1 .
SELECTION-SCREEN COMMENT 4(22) TEXT-017 FOR FIELD RB_RMC.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: RB_IVT RADIOBUTTON GROUP GRP1 .
SELECTION-SCREEN COMMENT 4(10) TEXT-018 FOR FIELD RB_IVT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: RB_WIP RADIOBUTTON GROUP GRP1 .
SELECTION-SCREEN COMMENT 4(5) TEXT-019 FOR FIELD RB_WIP.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK BLK1.
PARAMETERS CB_DEL AS CHECKBOX DEFAULT ''.
SELECTION-SCREEN END OF BLOCK BLK0.
*----------------------------------------------------------------------*
* INITIALIZATION
*----------------------------------------------------------------------*
INITIALIZATION.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
* Check Input Parameter
PERFORM CHECK_PARAMETER.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
* Company Code authorization check
AUTHORITY-CHECK OBJECT 'F_BKPF_BUK' ID 'BUKRS' FIELD P_BUKRS
ID 'ACTVT' FIELD ''.
IF SY-SUBRC <> 0.
MESSAGE S006 DISPLAY LIKE 'E'.
CALL SELECTION-SCREEN 1000.
SET CURSOR FIELD 'P_BUKRS'.
STOP.
ENDIF.
CASE C_X.
WHEN RB_ALL.
* Get the mian data
PERFORM GET_PRODUCTION_DATA.
WHEN RB_GS.
* Get Gross Sales data
PERFORM GET_GROSS_SALES_DATA.
WHEN RB_CGS.
* Get Cost of Goods Sold data
PERFORM GET_GOODS_SOLD_DATA.
WHEN RB_RMC.
* Get the Material data
PERFORM GET_MATERIAL_DATA.
WHEN RB_WIP.
* Get WIP data
PERFORM GET_WIP_DATA.
WHEN RB_IVT.
* Get Inventory data
PERFORM GET_INVENTORY_DATA.
ENDCASE.
* Update table
PERFORM UPDATE_TABLE.
*----------------------------------------------------------------------*
* END-OF-SELECTION
*----------------------------------------------------------------------*
END-OF-SELECTION.
*----------------------------------------------------------------------*
* FORM
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form CHECK_PARAMETER
*&---------------------------------------------------------------------*
* Check Input Parameter
*----------------------------------------------------------------------*
FORM CHECK_PARAMETER .
DATA:
LW_POPER TYPE T009B-POPER,
LW_PERIV TYPE T001-PERIV,
LW_DATE TYPE SY-DATUM.
* Company Code existence check
SELECT SINGLE BUTXT
PERIV
INTO (W_BUTXT, LW_PERIV)
FROM T001
WHERE BUKRS = P_BUKRS.
IF SY-SUBRC <> 0.
MESSAGE E005.
ENDIF.
LW_POPER = P_PERID.
* Fiscal Year Period check
CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
EXPORTING
I_GJAHR = P_GJAHR
I_MONMIT = '00'
I_PERIV = LW_PERIV
I_POPER = LW_POPER
IMPORTING
E_DATE = LW_DATE
EXCEPTIONS
INPUT_FALSE = 1
T009_NOTFOUND = 2
T009B_NOTFOUND = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
SET CURSOR FIELD 'P_PERID'.
MESSAGE E082.
ENDIF.
ENDFORM. " CHECK_PARAMETER
*&---------------------------------------------------------------------*
*& Form GET_PRODUCTION_DATA
*&---------------------------------------------------------------------*
* Get the mian data
*----------------------------------------------------------------------*
FORM GET_PRODUCTION_DATA .
* Get Gross Sales data
PERFORM GET_GROSS_SALES_DATA.
* Get Cost of Goods Sold data
PERFORM GET_GOODS_SOLD_DATA.
* Get the Material data
PERFORM GET_MATERIAL_DATA.
* Get WIP data
PERFORM GET_WIP_DATA.
* Get Inventory data
PERFORM GET_INVENTORY_DATA.
ENDFORM. " GET_PRODUCTION_DATA
*&---------------------------------------------------------------------*
*& Form GET_GROSS_SALES_DATA
*&---------------------------------------------------------------------*
* Get Gross Sales data
*----------------------------------------------------------------------*
FORM GET_GROSS_SALES_DATA .
DATA:
BEGIN OF LTH_BSIS,
BELNR TYPE BSIS-BELNR, "Accounting document number
BUZEI TYPE BSIS-BUZEI, "Number of Line Item
HKONT TYPE BSIS-HKONT, "Account number
SHKZG TYPE BSIS-SHKZG, "Debit/Credit Indicator
DMBTR TYPE BSIS-DMBTR, "Amount in Local currency
WRBTR TYPE BSIS-WRBTR, "Amount in Document currency: added by zhang mei
AUFNR TYPE BSIS-AUFNR, "Order No.
MONAT TYPE BSIS-MONAT, "Perid
XBLNR TYPE BSIS-XBLNR, "Reference Document Number
AWKEY TYPE BKPF-AWKEY, "Reference Key
PRCTR TYPE BSIS-PRCTR, "Profit center added by zhang Mei
END OF LTH_BSIS,
BEGIN OF LTH_VBRP,
WERKS TYPE VBRP-WERKS, "Plant
LGORT TYPE VBRP-LGORT, "Strage Location
MATNR TYPE VBRP-MATNR, "Material
VGBEL TYPE VBRP-VGBEL, "Document number of the reference document
LMENG TYPE VBRP-LMENG, "Required quantity for material
FKIMG TYPE VBRP-FKIMG, "Required quantity for material added by zhang mei on 2011.10.24
NETWR TYPE VBRP-NETWR, "NET amount under document currency
MEINS TYPE VBRP-MEINS, "BASE UOM
END OF LTH_VBRP,
BEGIN OF LTH_CHARG,
CHARG TYPE LIPS-CHARG, "Batch
LFIMG TYPE LIPS-LFIMG, "QUANTITY
END OF LTH_CHARG.
DATA:
LW_ZEILE LIKE MSEG-ZEILE,
LW_LINES TYPE SY-TABIX,
LTD_BSIS LIKE TABLE OF LTH_BSIS,
LTD_VBRP LIKE TABLE OF LTH_VBRP,
LTD_CHARG LIKE TABLE OF LTH_CHARG,
LW_AMOUNT LIKE /add/CT000401-AMOUNT,
LW_AMTTEMP LIKE /add/CT000401-AMOUNT,
LW_QUANT LIKE /add/CT000401-QUANT,
LTH_CT000401 LIKE LINE OF TD_CT000401.
CLEAR RH_ACCOUNT.
REFRESH RD_ACCOUNT.
* Get the Account
SELECT VALFROM
FROM SETLEAF
INTO TABLE TD_SETLEAF
WHERE SETCLASS = '0000'
AND SETNAME = 'AG01_1'.
LOOP AT TD_SETLEAF INTO TH_SETLEAF.
RH_ACCOUNT-SIGN = 'I'.
RH_ACCOUNT-OPTION = 'EQ'.
RH_ACCOUNT-LOW = TH_SETLEAF-VALFROM.
APPEND RH_ACCOUNT TO RD_ACCOUNT.
CLEAR:
TH_SETLEAF,
RH_ACCOUNT.
ENDLOOP.
* Get Gross Sales data
SELECT BSIS~BELNR "Accounting document number
BSIS~BUZEI "Number of Line Item
BSIS~HKONT "Accounting number
BSIS~SHKZG "Debit/Credit Indicator
BSIS~DMBTR "Amount in Local currency
BSIS~WRBTR "Amount in Docuement currency
BSIS~AUFNR "Order No.
BSIS~MONAT "Perid
BSIS~XBLNR "Reference Document Number
BKPF~AWKEY "Reference Key
BSIS~PRCTR "Profit Center
FROM BSIS INNER JOIN BKPF
ON BSIS~BUKRS = BKPF~BUKRS
AND BSIS~BELNR = BKPF~BELNR
AND BSIS~GJAHR = BKPF~GJAHR
INTO TABLE LTD_BSIS
WHERE BSIS~BUKRS = P_BUKRS
AND BSIS~WERKS = P_WERKS
AND BSIS~GJAHR = P_GJAHR
AND BSIS~MONAT = P_PERID
AND BKPF~STBLG = SPACE
AND BSIS~HKONT IN RD_ACCOUNT.
IF SY-SUBRC = 0.
SORT LTD_BSIS BY AWKEY ASCENDING.
LOOP AT LTD_BSIS INTO LTH_BSIS.
AT NEW AWKEY.
SELECT WERKS "Plant
LGORT "Strage Location
MATNR "Material
VGBEL "Document number of the reference document
LMENG "Required quantity for material
FKIMG "Billed quantity for material changed by zhang mei on 2011.10.24
NETWR "NET Value in document currency
MEINS "BASE UOM
FROM VBRP
INTO CORRESPONDING FIELDS OF TABLE LTD_VBRP
WHERE VBELN = LTH_BSIS-AWKEY
AND MATNR IN S_MATNR.
IF SY-SUBRC = 0.
SELECT CHARG
LFIMG
FROM LIPS
INTO TABLE LTD_CHARG
FOR ALL ENTRIES IN LTD_VBRP
WHERE VBELN = LTD_VBRP-VGBEL
AND CHARG <> SPACE.
ENDIF.
ENDAT.
LOOP AT LTD_VBRP INTO LTH_VBRP WHERE NETWR = LTH_BSIS-WRBTR.
IF LTH_BSIS-SHKZG = 'H'.
LTH_CT000401-AMOUNT = LTH_BSIS-DMBTR * -1. "Amount
LTH_CT000401-QUANT = LTH_VBRP-FKIMG * -1. "Quantity
ELSE.
LTH_CT000401-AMOUNT = LTH_BSIS-DMBTR. "Amount
LTH_CT000401-QUANT = LTH_VBRP-FKIMG. "Quantity
ENDIF.
LTH_CT000401-MATNR = LTH_VBRP-MATNR. "Material number
LTH_CT000401-WERKS = LTH_VBRP-WERKS. "Plant
LTH_CT000401-LGORT = LTH_VBRP-LGORT. "Storage location
LTH_CT000401-MEINS = LTH_VBRP-MEINS. "Base UOM
DELETE LTD_VBRP INDEX SY-TABIX.
EXIT.
ENDLOOP.
IF SY-SUBRC <> 0.
CONTINUE.
ENDIF.
LTH_CT000401-BUKRS = P_BUKRS. "Company Code
LTH_CT000401-GJAHR = P_GJAHR. "Fiscal Year
LTH_CT000401-MONAT = LTH_BSIS-MONAT. "Perid
LTH_CT000401-BELNR = LTH_BSIS-BELNR. "Account document
LTH_CT000401-BUZEI = LTH_BSIS-BUZEI. "Number of Line Item
LTH_CT000401-HKONT = LTH_BSIS-HKONT. "Account Number
LTH_CT000401-AUFNR = LTH_BSIS-AUFNR. "Order NO.
LTH_CT000401-PRCTR = LTH_BSIS-PRCTR. "Profit center: added by zhang Mei
* Get Valuation Class
SELECT SINGLE BKLAS
FROM MBEW
INTO LTH_CT000401-BKLAS
WHERE BWKEY = P_WERKS
AND MATNR = LTH_CT000401-MATNR. "Material number
IF SY-SUBRC <> 0.
SELECT SINGLE BKLAS
FROM MBEWH
INTO LTH_CT000401-BKLAS
WHERE BWKEY = P_WERKS
AND LFGJA = P_GJAHR
AND LFMON = P_PERID
AND MATNR = LTH_CT000401-MATNR. "Material number
ENDIF.
* Get the routing data
PERFORM GET_ROUTING_DATA USING LTH_BSIS-AUFNR
LTH_CT000401-WERKS
LTH_CT000401-LGORT
LTH_CT000401-MATNR
LTH_CT000401-CHARG
CHANGING LTH_CT000401-RTGRP1
LTH_CT000401-RTGRP2
LTH_CT000401-RTGRP3
LTH_CT000401-RTGRP4
LTH_CT000401-RTGRP5
LTH_CT000401-RTGRP6
LTH_CT000401-RTGRP7
LTH_CT000401-RTGRP8.
* Get batch
IF LTD_CHARG IS NOT INITIAL.
SORT LTD_CHARG BY CHARG ASCENDING.
DESCRIBE TABLE LTD_CHARG LINES LW_LINES.
LW_AMOUNT = LTH_CT000401-AMOUNT.
LW_QUANT = LTH_CT000401-QUANT.
LOOP AT LTD_CHARG INTO LTH_CHARG.
LTH_CT000401-CHARG = LTH_CHARG-CHARG. "Barch.
* Get the routing data
PERFORM GET_ROUTING_DATA USING LTH_BSIS-AUFNR
LTH_CT000401-WERKS
LTH_CT000401-LGORT
LTH_CT000401-MATNR
LTH_CT000401-CHARG
CHANGING LTH_CT000401-RTGRP1
LTH_CT000401-RTGRP2
LTH_CT000401-RTGRP3
LTH_CT000401-RTGRP4
LTH_CT000401-RTGRP5
LTH_CT000401-RTGRP6
LTH_CT000401-RTGRP7
LTH_CT000401-RTGRP8.
IF SY-TABIX <> LW_LINES.
IF LTH_CT000401-AMOUNT < 0.
LTH_CT000401-AMOUNT = LW_AMOUNT * LTH_CHARG-LFIMG / LW_QUANT * -1. "Amount
LTH_CT000401-QUANT = LTH_CHARG-LFIMG * -1. "Quantity
ELSE.
LTH_CT000401-AMOUNT = LW_AMOUNT * LTH_CHARG-LFIMG / LW_QUANT . "Amount
LTH_CT000401-QUANT = LTH_CHARG-LFIMG. "Quantity
ENDIF.
LW_AMTTEMP = LW_AMTTEMP + LTH_CT000401-AMOUNT.
ELSE.
IF LTH_CT000401-AMOUNT < 0.
LTH_CT000401-AMOUNT = LW_AMOUNT - LW_AMTTEMP. "Amount
LTH_CT000401-QUANT = LTH_CHARG-LFIMG * -1. "Quantity
ELSE.
LTH_CT000401-AMOUNT = LW_AMOUNT - LW_AMTTEMP . "Amount
LTH_CT000401-QUANT = LTH_CHARG-LFIMG. "Quantity
ENDIF.
ENDIF.
APPEND LTH_CT000401 TO TD_CT000401.
CLEAR LTH_CHARG.
ENDLOOP.
ELSE.
APPEND LTH_CT000401 TO TD_CT000401.
ENDIF.
TH_MATNR-MATNR = LTH_CT000401-MATNR.
APPEND TH_MATNR TO TD_MATNR.
CLEAR: TH_MATNR, LW_ZEILE, LTH_CHARG, LW_LINES.
CLEAR: LTH_CT000401, LTH_VBRP, LTH_CHARG, LW_QUANT, LW_AMOUNT, LW_AMTTEMP.
ENDLOOP.
* Delete the old data
IF CB_DEL IS NOT INITIAL.
SELECT SINGLE * FROM /add/CT000401
WHERE BUKRS = P_BUKRS
AND GJAHR = P_GJAHR
AND MONAT = P_PERID
AND HKONT IN RD_ACCOUNT
AND MATNR IN S_MATNR
AND WERKS = P_WERKS.
IF SY-SUBRC = 0.
DELETE FROM /add/CT000401
WHERE BUKRS = P_BUKRS
AND GJAHR = P_GJAHR
AND MONAT = P_PERID
AND HKONT IN RD_ACCOUNT
AND MATNR IN S_MATNR
AND WERKS = P_WERKS.
IF SY-SUBRC <> 0.
MESSAGE E027
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " GET_GROSS_SALES_DATA
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8356764/viewspace-1059574/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Stock overview and cost assignment - 2View
- Stock overview and cost assignment - 3View
- Stock overview and cost assignment - 4View
- Stock overview and cost assignment - 5View
- Stock overview and cost assignment - 6View
- Algorithm assignment 1Go
- SAP WebClient UI overview頁面裡assignment block的可見性分析技巧WebclientUIViewBloC
- SAP MM Stock Tables and Stock Types
- Oracle Memory Structure 1. Overview And ManagementOracleStructView
- Presentation Skills 1: The Overview and the Agenda C1-Upper-IntermediateView
- 1-Overview-(概述 What is Kubernetes)View
- stock Types
- Forget stock
- The Overview of ECMA C# Language Specialisation (1) (轉)ViewC#
- iOS動畫程式設計-Layer動畫[ 1 ] Layer Animations OverviewiOS動畫程式設計View
- Credit block & Stock resevedBloC
- Flutter OverviewFlutterView
- 第二課改善深層神經網路assignment1-Initialization神經網路
- cs231n - assignment1 - neural net 梯度推導梯度
- 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
- C231n-KNN-assignment1-完全程式碼及註釋KNN