ZPPR001-(展bom)
***********************************************************************
* Title : ZPPR010 *
* Application : *
* Subject : *
* Requested by : *
* Execution : *
* Ref no: : *
* Author :RAINY *
* Req Date : *
***********************************************************************
* Production Order Variance Report *
***********************************************************************
***********************************************************************
*1.取数:
*2.输出: *
***********************************************************************
* MODIFICATIONS (latest entry at the top) *
* ------------------------------------------------------------------- *
* REL DATE NAME (COMPANY) DESCRIPTION TASK-NO *
* --- ---- ---- --------- ----------- ------- *
***********************************************************************
REPORT ZPPR010 NO STANDARD PAGE HEADING
MESSAGE-ID ZSD
LINE-SIZE 132
LINE-COUNT 65.
*----------------------------------------------------------------------
* TYPE-POOLS
*----------------------------------------------------------------------
TYPE-POOLS: SLIS, "ALV
TRUXS.
*----------------------------------------------------------------------
* TABLES/Structure
*----------------------------------------------------------------------
TABLES: AFKO,
AFPO,
AUFM,
MARA,
MARM.
*----------------------------------------------------------------------
* DAGTA /Internal table
*----------------------------------------------------------------------
*&(contain all)
DATA:BEGIN OF IT_DA OCCURS 0,
AUFNR LIKE AFKO-AUFNR, "工单"Prod ID
PLNBEZ LIKE AFKO-PLNBEZ,"成品料号,"Material
PSMNG LIKE AFPO-PSMNG, "工单数量"Prod Qty
ERDAT LIKE AUFK-ERDAT, "创建日期"Prod Creation Date,订单创建日期
AUFLD LIKE AFKO-AUFLD, "结束日期 "BOM Explosion Date,Bom结束日期
MATNR LIKE RESB-MATNR, "组件 "Component,组件
RSNUM LIKE AFKO-RSNUM, "预留号
POSNR LIKE AFPO-POSNR,"项目
DWERK LIKE AFPO-DWERK,"工厂
BDMNG LIKE RESB-BDMNG, "需求数量
GAMNG LIKE AFKO-GAMNG, "订单数量
SYNGE LIKE RESB-BDMNG,"工单用量"Prod Usage ("Reqmt Qty" / Prod Qty用量= 需求数量/生产订单数量
MEINS LIKE MARA-MEINS, "UoM ,单位
SHKZG LIKE RESB-SHKZG, "借贷方
ENMNG LIKE RESB-ENMNG, "需求数量"Total Actual Qty(Prod),总计数量(实际的领料数量)
BOMNG LIKE RESB-BDMNG, "BOM用量"BOM Usage,Bom使用量(CS_BOM_EXPL_MAT_V2)
GETGE LIKE RESB-BDMNG, "BOM需求数量"Total Target QTY (BOM) ,Bom总量【目标数量=BOM 用量×生产订单数量】
VANGE LIKE RESB-BDMNG, "差异数量"Variance,计算量【变化量=实际领料数量-目标数量】
* PDATV LIKE AFKO-PDATV, "创建日期
SEL TYPE C,
END OF IT_DA.
DATA: WA_DA LIKE IT_DA,
WA_DA1 LIKE IT_DA.
*&For csv
DATA:BEGIN OF IT_DATA OCCURS 0,
AUFNR LIKE AFKO-AUFNR, "工单 "Prod ID
PLNBEZ LIKE AFKO-PLNBEZ,"成品料号"Material
PSMNG LIKE AFPO-PSMNG, "工单数量"Prod Qty
ERDAT LIKE AUFK-ERDAT, "创建日期 Prod Creation Date
AUFLD LIKE AFKO-AUFLD, "结束日期"BOM Explosion Date
MATNR LIKE RESB-MATNR, "组件 "Component
DWERK LIKE AFPO-DWERK,"工厂
SYNGE LIKE RESB-BDMNG, "工单用量"Prod Usage ("Reqmt Qty" / Prod Qty用量= 需求数量/生产订单数量
MEINS LIKE MARA-MEINS, "UoM ,单位
ENMNG LIKE RESB-ENMNG, "需求数量"Total Actual Qty(Prod),总计数量(实际的领料数量)
BOMNG LIKE RESB-BDMNG, "BOM用量"BOM Usage,Bom使用量(CS_BOM_EXPL_MAT_V2)
GETGE LIKE RESB-BDMNG, "BOM需求数量"Total Target QTY (BOM) ,Bom总量【目标数量=BOM 用量×生产订单数量】
VANGE LIKE RESB-BDMNG, "差异数量"Variance,计算量【变化量=实际领料数量-目标数量】
SEL TYPE C,
TXT(10) TYPE C,
"RSNUM LIKE AFKO-RSNUM, "预留号
"PDATV LIKE AFKO-PDATV, "创建日期"Prod Creation Date
* BDMNG LIKE RESB-BDMNG, "需求数量
* GAMNG LIKE AFKO-GAMNG, "订单数量
END OF IT_DATA.
DATA: WA_DATA LIKE IT_DATA.
*----------------------------------------------------------------------
* Data parameters for alv report use
*----------------------------------------------------------------------
DATA: G_PROGRAM TYPE SY-REPID,
GW_LAYOUT TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
GT_EVENT TYPE SLIS_T_EVENT,
WA_EVENT TYPE SLIS_ALV_EVENT,
TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA L_LEN TYPE I.
CONSTANTS:ER_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.
DATA:G_FILE LIKE RLGRAP-FILENAME.
DATA:S_FILE LIKE RLGRAP-FILENAME.
DATA:LINE(1000) TYPE C.
*======================================================================
* SELECTION-SCREEN
*======================================================================
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_DWERK LIKE AFPO-DWERK." OBLIGATORY,
SELECT-OPTIONS: S_AUFNR FOR AFKO-AUFNR,
S_PLNBEZ FOR AFKO-PLNBEZ,
S_MATNR FOR AFPO-MATNR,
S_BUDAT FOR AUFM-BUDAT.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK BLK2 WITH FRAME TITLE TEXT-002.
PARAMETERS: RB_IMP RADIOBUTTON GROUP G1,
RB_ALL RADIOBUTTON GROUP G1.
SELECTION-SCREEN END OF BLOCK BLK2.
*SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:P_CSV TYPE C AS CHECKBOX,
P_SEFILE LIKE RLGRAP-FILENAME DEFAULT '/mnt/ReceiveFromMG/Report/'.
*SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK BLK1.
*----------------------------------------------------------------------
* INITIALIZATION
*----------------------------------------------------------------------
INITIALIZATION.
* 初始化数据
PERFORM FRM_INITIAL.
*----------------------------------------------------------------------
* AT SELECTION-SCREEN
*----------------------------------------------------------------------
AT SELECTION-SCREEN.
* 权限检查部分
PERFORM FRM_CHECK_AUTHOR.
*======================================================================
* MAIN PROGRAM
*======================================================================
* START-OF-SELECTION
*----------------------------------------------------------------------
START-OF-SELECTION.
*&获取数据
PERFORM FRM_GET_DATA.
IF P_CSV EQ 'X'.
PERFORM FRM_CSV_OUT.
PERFORM FRM_ALV_OUTPUT.
ELSE.
PERFORM FRM_ALV_OUTPUT.
ENDIF.
* CASE 'X'.
* WHEN RB_PDF.
* CHECK IT_DATAP[] IS NOT INITIAL.
* PERFORM FRM_PDF_OUT.
* WHEN RB_CSV.
* CHECK IT_DATAC[] IS NOT INITIAL.
* PERFORM FRM_CSV_OUT.
* WHEN RB_ALV.
**&ALV展示输出
* CHECK IT_DATA[] IS NOT INITIAL.
* WHEN OTHERS.
* ENDCASE.
*----------------------------------------------------------------------
* END-OF-SELECTION
*----------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Form FRM_INITIAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_INITIAL.
ENDFORM. " FRM_INITIAL
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_AUTHOR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_CHECK_AUTHOR.
ENDFORM. " FRM_CHECK_AUTHOR
*&---------------------------------------------------------------------*
*& Form frm_get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GET_DATA .
* AUFNR LIKE AFKO-AUFNR, "工单 "Prod ID
* PLNBEZ LIKE AFKO-PLNBEZ,"成品料号"Material
* PSMNG LIKE AFPO-PSMNG, "工单数量"Prod Qty
* ERDAT LIKE AUFK-ERDAT, "创建日期 Prod Creation Date
* AUFLD LIKE AFKO-AUFLD, "结束日期"BOM Explosion Date
* MATNR LIKE RESB-MATNR, "组件 "Component
*
* SYNGE LIKE RESB-BDMNG, "工单用量"Prod Usage ("Reqmt Qty" / Prod Qty用量= 需求数量/生产订单数量
* MEINS LIKE AFPO-MEINS, "UoM ,单位
*
* ENMNG LIKE RESB-ENMNG, "需求数量"Total Actual Qty(Prod),总计数量(实际的领料数量)
* BOMNG LIKE RESB-BDMNG, "BOM用量"BOM Usage,Bom使用量(CS_BOM_EXPL_MAT_V2)
* GETGE LIKE RESB-BDMNG, "BOM需求数量"Total Target QTY (BOM) ,Bom总量【目标数量=BOM 用量×生产订单数量】
* VANGE LIKE RESB-BDMNG, "差异数量"Variance,计算量【变化量=实际领料数量-目标数量】
* SEL TYPE C,
* ERDAT LIKE AUFK-ERDAT, "创建日期"Prod Creation Date,订单创建日期
* AUFLD LIKE AFKO-AUFLD, "结束日期 "BOM Explosion Date,Bom结束日期
*一 AFKO-AUFNR 往下到resb组件,
*一 AFKO~PLNBEZ 往下到bom.
*BOM是用函数展开
*SELECT E_Name FROM Employees_China
*UNION
*SELECT E_Name FROM Employees_USA
DATA:L_WAERS LIKE EINE-WAERS.
DATA STB LIKE TABLE OF STPOX WITH HEADER LINE.
DATA:L_TABIX TYPE SY-TABIX.
DATA:L_LINE TYPE I.
DATA:L_MATNR LIKE MARA-MATNR.
DATA:BEGIN OF LT_DATE OCCURS 0,
AUFNR LIKE AUFM-AUFNR,
END OF LT_DATE.
DATA:BEGIN OF LT_AUFM OCCURS 0,
AUFNR LIKE AUFM-AUFNR,
MATNR LIKE AUFM-MATNR,
MEINS LIKE AUFM-MEINS,
SHKZG LIKE AUFM-SHKZG,
MENGE LIKE AUFM-MENGE,
BUDAT LIKE AUFM-BUDAT,
END OF LT_AUFM.
DATA:L_AUFNR LIKE AFKO-AUFNR.
DATA:BEGIN OF LT_QTY OCCURS 0,
AUFNR LIKE AUFM-AUFNR,
MATNR LIKE AUFM-MATNR,
SHKZG LIKE AUFM-SHKZG,
MENGE LIKE AUFM-MENGE,
MENGE_1 LIKE AUFM-MENGE,
END OF LT_QTY.
DATA:BEGIN OF LT_AQ OCCURS 0,
AUFNR LIKE AUFM-AUFNR,
MATNR LIKE AUFM-MATNR,
MENGE_1 LIKE AUFM-MENGE,
END OF LT_AQ.
DATA:LT_DATA LIKE TABLE OF IT_DATA WITH HEADER LINE.
* BREAK VN0037.
*&S1,过选择条件AUFM取到合适工单(join afpo limit product )
SELECT AUFM~AUFNR AUFM~MATNR
AUFM~MEINS AUFM~SHKZG
AUFM~MENGE AUFM~BUDAT
INTO TABLE LT_AUFM
FROM AUFM
JOIN AFKO
ON AUFM~AUFNR EQ AFKO~AUFNR
* AND AUFM~WERKS EQ AFKO~DWERK
WHERE AUFM~WERKS EQ P_DWERK
AND AUFM~AUFNR IN S_AUFNR
AND BUDAT IN S_BUDAT
AND BWART IN ('261','262')
AND AUFM~MATNR IN S_MATNR
AND AFKO~PLNBEZ IN S_PLNBEZ.
SORT LT_AUFM BY AUFNR MATNR.
*DELETE ADJACENT DUPLICATES FROM LT_AUFM COMPARING ALL FIELDS.
L_LINE = LINES( LT_AUFM[] ).
IF L_LINE EQ 0.
MESSAGE I000 WITH 'No qualified data!'.
STOP.
ENDIF.
*&S2.获取满足条件工单
LOOP AT LT_AUFM.
MOVE-CORRESPONDING LT_AUFM TO LT_DATE.
COLLECT LT_DATE.
ENDLOOP.
*&3.取AFKO-AUFNR 及工单组件
SELECT AFKO~AUFNR
AFKO~PLNBEZ
AFPO~PSMNG
AUFK~ERDAT
AFKO~AUFLD
RESB~MATNR
AFPO~POSNR
AFPO~DWERK
RESB~BDMNG
AFKO~GAMNG
AFPO~MEINS
RESB~ENMNG
RESB~SHKZG
INTO CORRESPONDING FIELDS OF TABLE IT_DA
FROM AFKO
JOIN AFPO
ON AFKO~AUFNR EQ AFPO~AUFNR
JOIN AUFK
ON AFKO~AUFNR EQ AUFK~AUFNR
JOIN RESB
ON AFKO~RSNUM EQ RESB~RSNUM
AND AFKO~AUFNR EQ RESB~AUFNR
AND AFPO~DWERK EQ RESB~WERKS
FOR ALL ENTRIES IN LT_DATE
WHERE AFKO~AUFNR EQ LT_DATE-AUFNR
AND AFPO~DWERK EQ P_DWERK
AND RESB~MATNR IN S_MATNR
AND AFPO~XLOEK NE 'X'
AND AFKO~PLNBEZ IN S_PLNBEZ
AND RESB~RGEKZ = 'X'.
SORT IT_DA BY AUFNR MATNR.
L_LINE = LINES( IT_DA[] ).
IF L_LINE EQ 0.
MESSAGE I000 WITH 'No qualified data!'.
STOP.
ENDIF.
*&S4.处理工单数据
LOOP AT IT_DA WHERE SEL NE 'X'.
L_TABIX = SY-TABIX.
CLEAR WA_DA.
MOVE IT_DA TO WA_DA.
CLEAR L_WAERS.
*&L1.排除非进口组件
IF RB_IMP EQ 'X'.
SELECT SINGLE EINE~WAERS
INTO L_WAERS
FROM EINA
JOIN EINE
ON EINA~INFNR EQ EINE~INFNR
WHERE EINA~MATNR EQ IT_DA-MATNR
AND EINA~LOEKZ NE 'X'
AND EINE~WERKS EQ IT_DA-DWERK.
IF SY-SUBRC NE 0 OR L_WAERS EQ 'RMB'.
* IF L_WAERS EQ 'RMB'.
DELETE IT_DA INDEX L_TABIX.
CLEAR IT_DA.
CONTINUE.
ENDIF.
ENDIF.
CLEAR L_AUFNR.
*L2.根据产品 AFKO~PLNBEZ 往下到bom.
*&一个新工单展一次BOM
AT NEW PLNBEZ.
L_AUFNR = IT_DA-AUFNR.
* L_MATNR = IT_DA-PLNBEZ.
* ENDAT.
* ENDAT.
* at first with
* at first while
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
CAPID = 'PP01' "application id
DATUV = WA_DA-ERDAT "有效开始日
EMENG = WA_DA-PSMNG "工厂数量'1'
MDMPS = 'X' "展虚拟
MEHRS = 'X' "展多层
MTNRV = WA_DA-PLNBEZ"物料
STLAN = '1' "Bom用途
WERKS = WA_DA-DWERK "工厂
AUSKZ = 'X' "计算损耗
* RNDKZ = '1' "不取整
* IMPORTING
* TOPMAT =
* DSTST =
TABLES
STB = STB
* MATCAT =
EXCEPTIONS
ALT_NOT_FOUND = 1
CALL_INVALID = 2
MATERIAL_NOT_FOUND = 3
MISSING_AUTHORIZATION = 4
NO_BOM_FOUND = 5
NO_PLANT_DATA = 6
NO_SUITABLE_BOM_FOUND = 7
CONVERSION_ERROR = 8
OTHERS = 9 .
IF SY-SUBRC EQ 0.
*&L3.获取BOM组件
*计算BOM 用量
IF S_MATNR IS NOT INITIAL.
DELETE STB WHERE IDNRK NOT IN S_MATNR.
ENDIF.
LOOP AT STB.
SELECT SINGLE SCHGT INTO STB-SCHGT
FROM MARC
WHERE WERKS = WA_DA-DWERK
AND MATNR = STB-IDNRK .
*&祛除虚拟行
IF STB-DUMPS = '' AND STB-RGEKZ = '1' AND STB-SCHGT NE 'X'.
* XMATNR-MATNRV1 = STB-IDNRK.
* IMATNR-MAKTXV2 = STB-OJTXP.
* XMATNR-WERKS = IMATNR-WERKS.
* IF STB-IDNRK NE WA_DA-MATNR.
*&L...读取BOM组件和工单组件是否重复
READ TABLE IT_DA WITH KEY MATNR = STB-IDNRK AUFNR = L_AUFNR.". BINARY SEARCH."AUFNR = STB-AUFNR
*&L4..只是BOM组件,则工单用量、工单领料量为0
IF SY-SUBRC NE 0.
IT_DATA-AUFNR = WA_DA-AUFNR.
IT_DATA-PLNBEZ = WA_DA-PLNBEZ.
IT_DATA-PSMNG = WA_DA-PSMNG.
IT_DATA-ERDAT = WA_DA-ERDAT.
IT_DATA-AUFLD = WA_DA-AUFLD.
IT_DATA-MATNR = STB-IDNRK.
IT_DATA-DWERK = WA_DA-DWERK.
IT_DATA-SYNGE = 0.
IT_DATA-MEINS = WA_DA-MEINS.
IT_DATA-ENMNG = 0.
*&L5.BOM需求数量
IF STB-ALPOS = 'X'.
*&L6.bom替代项目处理
IT_DATA-GETGE = STB-MNGLG * ( STB-EWAHR / 100 )."使用可能性按 % (可选项目)
ELSE.
IT_DATA-GETGE = STB-MNGLG.
* IT_DATA-GETGE = STB-MNGLG.
ENDIF.
*&L7.BOM用量 Total Target QTY (BOM)
IT_DATA-BOMNG = IT_DATA-GETGE / IT_DATA-PSMNG.
*IT_DATA-GETGE = STB-MNGLG.
*IT_DATA-BOMNG = STB-MENGE.
*&L8.计算变化数量 Variance
IT_DATA-VANGE = IT_DATA-ENMNG - IT_DATA-GETGE.
IT_DATA-TXT = 'BOM组件'.
APPEND IT_DATA.
*COLLECT IT_DATA.
CLEAR: IT_DA,IT_DATA.
CONTINUE.
ELSE.
*&L...既是BOM组件又是工单组件
MOVE IT_DA TO WA_DA1.
MOVE-CORRESPONDING WA_DA1 TO IT_DATA.
IT_DATA-SEL = ''.
* IT_DATA-MATNR = STB-IDNRK.
*&L2.1.BOM需求数量
IF STB-ALPOS = 'X'.
*&L2.2.bom替代项目处理
IT_DATA-GETGE = STB-MNGLG * ( STB-EWAHR / 100 )."使用可能性按 % (可选项目)
ELSE.
IT_DATA-GETGE = STB-MNGLG.
* IT_DATA-GETGE = STB-MNGLG.
ENDIF.
*&L2.3.BOM用量 Total Target QTY (BOM)
IT_DATA-BOMNG = IT_DATA-GETGE / IT_DATA-PSMNG.
*&S2.4计算工单用量 Prod Usage【用量= 需求数量/生产订单数量】
IT_DATA-SYNGE = WA_DA1-BDMNG / WA_DA1-GAMNG.
*&S2.5计算变化数量 Variance
IT_DATA-VANGE = IT_DATA-ENMNG - IT_DATA-GETGE.
IT_DATA-TXT = '共同组件'.
APPEND IT_DATA.
*COLLECT IT_DATA.
CLEAR:IT_DA, IT_DATA,WA_DA1.
*&S2.6已做处理的工单组件删除
* DELETE IT_DA WHERE MATNR = STB-IDNRK.
*&S2.7共同组件打上标识,后续不处理
IT_DA-SEL = 'X'.
MODIFY IT_DA TRANSPORTING SEL WHERE MATNR = STB-IDNRK AND AUFNR = L_AUFNR."INDEX L_TABIX.
CONTINUE.
ENDIF.
ENDIF.
CLEAR:STB.
ENDLOOP.
ENDIF.
ENDAT.
*&排除重复第一条,
IF IT_DA-SEL EQ 'X'.
CONTINUE.
ENDIF.
*&S5.BOM 用量
IT_DA-BOMNG = 0.
*&S6.BOM 需求量
IT_DA-GETGE = 0.
*&S7.计算工单用量 Prod Usage【用量= 需求数量/生产订单数量】
IT_DA-SYNGE = IT_DA-BDMNG / IT_DA-GAMNG.
*&S8.计算变化数量 Variance
IT_DA-VANGE = IT_DA-ENMNG - IT_DA-GETGE.
*&S9.MOVE TO IT_DATA.
MOVE-CORRESPONDING IT_DA TO IT_DATA.
IT_DATA-SEL = ''.
IT_DATA-TXT = '工单组件'.
*COLLECT IT_DATA.
APPEND IT_DATA.
CLEAR IT_DATA.
* COLLECT IT_DATA.
*&S10.modify it_da
MODIFY IT_DA INDEX L_TABIX.
CLEAR IT_DA.
ENDLOOP.
SORT IT_DATA BY AUFNR MATNR.
* DELETE ADJACENT DUPLICATES FROM IT_DATA COMPARING AUFNR MATNR.
*&S11. 加入AUFM领料物料
LOOP AT LT_AUFM.
READ TABLE IT_DATA WITH KEY AUFNR = LT_AUFM-AUFNR MATNR = LT_AUFM-MATNR ."BINARY SEARCH .
" BINARY SEARCH.
IF SY-SUBRC NE 0.
READ TABLE IT_DATA WITH KEY AUFNR = LT_AUFM-AUFNR.
IT_DATA-AUFNR = LT_AUFM-AUFNR.
IT_DATA-PLNBEZ = IT_DATA-PLNBEZ.
IT_DATA-PSMNG = IT_DATA-PSMNG.
IT_DATA-ERDAT = IT_DATA-ERDAT.
IT_DATA-AUFLD = IT_DATA-AUFLD.
*&AUFM料
IT_DATA-MATNR = LT_AUFM-MATNR.
IT_DATA-MEINS = LT_AUFM-MEINS.
IT_DATA-TXT = 'AUFM增加料'.
IT_DATA-SEL = 'X'.
IT_DATA-SYNGE = 0.
IT_DATA-ENMNG = 0.
IT_DATA-BOMNG = 0.
IT_DATA-GETGE = 0.
IT_DATA-VANGE = 0.
APPEND IT_DATA.
ENDIF.
CLEAR LT_AUFM.
ENDLOOP.
*&S12.AUFM取实际的领料数量
LOOP AT LT_AUFM.
LT_AQ-AUFNR = LT_AUFM-AUFNR.
LT_AQ-MATNR = LT_AUFM-MATNR.
IF LT_AUFM-SHKZG EQ 'H'.
LT_AQ-MENGE_1 = LT_AUFM-MENGE.
ELSE.
LT_AQ-MENGE_1 = 0 - LT_AUFM-MENGE.
ENDIF.
* MODIFY LT_AQ.
COLLECT LT_AQ.
CLEAR:LT_AQ,LT_AUFM.
ENDLOOP.
SORT LT_AQ BY AUFNR MATNR.
*&collect 数据
LT_DATA[] = IT_DATA[].
CLEAR IT_DATA[].
DATA:L_PSMNG LIKE RESB-BDMNG,
L_ENMNG LIKE RESB-ENMNG.
*&ADD1
SORT LT_DATA BY AUFNR MATNR.
*&S13.计算
LOOP AT LT_DATA.
L_TABIX = SY-TABIX.
AT NEW AUFNR.
CLEAR:L_AUFNR,L_PSMNG.
L_AUFNR = LT_DATA-AUFNR.
L_PSMNG = LT_DATA-PSMNG.
ENDAT.
*&L1.排除非进口组件
CLEAR L_WAERS.
IF RB_IMP EQ 'X'.
SELECT SINGLE EINE~WAERS
INTO L_WAERS
FROM EINA
JOIN EINE
ON EINA~INFNR EQ EINE~INFNR
WHERE EINA~MATNR EQ LT_DATA-MATNR
AND EINA~LOEKZ NE 'X'
AND EINE~WERKS EQ LT_DATA-DWERK.
IF SY-SUBRC NE 0 OR L_WAERS EQ 'RMB'.
DELETE LT_DATA INDEX L_TABIX.
CLEAR LT_DATA.
CONTINUE.
ENDIF.
ENDIF.
*&L2.*& Convert units
* CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
* EXPORTING
* INPUT = LT_DATA-MEINS
* LANGUAGE = '1'"SY-LANGU"'
* IMPORTING
** LONG_TEXT =
* OUTPUT = LT_DATA-MEINS
** SHORT_TEXT =
* EXCEPTIONS
* UNIT_NOT_FOUND = 1
* OTHERS = 2.
CLEAR:L_ENMNG.
*&L3.获取实际用量(领料数量)
*&ADD2
AT NEW MATNR.
READ TABLE LT_AQ WITH KEY AUFNR = LT_DATA-AUFNR MATNR = LT_DATA-MATNR BINARY SEARCH.
IF SY-SUBRC EQ 0.
L_ENMNG = LT_AQ-MENGE_1.
LT_DATA-ENMNG = LT_AQ-MENGE_1.
ENDIF.
ENDAT.
*IF IT_DATA-VANGE EQ 0.
* 计划领料数,计算变化数量
*&S0.计算变化数量 Variance
* Total Actual Qty(Prod) - Total Target QTY (BOM)
*&L3.计算变化量
LT_DATA-VANGE = LT_DATA-ENMNG - LT_DATA-GETGE.
MOVE-CORRESPONDING LT_DATA TO IT_DATA.
IT_DATA-TXT = LT_DATA-TXT.
L_PSMNG = IT_DATA-PSMNG.
IT_DATA-ENMNG = L_ENMNG.
* MODIFY IT_DATA INDEX L_TABIX TRANSPORTING ENMNG VANGE.
COLLECT IT_DATA.
* AT NEW MATNR.
* MODIFY IT_DATA TRANSPORTING ENMNG WHERE AUFNR = L_AUFNR.
* ENDAT.
*&订单数量处理(工单用量唯一)
AT END OF AUFNR.
MODIFY IT_DATA TRANSPORTING PSMNG WHERE AUFNR = L_AUFNR.
ENDAT.
CLEAR:LT_DATA,IT_DATA.
ENDLOOP.
SORT IT_DATA BY AUFNR MATNR.
DELETE ADJACENT DUPLICATES FROM IT_DATA COMPARING AUFNR MATNR .
L_LINE = LINES( IT_DATA[] ).
IF L_LINE EQ 0.
MESSAGE I000 WITH 'No qualified data!'.
STOP.
ELSE.
MESSAGE S000 WITH 'Find data' L_LINE 'lines!'.
ENDIF.
ENDFORM. " frm_get_data
*&---------------------------------------------------------------------*
*& Form frm_alv_output
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_ALV_OUTPUT .
DATA: L_NN TYPE I.
DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
*&===>fieldcat
DEFINE ADD_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-FIELDNAME = &1.
WA_FIELDCAT-SELTEXT_L = &2.
* WA_FIELDCAT-KEY = &3.
WA_FIELDCAT-REF_FIELDNAME = &3.
WA_FIELDCAT-COL_POS = L_NN + 1.
WA_FIELDCAT-REF_TABNAME = &4.
* WA_FIELDCAT-JUST = &4.
WA_FIELDCAT-OUTPUTLEN = &5.
WA_FIELDCAT-FIX_COLUMN = &6.
WA_FIELDCAT-NO_ZERO = &7.
WA_FIELDCAT-EDIT_MASK = &8.
WA_FIELDCAT-EMPHASIZE = &9.
* WA_FIELDCAT-COLOR = &9.
*==CUNIT
APPEND WA_FIELDCAT TO GT_FIELDCAT.
END-OF-DEFINITION.
CLEAR GT_FIELDCAT.
REFRESH GT_FIELDCAT.
* AUFNR LIKE AFKO-AUFNR, "Prod ID
* PLNBEZ LIKE AFKO-PLNBEZ,"Material
* PSMNG LIKE AFPO-PSMNG, "Prod Qty
* PDATV LIKE AFKO-PDATV, "Prod Creation Date,订单创建日期
* AUFLD LIKE AFKO-AUFLD, "BOM Explosion Date,Bom结束日期
* MATNR LIKE AFPO-MATNR, "Component,组件
** BDMNG LIKE RESB-BDMNG, "需求数量
** GAMNG LIKE AFKO-GAMNG, "订单数量
* SYNGE LIKE RESB-BDMNG, "Prod Usage ("Reqmt Qty" / Prod Qty用量= 需求数量/生产订单数量
* MEINS LIKE AFPO-MEINS, "UoM ,单位
* ENMNG LIKE RESB-ENMNG, "Total Actual Qty(Prod),总计数量(实际的领料数量)
* BOMNG LIKE RESB-BDMNG, "BOM Usage,Bom使用量(CS_BOM_EXPL_MAT_V2)
* GETGE LIKE RESB-BDMNG, "Total Target QTY (BOM) ,Bom总量【目标数量=BOM 用量×生产订单数量】
* VANGE LIKE RESB-BDMNG, "Variance,计算量【变化量=实际领料数量-目标数量】
* SEL TYPE C,
ADD_FIELDCAT 'AUFNR' 'Prod ID' '' '' '12' '' 'X' '' ''."1
ADD_FIELDCAT 'PLNBEZ' 'Material' '' '' '18' '' '' '' ''."1
ADD_FIELDCAT 'PSMNG' 'Prod Qty' '' '' '' '' '' '' ''."2
ADD_FIELDCAT 'ERDAT' 'Prod Creation Date' '' '' '' '' '' '' ''."3
ADD_FIELDCAT 'AUFLD' 'BOM Explosion Date' '' '' '' '' '' '' ''."5
ADD_FIELDCAT 'MATNR' 'Component' '' '' '18' '' '' '' ''."4
ADD_FIELDCAT 'SYNGE' 'Prod Usage' '' '' '' '' '' '' ''."5
ADD_FIELDCAT 'BOMNG' 'BOM Usage' '' '' '' '' '' '' ''."7
ADD_FIELDCAT 'MEINS' 'UoM' 'MEINS' 'AFPO' '' '' '' '==CUNIT' ''."5
ADD_FIELDCAT 'GETGE' 'Total Target QTY (BOM)' '' '' '' '' '' '' ''."7
ADD_FIELDCAT 'ENMNG' 'Total Actual Qty(Prod)' '' '' '' '' '' '' ''."7
ADD_FIELDCAT 'VANGE' 'Variance' '' '' '' '' '' '' 'C610'."8
ADD_FIELDCAT 'TXT' '组件描述' '' '' '' '' '' '' ''."8
*&===>layout
GW_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GW_LAYOUT-ZEBRA = ''.
GW_LAYOUT-DETAIL_POPUP = 'X'.
*&===>Way1:
*&use event to get frm_top_of_page.
*&===>event
* CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
* EXPORTING
* I_LIST_TYPE = 0
* IMPORTING
* ET_EVENTS = GT_EVENT
* EXCEPTIONS
* LIST_TYPE_WRONG = 1
* OTHERS = 2.
* READ TABLE GT_EVENT WITH KEY NAME = SLIS_EV_TOP_OF_PAGE INTO LS_EVENT.
* IF SY-SUBRC EQ 0.
* MOVE ER_FORMNAME_TOP_OF_PAGE TO LS_EVENT-FORM.
* APPEND LS_EVENT TO GT_EVENT.
* ENDIF.
*&TOP OF PAGE.
PERFORM COMMENT_BUILD USING TOP_OF_PAGE[].
*& 调用函数显示ALV列表
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_SAVE = 'A'
IS_LAYOUT = GW_LAYOUT
IT_FIELDCAT = GT_FIELDCAT
IT_EVENTS = GT_EVENT
TABLES
T_OUTTAB = IT_DATA
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " frm_alv_output
*&---------------------------------------------------------------------*
*& Form comment_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->U_ER_LIST_TOP_OF_PAGE text
*----------------------------------------------------------------------*
FORM COMMENT_BUILD USING U_ER_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
* DATA: LS_LINE TYPE SLIS_LISTHEADER,
* LV_CUST TYPE STRING,
* LV_STR TYPE STRING.
*
*
* CLEAR: LS_LINE, LV_STR.
* LS_LINE-TYP = 'H'.
*
* CONCATENATE LV_CUST 'Production Order Variance Report' INTO LV_STR.
* LS_LINE-INFO = LV_STR.
* APPEND LS_LINE TO U_ER_LIST_TOP_OF_PAGE.
*
* CLEAR: LS_LINE, LV_STR.
* LS_LINE-TYP = 'S'.
* CONCATENATE 'Valid to:' SY-DATUM+0(4) '-' SY-DATUM+4(2) '-' SY-DATUM+6(2) INTO LV_STR.
* LS_LINE-KEY = LV_STR.
* APPEND LS_LINE TO U_ER_LIST_TOP_OF_PAGE.
ENDFORM. " COMMENT_BUILDS
*---------------------------------------------------------------------*
* FORM top_of_page *
*---------------------------------------------------------------------*
FORM TOP_OF_PAGE.
* CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
* EXPORTING
* I_LOGO = 'ENJOYSAP_LOGO'"'ZMG_LOGO_NEW'
* IT_LIST_COMMENTARY = TOP_OF_PAGE.
ENDFORM. "TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form FRM_CSV_OUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_CSV_OUT .
DATA:PSMNG(20),
SYNGE(20),
ENMNG(20),
BOMNG(20),
GETGE(20),
VANGE(20).
*&是否需要一张单存一个文件
* DATA:BEGIN OF LT_CSV OCCURS 0,
* AUFNR LIKE AFKO-AUFNR,
* END OF LT_CSV.
* DATA:LT_AUFNR LIKE TABLE OF IT_DATA WITH HEADER LINE.
* LOOP AT IT_DATA.
* LT_CSV-AUFNR = IT_DATA-AUFNR.
* COLLECT LT_CSV.
* ENDLOOP.
*
* LOOP AT LT_CSV.
* CLEAR lt_aufnr[].
* LT_AUFNR[] = IT_DATA[].
* DELETE LT_AUFNR WHERE AUFNR NE LT_CSV-AUFNR.
* ENDLOOP.
*SORT IT_DATA BY ZONGL FENEL ZMDNM.
CONCATENATE P_SEFILE SY-DATUM '_Production Order list.csv' INTO S_FILE. "服务器保存的目录和文件名
OPEN DATASET S_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT . "打开文件
IF SY-SUBRC = 0.
CONCATENATE 'Prod ID'
'Material'
'ProdQty'
'Prod Creation Date'
'BOM Explosion Date'
'Component '
'Prod Usage'
'UOM'
'Total Actual Qty(Prod)'
'BOM Usage'
'Total Target QTY (BOM)'
'Variance'
INTO LINE SEPARATED BY ','.
TRANSFER LINE TO S_FILE .
LOOP AT IT_DATA.
PSMNG = IT_DATA-PSMNG.
SYNGE = IT_DATA-SYNGE.
ENMNG = IT_DATA-ENMNG.
BOMNG = IT_DATA-BOMNG.
GETGE = IT_DATA-GETGE.
VANGE = IT_DATA-VANGE.
CONCATENATE IT_DATA-AUFNR
IT_DATA-PLNBEZ
PSMNG
IT_DATA-ERDAT
IT_DATA-AUFLD
IT_DATA-MATNR
SYNGE
IT_DATA-MEINS
ENMNG
BOMNG
GETGE
VANGE
INTO LINE SEPARATED BY ','.
TRANSFER LINE TO S_FILE .
IF SY-SUBRC NE 0 .
MESSAGE 'ERROR!!' TYPE 'E'.
STOP.
ENDIF.
CLEAR LINE .
ENDLOOP.
CLOSE DATASET S_FILE.
MESSAGE 'Save to shared folder succeed!' TYPE 'S'.
ELSE.
MESSAGE E000 WITH 'OPEN ERROR!!' DISPLAY LIKE 'S'.
STOP.
ENDIF.
ENDFORM. " FRM_CSV_OUT
ZPPR001-(展bom)的更多相关文章
- 展BOM
CS_BOM_EXPL_MAT_V2 *&---------------------------------------------------------------------* *&am ...
- ZPPR032-批量展BOM
*-----------------------------------------------------------------------REPORT zppr032 NO STANDARD P ...
- [MSSQL]最小公约数
[摘要]一个朋友在展BOM的时候有这种需求,两列字段(数值):A ,B A=用量,B=底数,组成用量=用量/底数.A/B,若能被整除,显示整除的结果,若不能整除显示分数形式A/B(分数形式要是约分 ...
- MM-委外业务
SAP MM-分包业务讲解(subcontracting)-01-主数据与采购订单的创建 SAP MM-分包业务讲解(subcontracting)-02-主数据与采购订单的创建-多BOM的业务情况分 ...
- 订单BOM、销售BOM、标准BOM
订单BOM.销售BOM.标准BOM 訂單BOM: 是實際生產時用的BOM, 在標準BOM和銷售BOM基礎上增減物料的BOM銷售BOM: 是為特定客戶設定的BOM, 在主檔數據層次上的BOM, 在生 ...
- 订单BOM与销售BOM的区别
訂單BOM: 是實際生產時用的BOM, 在標準BOM和銷售BOM基礎上增減物料的BOM 銷售BOM: 是為特定客戶設定的BOM, 在主檔數據層次上的BOM, 在生產時是帶到訂單BOM中去的. 標準BO ...
- HTML BOM Browser对象
BOM:Browser Object Model,即浏览器对象模型,提供了独立于内容的.可以与浏览器窗口进行互动的对象结构. Browser对象:指BOM提供的多个对象,包括:Window.Navig ...
- 一步步学习javascript基础篇(7):BOM和DOM
一.什么是BOM.什么是DOM BOM即浏览器对象模型,主要用了访问一些和网页无关的浏览器功能.如:window.location.navigator.screen.history等对象. DOM即文 ...
- BOM,DOM,ECMAScripts三者的关系
一:DOM 文档对象模型(DOM)是表示文档(比如HTML和XML)和访问.操作构成文档的各种元素的应用程序接口(API) DOM是HTML与JavaScript之间沟通的桥梁. DOM下,HTM ...
随机推荐
- Socket通信(转)
一.Socket通信简介 Android与服务器的通信方式主要有两种,一是Http通信,一是Socket通信.两者的最大差异在于,http连接使用的是“请求—响应方式”,即在请求时建立连接通道,当客户 ...
- iOS只执行一次的方法
IOS开发(64)之GCD任务最多只执行一次 1 前言 使用 dispatch_once 函数 在 APP 的生命周期内来保证你想确保每段代码只执行一次,即使它在代码的不同地方多次调用(比如单例的初始 ...
- c++普通高精加
//作为一名蒟蒻,还请诸位不要吐槽. //第一次打c++高精加,内心有点小激动. //为codevs3116 高精度练习之加法 //程序太简单,就不打注释了. #include<cstdio&g ...
- PowerMock遇到的问题——4
当我们在测试一个方法的构造方法的时候,有的时候内部需要new一些对象,这是就需要用到PowerMock.exceptNew(),这个方法,但有时候传的参数有关键字this,比如SAPPublisher ...
- comboBox绑定数据库、模糊查询
实现: 一.绑定数据库 点击查询按钮,comboBox显示从数据库查到的某字段的一列数据 方法:在按钮的点击事件绑定数据库 private void button1_Click(object send ...
- 为ASP.NET MVC应用添加自定义路由
这里,我们将学习如何给asp.net mvc应用添加自定义路由.用自定义路由来修改默认路由表. 对一些简单的asp.net mvc应用,默认的路由表就已经足够了.但是,当你需要创建特殊的路由时,就需要 ...
- 关于Spatial referencing by geographical identifiers 标准
地理信息空间参考大体可以分为两类,ISO给出了分类:Spatial referencing by geographical identifiers(根据地理标识符的空间定位,ISO 19112)与Sp ...
- ie浏览器兼容性快速处理小招
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 模拟iOS系统原生导航条隐藏或显示动画
借UIView动画,使更改导航条的hidden属性这一过程动起来.悦德财富:https://yuedecaifu.com 代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
- javascript面向对象知识点
首先,声明何为对象:对象是键值对的集合 其次,声明:变量就是键值对 再次,声明:函数也是变量 1. JavaScript包含:ECMAScript(核心).DOM(文档对象模型)和BOM(浏览器对象模 ...