zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    详解javascript的深拷贝与浅拷贝
    fis3+vue+pdf.js制作预览PDF文件或其他
    那一年,2020
    H5移动端IOS/Android兼容性总结,持续更新中…
    浏览器里点击复制到剪贴板的小方法
    elementUI upload 对图片的宽高做校验
    CSS实现核辐射警告标志
    github常用命令
    偶遇vue-awesome-swiper的坑
    gauge+python+vscode搭建自动化测试框架
  • 原文地址:https://www.cnblogs.com/rainysblog/p/4449448.html
Copyright © 2011-2022 走看看