• 成本分析报表


    最近做的一个成本分析的报表。
    
    以下是部分关键代码,仅作参考,just 而已!
    
    *&---------------------------------------------------------------------*
    *& Report  ZCOXY006
    *&
    *&---------------------------------------------------------------------*
    *&Author:  xieyao 2009.08.21
    *&Funtion: 成本分析-制造费用、人工成本、材料费用分析
    *&注意:定义的表结构顺序请不要更改
    *&
    *&Modify: xieyao 2009.08.31
    *&        xieyao 2009.09.03 标准价格取MBEW 实际采购价格取KONP
    *&
    *&---------------------------------------------------------------------*
    
    REPORT  zcoxy006 NO STANDARD PAGE HEADING LINE-SIZE 255..
    
    TYPE-POOLS: slis.
    INCLUDE zsy_xy_tcus.
    TABLES: coss,cost, afru,mcafpov,cobk,afko,afpo,
            s026, aufk,mapl,ckmlhd,ckmlcr,mbew.
    
    DATA:    g_repid     LIKE sy-repid.
    g_repid = sy-repid.
    *
    DATA: BEGIN OF gt_objnr OCCURS 100,
          objnr LIKE coep-objnr,
          END OF gt_objnr.
    
    DATA: BEGIN OF i_list OCCURS 0,
          rueck LIKE afru-rueck,              "操作完成的确认编号
          ersda LIKE afru-ersda,              "确认输入日期
          budat LIKE afru-budat,              "记帐日期
          werks LIKE afru-werks,
          ile01 LIKE afru-ile01,              "要确认作业的计量单位
          ism01 LIKE afru-ism01,              "当前需确认作业
          ile02 LIKE afru-ile02,"
          ism02 LIKE afru-ism02,"
          ile03 LIKE afru-ile03,"
          ism03 LIKE afru-ism03,"
          ile04 LIKE afru-ile04,"
          ism04 LIKE afru-ism04,"
          ile05 LIKE afru-ile05,"
          ism05 LIKE afru-ism05,"
          ile06 LIKE afru-ile06,"
          ism06 LIKE afru-ism06,"
          wablnr LIKE afru-wablnr,            "物料凭证编号
          aufnr LIKE afru-aufnr,              "订单号
          vornr LIKE afru-vornr,              "工序
          arbid LIKE afru-arbid,              "对象ID
          matnr LIKE afko-plnbez,
          plnnr LIKE afko-plnnr,
          objnr LIKE aufk-objnr,              "对象号
          auart LIKE aufk-auart,              "PO type
          month TYPE char_02,                 "期间
          END OF i_list.
    
    DATA: BEGIN OF gt_list OCCURS 0,
          aufnr LIKE afru-aufnr,              "订单号
          vornr LIKE afru-vornr,              "工序
          arbid LIKE afru-arbid,              "对象ID
          auart LIKE aufk-auart,              "PO type
          werks LIKE afru-werks,
          matnr LIKE afko-plnbez,
          objnr LIKE aufk-objnr,
          plnnr LIKE afko-plnnr,
          year(4)  TYPE c,
          month TYPE char_02,
          gmnga(13) TYPE c,
          gmein LIKE afru-gmein,
          ile01 LIKE afru-ile01,
          ism01 LIKE afru-ism01,
          ile02 LIKE afru-ile02,"
          ism02 LIKE afru-ism02,"
          ile03 LIKE afru-ile03,"
          ism03 LIKE afru-ism03,"
          ile04 LIKE afru-ile04,"
          ism04 LIKE afru-ism04,"
          ile05 LIKE afru-ile05,"
          ism05 LIKE afru-ism05,"
          ile06 LIKE afru-ile06,"
          ism06 LIKE afru-ism06,"
          withcost_s_03 LIKE s026-enwrt,     "实际材料成本
          withcost_q_03 LIKE s026-enwrt,     "标准材料成本
          END OF gt_list.
    DATA: lwa_list LIKE LINE OF gt_list,
          wa_list LIKE LINE OF gt_list.
    
    DATA: BEGIN OF i_coss OCCURS 0,
          objnr LIKE coss-objnr,
          gjahr LIKE coss-gjahr,
          kstar LIKE coss-kstar,               "成本要素
          uspob(22) TYPE c,                    "初始对象
          meinh LIKE coss-meinh,               "计量单位
          wkg001 type p decimals 4,
          wkg002 type p decimals 4,
          wkg003 type p decimals 4,
          wkg004 type p decimals 4,
          wkg005 type p decimals 4,
          wkg006 type p decimals 4,
          wkg007 type p decimals 4,
          wkg008 type p decimals 4,
          wkg009 type p decimals 4,
          wkg010 type p decimals 4,
          wkg011 type p decimals 4,
          wkg012 type p decimals 4,
          wkg013 type p decimals 4,
          wkg014 type p decimals 4,
          wkg015 type p decimals 4,
          wkg016 type p decimals 4,
    
          END OF i_coss.
    DATA  i_tkg LIKE TABLE OF i_coss WITH HEADER LINE.       "标准成本表
    
    DATA: BEGIN OF gt_coss OCCURS 0,
          objnr LIKE coss-objnr,
          gjahr LIKE coss-gjahr,
          uspob(22) TYPE c,              "初始对象
          meinh LIKE coss-meinh,
    
          withdrawn_01 LIKE s026-enwrt,          "机器
          withdrawn_02 LIKE s026-enwrt,
          withdrawn_03 LIKE s026-enwrt,
          withdrawn_04 LIKE s026-enwrt,
          withdrawn_05 LIKE s026-enwrt,
          withdrawn_06 LIKE s026-enwrt,          "
          END OF gt_coss.
    DATA: gt_tkg LIKE TABLE OF gt_coss WITH HEADER LINE.
    
    DATA: BEGIN OF tkg OCCURS 0,             "作业价格
          objnr LIKE cost-objnr,             "对象号 如:KL10000000004130LAB2
          gjahr LIKE cost-gjahr,
          tkg001 LIKE cost-tkg001,  "作业价格
          tkg002 LIKE cost-tkg002,
          tkg003 LIKE cost-tkg003,
          tkg004 LIKE cost-tkg004,
          tkg005 LIKE cost-tkg005,
          tkg006 LIKE cost-tkg006,
          tkg007 LIKE cost-tkg007,
          tkg008 LIKE cost-tkg008,
          tkg009 LIKE cost-tkg009,
          tkg010 LIKE cost-tkg010,
          tkg011 LIKE cost-tkg011,
          tkg012 LIKE cost-tkg012,
          tke001 LIKE cost-tke001,  "计量单位
          tke002 LIKE cost-tke002,
          tke003 LIKE cost-tke003,
          tke004 LIKE cost-tke004,
          tke005 LIKE cost-tke005,
          tke006 LIKE cost-tke006,
          tke007 LIKE cost-tke007,
          tke008 LIKE cost-tke008,
          tke009 LIKE cost-tke009,
          tke010 LIKE cost-tke010,
          tke011 LIKE cost-tke011,
          tke012 LIKE cost-tke012,
          END OF tkg.
    
     
    
    DATA: order_s_objects TYPE bapi_pp_order_objects.    "输入表头查询
    
    DATA: order_t_component LIKE TABLE OF bapi_order_component,
          order_s_component TYPE bapi_order_component,
    
          order_t_header LIKE TABLE OF bapi_order_header1,
          order_s_header TYPE bapi_order_header1,
    
          order_t_item LIKE TABLE OF bapi_order_item,
          order_s_item TYPE bapi_order_item.
    
    DATA: tab_s_routing TYPE zxy_routing,
          tab_t_routing LIKE TABLE OF tab_s_routing,
    
          routing_table LIKE TABLE OF tab_s_routing.
    DATA: tab_s_purchasing TYPE zxy_purchasing,
          tab_t_purchasing LIKE TABLE OF tab_s_purchasing.
    
    *用作输出的内表
    DATA: BEGIN OF gt_result OCCURS 0,
          objnr LIKE aufk-objnr,
          year(4) TYPE c,
          month TYPE char_02,
          aufnr LIKE afru-aufnr,              "订单号
          auart LIKE aufk-auart,
          matnr LIKE afko-plnbez,
          werks LIKE afru-werks,
          plnnr LIKE afko-plnnr,
          vornr LIKE afru-vornr,              "工序
          budat LIKE afru-budat,
          gmnga(13) TYPE c,          "数量
          gmein LIKE afru-gmein,          "单位
    
          ism01 LIKE afru-ism01,          "实际机器时间
          ile01 LIKE afru-ile01,          "时间单位MIN
          ism01_q LIKE afru-ism01,        "标准机器时间
    
          ism02 LIKE afru-ism02,          "实际人工时间
          ile02 LIKE afru-ile02,          "时间单位MIN
          ism02_q LIKE afru-ism02,        "标准人工时间
    
          withcost_s_01 LIKE s026-enwrt,     "实际机器成本
          withcost_s_02 LIKE s026-enwrt,     "实际人工成本
          withcost_s_03 LIKE s026-enwrt,     "实际材料成本
    
          withcost_q_01 LIKE s026-enwrt,     "标准机器成本
          withcost_q_02 LIKE s026-enwrt,     "标准人工成本
          withcost_q_03 LIKE s026-enwrt,     "标准材料成本
    
          with_ef_m TYPE p DECIMALS 2,    "机器效率
          with_ef_l TYPE p DECIMALS 2,    "人工效率
    
          END OF gt_result.
    FIELD-SYMBOLS: <fs_result> LIKE LINE OF gt_result.
    
    *global value of alv display
    DATA:
          gt_sort  TYPE slis_t_sortinfo_alv,
          gt_fieldcat TYPE slis_t_fieldcat_alv,
          gt_event TYPE slis_alv_event OCCURS 0 WITH HEADER LINE, "Grid输出表头事件内表
          gt_head TYPE slis_t_listheader.     "Grid输出表头
    
    
    *选择条件:
    SELECTION-SCREEN BEGIN OF BLOCK sc_1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS:
                    s_werks FOR afru-werks,
                    s_matnr FOR mapl-matnr,
    
                    s_aufnr FOR afru-aufnr MEMORY ID auf MODIF ID auf,
                    s_auart FOR aufk-auart,
                    s_budat FOR afru-budat.
    SELECTION-SCREEN END OF BLOCK sc_1.
    SELECTION-SCREEN BEGIN OF BLOCK sc_2 WITH FRAME TITLE text-002.
    SELECT-OPTIONS: s_rueck FOR afru-rueck .
    SELECTION-SCREEN END OF BLOCK sc_2.
    ***********************************************************************
    * START-OF-SELECTION
    ***********************************************************************
    START-OF-SELECTION.
    
    
    *计算数据
      PERFORM select_data.
      PERFORM append_gt_result.
      PERFORM alv_output.
    *&---------------------------------------------------------------------*
    *&      Form  select_data
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM select_data .
    *range
      RANGES: lr_kstar  FOR coep-kstar,
              lr_gjahr  FOR coep-gjahr,
              lr_perio  FOR coep-perio,
              lr_objnr  FOR coep-objnr,
              lr_matnr  FOR mapl-matnr,
              lr_plnnr  FOR mapl-plnnr,
              lr_uspob  FOR coss-uspob.
    
      DATA: t_plnnr LIKE afko-plnnr,
            t_matnr LIKE afko-plnbez,
            t_aufnr LIKE afko-aufnr,
            t_result TYPE c.
    *得到订单的确认消耗成本单位-分批的
      SELECT
            a~rueck
            a~ersda
            a~budat
            a~werks
            a~ile01 "
            a~ism01 "
            a~ile02 "
            a~ism02 "
            a~ile03 "
            a~ism03 "
            a~ile04 "
            a~ism04 "
            a~ile05 "
            a~ism05 "
            a~ile06 "
            a~ism06 "
            a~wablnr              "物料凭证编号
            a~aufnr
            a~vornr
            a~arbid               "对象ID,---->成本中心
            b~plnbez AS matnr
            b~plnnr
            c~objnr
            c~auart
            FROM afru AS a
            INNER JOIN afko AS b ON a~aufnr = b~aufnr
            INNER JOIN aufk AS c ON a~aufnr = c~aufnr
            INTO TABLE i_list
            WHERE a~aufnr IN s_aufnr
                AND a~werks IN s_werks
                AND b~plnbez IN s_matnr
                AND c~auart IN s_auart
                AND a~budat IN s_budat
                AND a~rueck IN s_rueck
                AND a~stokz <> 'X'
                AND a~stzhl = ''.
    
      "工艺路线范围选择
      lr_matnr-sign = 'I'.
      lr_matnr-option = 'EQ'.
      lr_plnnr-sign = 'I'.
      lr_plnnr-option = 'EQ'.
    
    *汇总实际工时
      LOOP AT i_list.
        MOVE-CORRESPONDING i_list TO gt_list.                "i_list ------> gt_list
    
        gt_list-year =  i_list-budat(4).
        gt_list-month = i_list-budat+4(2).
    
        CONCATENATE 'OR' i_list-aufnr INTO gt_objnr-objnr .
    
        lr_matnr-low = i_list-matnr.
        lr_plnnr-low = i_list-plnnr.
    
        COLLECT gt_objnr.
        COLLECT lr_matnr.
        COLLECT lr_plnnr.
    
        COLLECT gt_list.
        CLEAR gt_list.
      ENDLOOP.                                                "is right, ok!
    
      CLEAR: gt_objnr,lr_matnr,lr_plnnr.
    *delete rubbish
      DELETE gt_list WHERE ism01 = 0 AND ism02 = 0 AND ism03 = 0 AND ism04 = 0 AND ism05 = 0 AND ism06 = 0.
    **************************************************************************************************
    
      LOOP AT gt_list[] INTO lwa_list.
    ***********************************************
    *取订单主数据、订单组件,算材料成本
    *******
    *add
    ********
        MOVE-CORRESPONDING lwa_list TO wa_list.
        t_plnnr = lwa_list-plnnr.
        t_matnr = lwa_list-matnr.
        t_aufnr = lwa_list-aufnr.
        AT END OF plnnr.
    
    *********************************************************************************************
    
    *取标准工艺路线值
    *******
    *add
    ********
          CALL FUNCTION 'ZXY_ROUTING_READ'
            EXPORTING
              plnty       = 'N'
              plnnr       = t_plnnr
              plnal       = '01'
              matnr       = t_matnr
              sign        = 'X'
            TABLES
              routing_new = tab_t_routing.
    
          IF sy-subrc = 0.
            IF NOT tab_t_routing IS INITIAL.
              "判断内表数据是否相同
              CALL FUNCTION 'COMPARE_TABLES'
                IMPORTING
                  RESULT    = t_result
                TABLES
                  table_new = tab_t_routing
                  table_old = routing_table.
              IF sy-subrc = 0.
                IF t_result = 'F'.
                  APPEND LINES OF tab_t_routing TO routing_table.
                ENDIF.
              ENDIF.
            ENDIF.
            CLEAR tab_t_routing.
          ENDIF.
    
          MODIFY gt_list FROM wa_list.
          CLEAR  gt_list.
          CLEAR: t_plnnr,
                 t_matnr.
    
        ENDAT.
      ENDLOOP.
    **************************************************************
    *此处算实际的成本消耗
    **************************************************************
    *算实际成本
      IF NOT gt_objnr[] IS INITIAL.
        lr_kstar-option = 'EQ'.
        lr_kstar-sign = 'I'.
    
        "DIP机器
        lr_kstar-low = '0000600100'.           "成本要素
        APPEND lr_kstar.
        "AV/JV机器
        lr_kstar-low = '0000600110'.
        APPEND lr_kstar.
        "辅料耗锡
        lr_kstar-low = '0000600130'.
        APPEND lr_kstar.
        "跳线
        lr_kstar-low = '0000600140'.
        APPEND lr_kstar.
        "DIP人工
        lr_kstar-low = '0000600210'.
        APPEND lr_kstar.
    
        "成型人工
        lr_kstar-low = '0000600220'.
        APPEND lr_kstar.
    
        lr_objnr-option = 'EQ'.
        lr_objnr-sign = 'I'.
        LOOP AT gt_objnr.
          lr_objnr-low = gt_objnr-objnr.
          APPEND lr_objnr.
        ENDLOOP.
    
    *实际成本
        SELECT * INTO CORRESPONDING FIELDS OF TABLE i_coss
          FROM coss
          WHERE objnr IN lr_objnr
            AND kstar IN lr_kstar                     "成本要素
            AND wrttp = '04'.                         "实际成本消耗
    *分离成本
        lr_uspob-option = 'EQ'.
        lr_uspob-sign = 'I'.
    
        LOOP AT i_coss.
          gt_coss-objnr = i_coss-objnr.
          gt_coss-gjahr = i_coss-gjahr.               "年度
          gt_coss-meinh = i_coss-meinh.               "单位
    
          gt_coss-uspob = i_coss-uspob.               "初始对象号
          lr_uspob-low  = i_coss-uspob.               "用于计算计划作业价格的对象号
    
          CASE i_coss-kstar.
            WHEN  '0000600100'.
    *实际机器制造费用-总
              gt_coss-withdrawn_01 = i_coss-wkg001 + i_coss-wkg002 + i_coss-wkg003 +
                     i_coss-wkg004 + i_coss-wkg005 + i_coss-wkg006 +
                     i_coss-wkg007 + i_coss-wkg008 + i_coss-wkg009 +
                     i_coss-wkg010 + i_coss-wkg011 + i_coss-wkg012 +
                     i_coss-wkg013 + i_coss-wkg014 + i_coss-wkg015 +
                     i_coss-wkg016 .
    
            WHEN  '0000600110'.
    *AV/JV机器-总
              gt_coss-withdrawn_02 = i_coss-wkg001 + i_coss-wkg002 + i_coss-wkg003 +
                     i_coss-wkg004 + i_coss-wkg005 + i_coss-wkg006 +
                     i_coss-wkg007 + i_coss-wkg008 + i_coss-wkg009 +
                     i_coss-wkg010 + i_coss-wkg011 + i_coss-wkg012 +
                     i_coss-wkg013 + i_coss-wkg014 + i_coss-wkg015 +
                     i_coss-wkg016 .
    
            WHEN  '0000600130'.
    *辅料耗锡-总
              gt_coss-withdrawn_03 = i_coss-wkg001 + i_coss-wkg002 + i_coss-wkg003 +
                     i_coss-wkg004 + i_coss-wkg005 + i_coss-wkg006 +
                     i_coss-wkg007 + i_coss-wkg008 + i_coss-wkg009 +
                     i_coss-wkg010 + i_coss-wkg011 + i_coss-wkg012 +
                     i_coss-wkg013 + i_coss-wkg014 + i_coss-wkg015 +
                     i_coss-wkg016 .
    
            WHEN  '0000600140'.
    *跳线-总
              gt_coss-withdrawn_04 = i_coss-wkg001 + i_coss-wkg002 + i_coss-wkg003 +
                     i_coss-wkg004 + i_coss-wkg005 + i_coss-wkg006 +
                     i_coss-wkg007 + i_coss-wkg008 + i_coss-wkg009 +
                     i_coss-wkg010 + i_coss-wkg011 + i_coss-wkg012 +
                     i_coss-wkg013 + i_coss-wkg014 + i_coss-wkg015 +
                     i_coss-wkg016 .
    
            WHEN  '0000600210'.
    *DIP人工-总
              gt_coss-withdrawn_05 = i_coss-wkg001 + i_coss-wkg002 + i_coss-wkg003 +
                     i_coss-wkg004 + i_coss-wkg005 + i_coss-wkg006 +
                     i_coss-wkg007 + i_coss-wkg008 + i_coss-wkg009 +
                     i_coss-wkg010 + i_coss-wkg011 + i_coss-wkg012 +
                     i_coss-wkg013 + i_coss-wkg014 + i_coss-wkg015 +
                     i_coss-wkg016 .
    
            WHEN '0000600220'.
    *成型人工-总
              gt_coss-withdrawn_06 = i_coss-wkg001 + i_coss-wkg002 + i_coss-wkg003 +
                     i_coss-wkg004 + i_coss-wkg005 + i_coss-wkg006 +
                     i_coss-wkg007 + i_coss-wkg008 + i_coss-wkg009 +
                     i_coss-wkg010 + i_coss-wkg011 + i_coss-wkg012 +
                     i_coss-wkg013 + i_coss-wkg014 + i_coss-wkg015 +
                     i_coss-wkg016 .
    
          ENDCASE.
          COLLECT gt_coss.
          COLLECT lr_uspob.
    
          CLEAR gt_coss.
        ENDLOOP.
        CLEAR lr_uspob. "清除表头
        CLEAR i_coss.
      ENDIF.
    
    *计算作业价格-----计算标准作业价格----table: cost
      SELECT objnr
             gjahr
             tkg001
             tkg002
             tkg003
             tkg004
             tkg005
             tkg006
             tkg007
             tkg008
             tkg009
             tkg010
             tkg011
             tkg012
             tke001 tke002 tke003 tke004 tke005 tke006 tke007 tke008 tke009 tke010 tke011 tke012
             INTO TABLE tkg FROM cost
             WHERE
    *         objnr in lr_uspob
    *               and
                   lednr = '00'   "控制对象的分类帐
                   AND wrttp = '01'.  "值类型
    
    *计算作业价格 * 工艺路线(工序)
      DATA: t_lar01,
            t_uspob_c(16) TYPE c,
            t_uspob(22) TYPE c,
            t_kstar LIKE coss-kstar,  "成本要素
            t_case(3) TYPE c,
            t_year(4) TYPE c,
            t_month TYPE char_02,
            t_field1(6) TYPE c,
            t_field(16) TYPE c,
            t_value TYPE P DECIMALS 4." s026-enwrt.               "xieyao 2009.09.07
    
      CONSTANTS: index TYPE i VALUE 7.
      DATA: i_index TYPE i,
            i_month TYPE i.
    
      DATA: lwa_gt_list LIKE LINE OF gt_list,
            lwa_i_coss LIKE LINE OF i_coss,
            lwa_i_tkg LIKE LINE OF i_tkg.
    
      FIELD-SYMBOLS: <fs1>,    "结构
                     <fs2>,    "字段
                     <fs3>,    "结构
                     <fs4>,    "字段
                     <fs5>,    "字段
                     <fs6>,    "字段
                     <fs_kostl>,
                     <f_one>,
                     <f_field>.
    
      LOOP AT gt_list INTO lwa_gt_list.
        t_year  = lwa_gt_list-year.
        t_month = lwa_gt_list-month .
        i_month = lwa_gt_list-month + 2.
    
        lwa_i_tkg-objnr = lwa_gt_list-objnr.            "1
        lwa_i_tkg-gjahr = lwa_gt_list-year.             "2
    
        READ TABLE routing_table ASSIGNING <fs1> WITH KEY plnnr = lwa_gt_list-plnnr   "标准工艺路线
                                                          vornr = lwa_gt_list-vornr.
        IF sy-subrc = 0.
          ASSIGN COMPONENT 'KOSTL' OF STRUCTURE <fs1> TO <fs_kostl>.
          "成本中心相关号-->不要作业编号
          CONCATENATE 'KL1000' <fs_kostl> INTO t_uspob_c.
    
          i_index = index.
          DO.
            ASSIGN COMPONENT i_index OF STRUCTURE <fs1> TO <fs2>.       "工艺路线-->作业类型如:MAC、LAB3
            IF sy-subrc <> 0.
              EXIT.
            ENDIF.
    
            CONCATENATE t_uspob_c <fs2> INTO t_uspob.                   "read的条件
            READ TABLE tkg ASSIGNING <fs3> WITH KEY objnr = t_uspob
                                                    gjahr = t_year.
            IF sy-subrc = 0.
              lwa_i_tkg-uspob = t_uspob.               "4
    
              ASSIGN COMPONENT i_month OF STRUCTURE <fs3> TO <fs4>.     "当月作业价格
              "定价单位
              CONCATENATE 'TKE0' t_month INTO t_field1.
              ASSIGN COMPONENT t_field1 OF STRUCTURE <fs3> TO <fs6>.
    
              i_index = i_index + 2.
              ASSIGN COMPONENT i_index OF STRUCTURE <fs1> TO <fs2>.     "工艺路线标准工时
              ASSIGN COMPONENT 'BMSCH' OF STRUCTURE <fs1> TO <fs5>.     "工艺路线基本单位
              IF <fs5> <> 0 AND <fs6> <> 0.
                t_value = <fs2> * <fs4> / <fs5> / <fs6> * 100.          "扩大100倍
              ELSE.
                t_value = 0.
              ENDIF.
    
              CONCATENATE 'LWA_I_TKG' '-WKG0' t_month INTO t_field.
              ASSIGN (t_field) TO <f_field>.
              <f_field> = t_value.                              "从列6/7/8……
    *collect cost.
              COLLECT lwa_i_tkg INTO i_tkg.
              CLEAR t_value.
    
              i_index = i_index + 1.
            ELSE.
              i_index = i_index + 3.
            ENDIF.
          ENDDO.
        ENDIF.
      ENDLOOP.
    
      LOOP AT i_tkg.
        gt_tkg-objnr = i_tkg-objnr.
        gt_tkg-gjahr = i_tkg-gjahr.               "年度
        gt_tkg-meinh = i_tkg-meinh.               "单位
    
        gt_tkg-uspob = i_tkg-uspob.               "初始对象号
        t_case = i_tkg-uspob+16(3).
        CASE t_case.
    
          WHEN  'MAC'.
    *标准机器制造费用-总
            gt_tkg-withdrawn_01 = i_tkg-wkg001 + i_tkg-wkg002 + i_tkg-wkg003 +
                   i_tkg-wkg004 + i_tkg-wkg005 + i_tkg-wkg006 +
                   i_tkg-wkg007 + i_tkg-wkg008 + i_tkg-wkg009 +
                   i_tkg-wkg010 + i_tkg-wkg011 + i_tkg-wkg012 +
                   i_tkg-wkg013 + i_tkg-wkg014 + i_tkg-wkg015 +
                   i_tkg-wkg016 .
    
          WHEN  'FAC'.
    *人工-总
            gt_tkg-withdrawn_02 = i_tkg-wkg001 + i_tkg-wkg002 + i_tkg-wkg003 +
                   i_tkg-wkg004 + i_tkg-wkg005 + i_tkg-wkg006 +
                   i_tkg-wkg007 + i_tkg-wkg008 + i_tkg-wkg009 +
                   i_tkg-wkg010 + i_tkg-wkg011 + i_tkg-wkg012 +
                   i_tkg-wkg013 + i_tkg-wkg014 + i_tkg-wkg015 +
                   i_tkg-wkg016 .
    
          WHEN  'LAB'.
    *人工-总
            gt_tkg-withdrawn_03 = i_tkg-wkg001 + i_tkg-wkg002 + i_tkg-wkg003 +
                   i_tkg-wkg004 + i_tkg-wkg005 + i_tkg-wkg006 +
                   i_tkg-wkg007 + i_tkg-wkg008 + i_tkg-wkg009 +
                   i_tkg-wkg010 + i_tkg-wkg011 + i_tkg-wkg012 +
                   i_tkg-wkg013 + i_tkg-wkg014 + i_tkg-wkg015 +
                   i_tkg-wkg016 .
    
        ENDCASE.
        COLLECT gt_tkg.
        CLEAR gt_tkg.
      ENDLOOP.
    
    ENDFORM.                    " select_data
    
    *&---------------------------------------------------------------------*
    *&      Form  append_gt_result
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM append_gt_result .
      DATA: i_index TYPE i,
            t_withcost_s_01 LIKE s026-enwrt,
            t_withcost_s_02 LIKE s026-enwrt,
            t_withcost_q_01 LIKE s026-enwrt,
            t_withcost_q_02 LIKE s026-enwrt.
    *data
      DATA: t_withcost_s LIKE s026-enwrt,
            t_withcost_q LIKE s026-enwrt.
      DATA: t_c_date LIKE sy-datum.
    
      FIELD-SYMBOLS: <fs>,
                     <fs_st>, "标准价格
                     <fs_pe>,
                     <fs_kb>,  "价格
                     <fs_kp>.  "条件定价单位
    *select options
      order_s_objects-components = 'X'.
      order_s_objects-header     = 'X'.
      order_s_objects-positions  = 'X'.
    
    *填充输出内表
      LOOP AT gt_list.
        gt_result-objnr = gt_list-objnr.
        gt_result-aufnr = gt_list-aufnr.
        gt_result-auart = gt_list-auart.
        gt_result-werks = gt_list-werks.
        gt_result-year = gt_list-year.
        gt_result-month = gt_list-month.
        gt_result-gmnga = gt_list-gmnga.
        gt_result-gmein = gt_list-gmein.
    
    *用于read的关键字---标准工艺路线
        gt_result-matnr = gt_list-matnr.
        gt_result-plnnr = gt_list-plnnr.
    
        COLLECT gt_result.
        CLEAR gt_list.
        CLEAR gt_result.
      ENDLOOP.
    
    
    *一统
      SORT gt_coss BY objnr gjahr.
      SORT gt_tkg BY objnr gjahr.
    
      CLEAR: t_withcost_s_01,
             t_withcost_s_02,
             t_withcost_q_01,
             t_withcost_q_02.
    
      LOOP AT gt_result ASSIGNING <fs_result>.
    *计算材料成本
    ***********************************************************************
        CALL FUNCTION 'BAPI_PRODORD_GET_DETAIL'
          EXPORTING
            number        = <fs_result>-aufnr
            order_objects = order_s_objects
          TABLES
            header        = order_t_header
            position      = order_t_item
            component     = order_t_component.
    
        READ TABLE order_t_header INDEX 1 INTO order_s_header.       "读取表头
    *    <fs_result>-gmnga = order_s_header-confirmed_quantity.       "取收到数量
        <fs_result>-gmein = order_s_header-unit.
    
        READ TABLE order_t_item INDEX 1 INTO order_s_item.
        <fs_result>-gmnga = order_s_item-delivered_quantity.       "取收到数量
    
        CONCATENATE <fs_result>-year <fs_result>-month '01' INTO t_c_date.
    
        LOOP AT order_t_component INTO order_s_component WHERE material <> order_s_header-material.
          "价格
          CALL FUNCTION 'ZXY_PURCHASE_DATE_READ'
            EXPORTING
              matnr     = order_s_component-material
              werks     = order_s_component-prod_plant
              budat     = t_c_date
            TABLES
              pur_table = tab_t_purchasing.
    
          IF sy-subrc = 0 AND tab_t_purchasing IS NOT INITIAL.
    
            READ TABLE tab_t_purchasing INDEX 1 ASSIGNING <fs> .
            "实际消耗的数量 * 标准价格 / 价格单位
            ASSIGN COMPONENT 'KBETR' OF STRUCTURE <fs> TO <fs_kb>.
            ASSIGN COMPONENT 'KPEIN' OF STRUCTURE <fs> TO <fs_kp>.
            IF <fs_kp> <> 0.
              t_withcost_s = t_withcost_s + order_s_component-withdrawn_quantity * <fs_kb> / <fs_kp>.    "实际材料成本
            ELSE.
              t_withcost_s = 0.
            ENDIF.
    
            "计划消耗的数量 * 标准价格 / 价格单位
            ASSIGN COMPONENT 'STPRS' OF STRUCTURE <fs> TO <fs_st>.
            ASSIGN COMPONENT 'PEINH' OF STRUCTURE <fs> TO <fs_pe>.
            IF <fs_pe> <> 0.
              t_withcost_q = t_withcost_q + order_s_component-req_quan * <fs_st> / <fs_pe>.              "标准材料成本
            ELSE.
              t_withcost_q = 0.
            ENDIF.
          ENDIF.
          CLEAR tab_t_purchasing.
        ENDLOOP.
    
        "实际材料成本
        <fs_result>-withcost_s_03 = t_withcost_s.
        "标准材料成本
        <fs_result>-withcost_q_03 = t_withcost_q.
    
        CLEAR:       t_c_date,
                     t_withcost_s,
                     t_withcost_q,
                     order_t_header,
                     order_t_item,
                     order_t_component.
    
    *计算实际成本
        READ TABLE gt_coss WITH KEY objnr = <fs_result>-objnr
                                  gjahr = <fs_result>-year.
        IF sy-subrc = 0.
          i_index = sy-tabix.
          LOOP AT gt_coss FROM i_index WHERE objnr = <fs_result>-objnr
                                            AND gjahr = <fs_result>-year.
            "实际制造费用
            t_withcost_s_01 = t_withcost_s_01 + :
                              gt_coss-withdrawn_03 , gt_coss-withdrawn_04 ,
                              gt_coss-withdrawn_01 , gt_coss-withdrawn_02.
            "实际人工成本
            t_withcost_s_02 = t_withcost_s_02 + :
                              gt_coss-withdrawn_05 , gt_coss-withdrawn_06.
    
          ENDLOOP.
          <fs_result>-withcost_s_01 = t_withcost_s_01.
          <fs_result>-withcost_s_02 = t_withcost_s_02.
        ENDIF.
    
    *计算标准成本
        READ TABLE gt_tkg WITH KEY objnr = <fs_result>-objnr
                                  gjahr = <fs_result>-year.
        IF sy-subrc = 0.
          i_index = sy-tabix.
          LOOP AT gt_tkg FROM i_index WHERE objnr = <fs_result>-objnr
                                            AND gjahr = <fs_result>-year.
            "标准制造费用
            t_withcost_q_01 = t_withcost_q_01 + : gt_tkg-withdrawn_02 ,
                              gt_tkg-withdrawn_01 .
            "标准人工成本
            t_withcost_q_02 = t_withcost_q_02 + :
                              gt_tkg-withdrawn_03 .
    
    
          ENDLOOP.
          <fs_result>-withcost_q_01 = t_withcost_q_01 * <fs_result>-gmnga / 100.    "xieyao 2009.09.07
          <fs_result>-withcost_q_02 = t_withcost_q_02 * <fs_result>-gmnga / 100.    "xieyao 2009.09.07
        ENDIF.
    
        CLEAR: t_withcost_s_01,
               t_withcost_s_02,
               t_withcost_q_01,
               t_withcost_q_02.
    
    *去掉前导零
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
          EXPORTING
            input  = <fs_result>-aufnr
          IMPORTING
            output = <fs_result>-aufnr.
    
     
    
      ENDLOOP.
    
    
    ENDFORM.                    " append_gt_result
    ***********************************************************************
    * END-OF-SELECTION
    ***********************************************************************
    END-OF-SELECTION.
    *&---------------------------------------------------------------------*
    *&      Form  alv_output
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM alv_output .
    *设置显示格式
      PERFORM f_fieldcat_init.
    *
      PERFORM event_top_of_page TABLES gt_event.
    *ALV显示报表
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program      = g_repid
          i_callback_user_command = 'USER_COMMAND'
          it_fieldcat             = gt_fieldcat[]
          it_sort                 = gt_sort[]
          it_events               = gt_event[]
        TABLES
          t_outtab                = gt_result
        EXCEPTIONS
          program_error           = 1
          OTHERS                  = 2.
    ENDFORM.                    " alv_output
    
    ************************************************************************
    *  设置表输出表头事件
    ************************************************************************
    FORM event_top_of_page  TABLES   ex_gt_event TYPE slis_t_event.
      REFRESH ex_gt_event.
      CLEAR ex_gt_event.
      ex_gt_event-name = slis_ev_top_of_page.
      ex_gt_event-form = 'WRITE_TOP_OF_PAGE'.
      APPEND ex_gt_event.
    ENDFORM.                    "event_top_of_page
    
    *************************************************************************
    **  设置明细表表头                                             *
    *************************************************************************
    FORM write_top_of_page.
      DATA: wa_hline TYPE slis_listheader.
    
      REFRESH gt_head.
      CLEAR: wa_hline.
      DATA:  l_count TYPE i.
    
      wa_hline-typ = 'H'.
      wa_hline-info = '成品实际/标准成本分析'.
      APPEND wa_hline TO gt_head.
    
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = gt_head.
    ENDFORM.                    "write_top_of_page
    
    ************************************************************************
    * 双击
    ************************************************************************
    FORM user_command USING r_ucomm LIKE sy-ucomm
                      rs_selfield TYPE slis_selfield.
      READ TABLE gt_result INDEX rs_selfield-tabindex.
      CHECK sy-subrc = 0.
      CASE r_ucomm.
        WHEN '&IC1'.                       "doubleclick
          CASE rs_selfield-sel_tab_field.
            WHEN '1-AUFNR'.
              SET PARAMETER ID 'ANR' FIELD gt_result-aufnr .
              CALL TRANSACTION  'CO03'  AND  SKIP  FIRST  SCREEN.
              CLEAR r_ucomm.
          ENDCASE.
      ENDCASE.
    ENDFORM.                    "USER_COMMAND_SUM
    
    ***********************************************************************
    *设置ALV输出报表的显示字段、排序字段及其相关属性                      *
    ***********************************************************************
    FORM f_fieldcat_init .
      DATA: wa_fieldcat TYPE slis_fieldcat_alv,
            wa_sort TYPE slis_sortinfo_alv.
    
    *显示字段
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname =  'AUFNR'.
      wa_fieldcat-seltext_s =  '工单号'.
      wa_fieldcat-key       =  'X'.
      wa_fieldcat-fix_column = 'X'.
      wa_fieldcat-outputlen = '12'.
      APPEND wa_fieldcat TO gt_fieldcat.
    
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname =  'YEAR'.
      wa_fieldcat-seltext_s =  '年度'.
      wa_fieldcat-key       =  'X'.
      wa_fieldcat-fix_column = 'X'.
      wa_fieldcat-outputlen = '4'.
      APPEND wa_fieldcat TO gt_fieldcat.
    
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname =  'MONTH'.
      wa_fieldcat-seltext_s =  '期间'.
      wa_fieldcat-key       =  'X'.
      wa_fieldcat-fix_column = 'X'.
      wa_fieldcat-outputlen = '4'.
      APPEND wa_fieldcat TO gt_fieldcat.
    
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname =  'AUART'.
      wa_fieldcat-seltext_s =  '订单类型'.
      wa_fieldcat-key       =  'X'.
      wa_fieldcat-fix_column = 'X'.
      wa_fieldcat-outputlen = '8'.
      APPEND wa_fieldcat TO gt_fieldcat.
    
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname =  'WERKS'.
      wa_fieldcat-seltext_s =  '工厂'.
      wa_fieldcat-key       =  'X'.
      wa_fieldcat-fix_column = 'X'.
      wa_fieldcat-outputlen = '10'.
      APPEND wa_fieldcat TO gt_fieldcat.
    
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname =  'MATNR'.
      wa_fieldcat-seltext_s =  '成品物料'.
      wa_fieldcat-fix_column = 'X'.
      wa_fieldcat-outputlen = '10'.
      APPEND wa_fieldcat TO gt_fieldcat.
    
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname =  'GMNGA'.
      wa_fieldcat-seltext_l =  '工单收货数量'.
      wa_fieldcat-fix_column = 'X'.
      APPEND wa_fieldcat TO gt_fieldcat.
    
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname =  'GMEIN'.
      wa_fieldcat-seltext_l =  '单位'.
      wa_fieldcat-outputlen = '3'.
      APPEND wa_fieldcat TO gt_fieldcat.
    
    *  clear wa_fieldcat.
    *  wa_fieldcat-fieldname =  'ISM01'.
    *  wa_fieldcat-seltext_l =  '实际机器工时'.
    *  append wa_fieldcat to gt_fieldcat.
    *
    *  clear wa_fieldcat.
    *  wa_fieldcat-fieldname =  'ISM02'.
    *  wa_fieldcat-seltext_l =  '实际人工工时'.
    *  append wa_fieldcat to gt_fieldcat.
    *
    *  clear wa_fieldcat.
    *  wa_fieldcat-fieldname =  'ILE01'.
    *  wa_fieldcat-seltext_l =  '单位'.
    *  wa_fieldcat-outputlen = '3'.
    *  append wa_fieldcat to gt_fieldcat.
    *
    *  clear wa_fieldcat.
    *  wa_fieldcat-fieldname =  'ISM01_Q'.
    *  wa_fieldcat-seltext_l =  '标准机器工时'.
    *  append wa_fieldcat to gt_fieldcat.
    *
    *  clear wa_fieldcat.
    *  wa_fieldcat-fieldname =  'ISM02_Q'.
    *  wa_fieldcat-seltext_l =  '标准人工工时'.
    *  append wa_fieldcat to gt_fieldcat.
    *
    *  clear wa_fieldcat.
    *  wa_fieldcat-fieldname =  'ILE02'.
    *  wa_fieldcat-seltext_l =  '单位'.
    *  wa_fieldcat-outputlen = '3'.
    *  append wa_fieldcat to gt_fieldcat.
    
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname =  'WITHCOST_S_01'.
      wa_fieldcat-seltext_l =  '实际制造成本'.
      wa_fieldcat-emphasize = 'C500'.
      APPEND wa_fieldcat TO gt_fieldcat.
    
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname =  'WITHCOST_S_02'.
      wa_fieldcat-seltext_l =  '实际人工成本'.
      wa_fieldcat-emphasize = 'C500'.
      APPEND wa_fieldcat TO gt_fieldcat.
    
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname =  'WITHCOST_S_03'.
      wa_fieldcat-seltext_l =  '实际材料成本'.
      wa_fieldcat-emphasize = 'C500'.
      APPEND wa_fieldcat TO gt_fieldcat.
    
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname =  'WITHCOST_Q_01'.
      wa_fieldcat-seltext_l =  '标准制造成本'.
      wa_fieldcat-emphasize = 'C701'.
      APPEND wa_fieldcat TO gt_fieldcat.
    
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname =  'WITHCOST_Q_02'.
      wa_fieldcat-seltext_l =  '标准人工成本'.
      wa_fieldcat-emphasize = 'C701'.
      APPEND wa_fieldcat TO gt_fieldcat.
    
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname =  'WITHCOST_Q_03'.
      wa_fieldcat-seltext_l =  '标准材料成本'.
      wa_fieldcat-emphasize = 'C701'.
      APPEND wa_fieldcat TO gt_fieldcat.
    
    *  clear wa_fieldcat.
    *  wa_fieldcat-fieldname =  'WITH_EF_M'.
    *  wa_fieldcat-seltext_l =  '机器生产效率'.
    *  append wa_fieldcat to gt_fieldcat.
    *
    *  clear wa_fieldcat.
    *  wa_fieldcat-fieldname =  'WITH_EF_L'.
    *  wa_fieldcat-seltext_l =  '人工生产效率'.
    *  append wa_fieldcat to gt_fieldcat.
    ENDFORM.                    "f_fieldcat_init
    本人常年接收SAP运维和远程项目,ECC,S/4HANA,CRM,WDA. 远程人天可谈,终身售后,有活请联系V信:18925782767(问问题免费,欢迎交流!) !!请关注本人技术分享公众号:SAP翔子(可扫头像二维码) 每天分享新知识,博客文章也会陆续整理并迁移至公众号,与您一起共同学习
  • 相关阅读:
    jQuery自学笔记(四):jQuery DOM节点操作
    jQuery自学笔记(三):jQuery动画效果
    jQuery自学笔记(二):jQuery选择器
    面试记录与复盘总结
    wh-研发功能复盘
    st项目-要素标记功能的实现以及经验总结
    ST项目经验总结2
    S台项目记录-1
    统计模型项目开发经验汇总
    开发规范
  • 原文地址:https://www.cnblogs.com/rainysblog/p/14986871.html
Copyright © 2020-2023  润新知