SAP-ABAP 生产订单差异明细表

&---------------------------------------------------------------------
*& Report ZCOPP007
&---------------------------------------------------------------------

REPORT zcorp007 MESSAGE-ID 00.

INCLUDE zcorp007_top.
INCLUDE zcorp007_sel.
INCLUDE zcorp007_frm.

START-OF-SELECTION.

AUTHORITY-CHECK OBJECT ‘F_BKPF_BUK’ ID ‘BUKRS’ FIELD p_bukrs
ID ‘ACTVT’ DUMMY.
IF sy-subrc <> 0.
MESSAGE e208 WITH ‘没有公司代码权限’.
ENDIF.

"取自建表数据
PERFORM frm_get_data.

**显示数据
PERFORM frm_alv_data.

END-OF-SELECTION.


&---------------------------------------------------------------------
*& 包含 ZCOPP007_TOP
&---------------------------------------------------------------------

------------------------------------------------------------

  • 数据声明 - 开始
    ------------------------------------------------------------

------------------------------------------------------------

  • DESC:INCLUDES文件 *
    ------------------------------------------------------------
    *INCLUDE .

------------------------------------------------------------

  • DESC: 表/ 结构 / 视图的声明 *
    ------------------------------------------------------------

TABLES: sscrfields, bkpf, aufk, afpo.

------------------------------------------------------------

  • DESC: 定义所需要的 TYPES *
    ------------------------------------------------------------
    *TYPE-POOLS: slis.
    TYPES: BEGIN OF ty_out,
    bukrs TYPE t001k-bukrs, "公司代码
    dwerk TYPE afpo-dwerk, "生产工厂
    bdatj TYPE ckmlprkeph-bdatj, "会计年度
    poper TYPE ckmlprkeph-poper, "过账期间
    aufnr TYPE afpo-aufnr, "生产订单
    rkdat TYPE jcds-udate, "入库日期
    wcdat TYPE jcds-udate, "完成日期
    txt30 TYPE tj02t-txt30, "订单状态
    matnr TYPE afpo-matnr, "物料编码
    maktx TYPE makt-maktx, "物料编码物料描述
    psmng TYPE afpo-psmng, "订单数量
    wemng TYPE afpo-wemng, "实际数量
    meins TYPE afpo-meins, "基本计量单位
    zprono TYPE aufk-zprono, "项目号
    kdauf TYPE aufk-kdauf, "销售订单
    kdpos TYPE aufk-kdpos, "销售订单行项目
    plnnr TYPE afko-plnnr, "基本计量单位

     bzclzj   TYPE  ckmlprkeph-kst001,    "材料(标准): 材料总计(原材料+半成品+成品)
     sjclzj   TYPE  ckmlprkeph-kst001,    "材料(实际): 材料总计(原材料+半成品+成品)
     cyclzj   TYPE  ckmlprkeph-kst001,    "材料(差异)
     bzycl    TYPE  ckmlprkeph-kst001,    "原材料(标准)
     sjycl    TYPE  ckmlprkeph-kst001,    "原材料(实际)
     cyycl    TYPE  ckmlprkeph-kst001,    "原材料(差异)
     bzbcp    TYPE  ckmlprkeph-kst003,    "半成品(标准)
     sjbcp    TYPE  ckmlprkeph-kst003,    "半成品(实际)
     cybcp    TYPE  ckmlprkeph-kst003,    "半成品(差异)
     bzccp    TYPE  ckmlprkeph-kst005,    "产成品(标准)
     sjccp    TYPE  ckmlprkeph-kst005,    "产成品(实际)
     cyccp    TYPE  ckmlprkeph-kst005,    "产成品(差异)
     bzwwfccl TYPE  ckmlprkeph-kst007,    "委外发出材料(标准)
     sjwwfccl TYPE  ckmlprkeph-kst007,    "委外发出材料(实际)
     cywwfccl TYPE  ckmlprkeph-kst007,    "委外发出材料(差异)
     bzwwjgf  TYPE  ckmlprkeph-kst009,    "委外加工费(标准)
     sjwwjgf  TYPE  ckmlprkeph-kst009,    "委外加工费(实际)
     cywwjgf  TYPE  ckmlprkeph-kst009,    "委外加工费(差异)
     bzwwjz   TYPE  ckmlprkeph-kst011,    "委外-结转(标准)
     sjwwjz   TYPE  ckmlprkeph-kst011,    "委外-结转(实际)
     cywwjz   TYPE  ckmlprkeph-kst011,    "委外-结转(差异)
     bzgxwxfy TYPE  ckmlprkeph-kst019,    "工序外协费用(标准)
     sjgxwxfy TYPE  ckmlprkeph-kst019,    "工序外协费用(实际)
     cygxwxfy TYPE  ckmlprkeph-kst019,    "工序外协费用(差异)
     bzrgfy   TYPE  ckmlprkeph-kst013,    "人工费用(标准)
     sjrgfy   TYPE  ckmlprkeph-kst013,    "人工费用(实际)
     cyrgfy   TYPE  ckmlprkeph-kst013,    "人工费用差异
     bzrggs   TYPE  afvv-vgw01,   "人工工时(标准)
     sjrggs   TYPE  afvv-ism01,   "人工工时(实际)
     cyrggs   TYPE  afvv-vgw01,   "人工工时差异
     bzrgfl   TYPE  ckmlprkeph-kst013,    "人工费率(标准)
     sjrgfl   TYPE  ckmlprkeph-kst013,    "人工费率(实际)
     cyrgfl   TYPE  ckmlprkeph-kst013,    "人工费率差异
     bzjqgsfy TYPE  ckmlprkeph-kst015,    "机器工时费用(标准)
     sjjqgsfy TYPE  ckmlprkeph-kst015,    "机器工时费用(实际)
     cyjqgsfy TYPE  ckmlprkeph-kst015,    "机器工时费用(差异)
     bzjqgs   TYPE  afvv-vgw02,   "机器工时(标准)
     sjjqgs   TYPE  afvv-ism02,   "机器工时(实际)
     cyjqgs   TYPE  afvv-vgw02,   "机器工时差异
     bzjqgsfl TYPE  ckmlprkeph-kst015,    "机器工时费率(标准)
     sjjqgsfl TYPE  ckmlprkeph-kst015,    "机器工时费率(实际)
     cyjqgsfl TYPE  ckmlprkeph-kst015,    "机器工时费率(差异)
     bzzzgsfy TYPE  ckmlprkeph-kst017,    "制造工时费用(标准)
     sjzzgsfy TYPE  ckmlprkeph-kst017,    "制造工时费用(实际)
     cyzzgsfy TYPE  ckmlprkeph-kst017,    "制造工时费用(差异)
     bzzzgs   TYPE  afvv-vgw03,   "制造工时(标准)
     sjzzgs   TYPE  afvv-ism03,   "制造工时(实际)
     cyzzgs   TYPE  afvv-vgw03,   "制造工时(差异)
     bzzzgsfl TYPE  ckmlprkeph-kst017,    "制造工时费用费率(标准)
     sjzzgsfl TYPE  ckmlprkeph-kst017,    "制造工时费用费率(实际)
     cyzzgsfl TYPE  ckmlprkeph-kst017,    "制造工时费用费率(差异)
    

    END OF ty_out.
    ------------------------------------------------------------

  • DESC:定义所需要的内表 / 结构 *
    ------------------------------------------------------------
    DATA: gt_out TYPE TABLE OF ty_out,
    wa_out LIKE LINE OF gt_out.

**–ALV用
DATA: gt_events TYPE slis_t_event,

  •  gw_reprep   TYPE  slis_reprep_id,
    gw_layout   TYPE  lvc_s_layo,
    gw_settings TYPE  lvc_s_glay,
    wa_fieldcat TYPE  lvc_s_fcat,
    gt_fieldcat TYPE  lvc_t_fcat,
    gt_drop     TYPE  lvc_t_drop,
    wa_drop     TYPE  lvc_s_drop,
    wa_sort     TYPE  slis_sortinfo_alv,
    gt_sort     TYPE  slis_t_sortinfo_alv,
    gt_header   TYPE slis_t_listheader,
    wa_header   TYPE slis_listheader.
    

------------------------------------------------------------

  • DESC: 定义变/常量 *
    ------------------------------------------------------------
    DATA: gv_len TYPE i,
    gv_flag TYPE char1.

*CONSTANTS: c_zgxc_hkont TYPE hkont VALUE ‘6601000001’,

  •       c_lwcb_hkont TYPE hkont VALUE '6601000002',
    
  •       c_gjj_hkont  TYPE hkont VALUE '6601000017',
    
  •       c_olda_hkont TYPE hkont VALUE '6601000025',
    
  •       c_medi_hkont TYPE hkont VALUE '6601000026',
    
  •       c_emij_hkont TYPE hkont VALUE '6601000027',
    
  •       c_mate_hkont TYPE hkont VALUE '6601000028',
    
  •       c_unem_hkont TYPE hkont VALUE '6601000029'.
    

------------------------------------------------------------

  • DESC: 定义屏幕号变量 *
    ------------------------------------------------------------
    *DATA: "sub(3) TYPE c VALUE ‘100’, "初始屏幕的屏幕号变量
  •  subrc_main(3) TYPE c VALUE '100',   "显示平台初始屏幕下面的屏幕号变量
    
  •  sub_target(3) TYPE c VALUE '221'.    "下半屏幕下得屏幕号变量
    

------------------------------------------------------------

  • DESC: 定义表条目变量和表控制变量 *
    ------------------------------------------------------------
    *CONTROLS: triptab TYPE TABSTRIP.
    --------------------------------------------------------------------
  • DESC: 定义类 *
    --------------------------------------------------------------------
    ------------------------------------------------------------
  • 数据定义 - 结束 *
    ------------------------------------------------------------

&---------------------------------------------------------------------
*& 包含 ZCOPP007_SEL
&---------------------------------------------------------------------
------------------------------------------------------------

  • DESC: 定义选择屏幕 —开始 *
    ------------------------------------------------------------
    SELECTION-SCREEN: FUNCTION KEY 1. "激活

SELECTION-SCREEN: BEGIN OF BLOCK blk0 WITH FRAME TITLE TEXT-001.
PARAMETERS: p_bukrs TYPE bukrs OBLIGATORY DEFAULT ‘1100’. " File location Input
SELECT-OPTIONS: s_gjahr FOR bkpf-gjahr,
s_monat FOR bkpf-monat,
s_aufnr FOR aufk-aufnr,
s_matnr FOR afpo-matnr,
s_kdauf FOR aufk-kdauf,
s_kdpos FOR aufk-kdpos,
s_zprono FOR aufk-zprono.
SELECTION-SCREEN END OF BLOCK blk0.

------------------------------------------------------------

  • DESC: 定义选择屏幕 —结束 *
    ------------------------------------------------------------
    INITIALIZATION.

&---------------------------------------------------------------------
*& 包含 ZCOPP007_FRM
&---------------------------------------------------------------------
&---------------------------------------------------------------------
*& Form frm_alv_data
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM frm_alv_data .
REFRESH: gt_fieldcat.
CLEAR: gw_layout,gw_settings.
gw_layout-cwidth_opt = ‘X’.
gw_layout-zebra = ‘X’.

  • gw_layout-box_fname = ‘SEL’.

  • gw_layout-stylefname = ‘EDITMARK’.

  • gw_settings-edt_cll_cb = ‘X’.

PERFORM frm_fill_dieldcat.

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
EXPORTING

  • I_INTERFACE_CHECK  = ' '
    
  • I_BYPASSING_BUFFER =
    
  • I_BUFFER_ACTIVE    =
    i_callback_program = sy-repid
    
  • i_callback_pf_status_set = 'SET_PF_STATUS'
    
  • i_callback_user_command  = 'USER_COMMAND'
    
  • I_CALLBACK_TOP_OF_PAGE   = ' '
    
  • I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
    
  • I_CALLBACK_HTML_END_OF_LIST       = ' '
    
  • I_STRUCTURE_NAME   =
    
  • I_BACKGROUND_ID    = ' '
    
  • i_grid_title       = gv_title
    
  • i_grid_settings    = gw_settings
    is_layout_lvc      = gw_layout
    it_fieldcat_lvc    = gt_fieldcat
    
  • it_excluding       = gt_excluding
    
  • IT_SPECIAL_GROUPS_LVC    =
    
  • IT_SORT_LVC        =
    
  • IT_FILTER_LVC      =
    
  • IT_HYPERLINK       =
    
  • IS_SEL_HIDE        =
    i_default          = 'X'
    i_save             = 'A'
    
  • IS_VARIANT         =
    
  • IT_EVENTS          =
    
  • IT_EVENT_EXIT      =
    
  • IS_PRINT_LVC       =
    
  • IS_REPREP_ID_LVC   =
    
  • I_SCREEN_START_COLUMN    = 0
    
  • I_SCREEN_START_LINE      = 0
    
  • I_SCREEN_END_COLUMN      = 0
    
  • I_SCREEN_END_LINE  = 0
    
  • I_HTML_HEIGHT_TOP  =
    
  • I_HTML_HEIGHT_END  =
    
  • IT_ALV_GRAPHICS    =
    
  • IT_EXCEPT_QINFO_LVC      =
    
  • IR_SALV_FULLSCREEN_ADAPTER        =
    
  • IMPORTING
  • E_EXIT_CAUSED_BY_CALLER  =
    
  • ES_EXIT_CAUSED_BY_USER   =
    
    TABLES
    t_outtab = gt_out
    EXCEPTIONS
    program_error = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
  • Implement suitable error handling here
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

ENDFORM.
*FORM set_pf_status USING rt_extab TYPE slis_t_extab.
*

  • REFRESH: rt_extab.
  • SET PF-STATUS ‘STANDARD’ EXCLUDING rt_extab.

*ENDFORM.
*FORM user_command USING r_ucomm LIKE sy-ucomm

  •                     rs_selfield TYPE slis_selfield.
    
  • CASE r_ucomm.
  • WHEN OTHERS.
  • ENDCASE.
  • rs_selfield-refresh = ‘X’.
  • rs_selfield-row_stable = ‘X’.
  • rs_selfield-col_stable = ‘X’.
    *ENDFORM.
    &---------------------------------------------------------------------
    *& Form frm_fill_dieldcat
    &---------------------------------------------------------------------
    *& text
    &---------------------------------------------------------------------
    *& --> p1 text
    *& <-- p2 text
    &---------------------------------------------------------------------
    FORM frm_fill_dieldcat .
    DEFINE def_fcat.
    CLEAR: wa_fieldcat.
    wa_fieldcat-fieldname = &1.
    wa_fieldcat-coltext = &2.
    wa_fieldcat-ref_field = &3.
    wa_fieldcat-ref_table = &4.
  • wa_fieldcat-edit = &5.
  • wa_fieldcat-checkbox = &6.
  • wa_fieldcat-no_zero = &7.
    APPEND wa_fieldcat TO gt_fieldcat.
    END-OF-DEFINITION.

def_fcat ‘BUKRS’ ‘公司代码’ ‘’ ‘’.
def_fcat ‘DWERK’ ‘生产工厂’ ‘’ ‘’.
def_fcat ‘BDATJ’ ‘会计年度’ ‘’ ‘’.
def_fcat ‘POPER’ ‘过账期间’ ‘’ ‘’.
def_fcat ‘AUFNR’ ‘生产订单’ ‘AUFNR’ ‘AFPO’.
def_fcat ‘RKDAT’ ‘入库日期’ ‘’ ‘’.
def_fcat ‘WCDAT’ ‘完成日期’ ‘’ ‘’.
def_fcat ‘TXT30’ ‘订单状态’ ‘’ ‘’.
def_fcat ‘MATNR’ ‘物料编码’ ‘MATNR’ ‘AFPO’.
def_fcat ‘MAKTX’ ‘物料编码物料描述’ ‘’ ‘’.
def_fcat ‘PSMNG’ ‘订单数量’ ‘’ ‘’.
def_fcat ‘WEMNG’ ‘实际数量’ ‘’ ‘’.
def_fcat ‘MEINS’ ‘基本计量单位’ ‘’ ‘’.
def_fcat ‘ZPRONO’ ‘项目号’ ‘’ ‘’.
def_fcat ‘KDAUF’ ‘销售订单’ ‘KDAUF’ ‘AUFK’.
def_fcat ‘KDPOS’ ‘销售订单行项目’ ‘’ ‘’.
def_fcat ‘BZCLZJ’ ‘材料总计(标准)’ ‘’ ‘’.
def_fcat ‘SJCLZJ’ ‘材料总计(实际)’ ‘’ ‘’.
def_fcat ‘CYCLZJ’ ‘材料总计(差异)’ ‘’ ‘’.
def_fcat ‘BZYCL’ ‘原材料(标准)’ ‘’ ‘’.
def_fcat ‘SJYCL’ ‘原材料(实际)’ ‘’ ‘’.
def_fcat ‘CYYCL’ ‘原材料(差异)’ ‘’ ‘’.
def_fcat ‘BZBCP’ ‘半成品(标准)’ ‘’ ‘’.
def_fcat ‘SJBCP’ ‘半成品(实际)’ ‘’ ‘’.
def_fcat ‘CYBCP’ ‘半成品(差异)’ ‘’ ‘’.
def_fcat ‘BZCCP’ ‘产成品(标准)’ ‘’ ‘’.
def_fcat ‘SJCCP’ ‘产成品(实际)’ ‘’ ‘’.
def_fcat ‘CYCCP’ ‘产成品(差异)’ ‘’ ‘’.
def_fcat ‘BZWWFCCL’ ‘委外发出材料(标准)’ ‘’ ‘’.
def_fcat ‘SJWWFCCL’ ‘委外发出材料(实际)’ ‘’ ‘’.
def_fcat ‘CYWWFCCL’ ‘委外发出材料(差异)’ ‘’ ‘’.
def_fcat ‘BZWWJGF’ ‘委外加工费(标准)’ ‘’ ‘’.
def_fcat ‘SJWWJGF’ ‘委外加工费(实际)’ ‘’ ‘’.
def_fcat ‘CYWWJGF’ ‘委外加工费(差异)’ ‘’ ‘’.
def_fcat ‘BZWWJZ’ ‘委外-结转(标准)’ ‘’ ‘’.
def_fcat ‘SJWWJZ’ ‘委外-结转(实际)’ ‘’ ‘’.
def_fcat ‘CYWWJZ’ ‘委外-结转(差异)’ ‘’ ‘’.
def_fcat ‘BZGXWXFY’ ‘工序外协费用(标准)’ ‘’ ‘’.
def_fcat ‘SJGXWXFY’ ‘工序外协费用(实际)’ ‘’ ‘’.
def_fcat ‘CYGXWXFY’ ‘工序外协费用(差异)’ ‘’ ‘’.
def_fcat ‘BZRGFY’ ‘人工费用(标准)’ ‘’ ‘’.
def_fcat ‘SJRGFY’ ‘人工费用(实际)’ ‘’ ‘’.
def_fcat ‘CYRGFY’ ‘人工费用差异’ ‘’ ‘’.
def_fcat ‘BZRGGS’ ‘人工工时(标准)’ ‘’ ‘’.
def_fcat ‘SJRGGS’ ‘人工工时(实际)’ ‘’ ‘’.
def_fcat ‘CYRGGS’ ‘人工工时差异’ ‘’ ‘’.
def_fcat ‘BZRGFL’ ‘人工费率(标准)’ ‘’ ‘’.
def_fcat ‘SJRGFL’ ‘人工费率(实际)’ ‘’ ‘’.
def_fcat ‘CYRGFL’ ‘人工费率差异’ ‘’ ‘’.
def_fcat ‘BZJQGSFY’ ‘机器工时费用(标准)’ ‘’ ‘’.
def_fcat ‘SJJQGSFY’ ‘机器工时费用(实际)’ ‘’ ‘’.
def_fcat ‘CYJQGSFY’ ‘机器工时费用(差异)’ ‘’ ‘’.
def_fcat ‘BZJQGS’ ‘机器工时(标准)’ ‘’ ‘’.
def_fcat ‘SJJQGS’ ‘机器工时(实际)’ ‘’ ‘’.
def_fcat ‘CYJQGS’ ‘机器工时(差异)’ ‘’ ‘’.
def_fcat ‘BZJQGSFL’ ‘机器工时费率(标准)’ ‘’ ‘’.
def_fcat ‘SJJQGSFL’ ‘机器工时费率(实际)’ ‘’ ‘’.
def_fcat ‘CYJQGSFL’ ‘机器工时费率(差异)’ ‘’ ‘’.
def_fcat ‘BZZZGSFY’ ‘制造工时费用(标准)’ ‘’ ‘’.
def_fcat ‘SJZZGSFY’ ‘制造工时费用(实际)’ ‘’ ‘’.
def_fcat ‘CYZZGSFY’ ‘制造工时费用(差异)’ ‘’ ‘’.
def_fcat ‘BZZZGS’ ‘制造工时(标准)’ ‘’ ‘’.
def_fcat ‘SJZZGS’ ‘制造工时(实际)’ ‘’ ‘’.
def_fcat ‘CYZZGS’ ‘制造工时(差异)’ ‘’ ‘’.
def_fcat ‘BZZZGSFL’ ‘制造工时费用费率(标准)’ ‘’ ‘’.
def_fcat ‘SJZZGSFL’ ‘制造工时费用费率(实际)’ ‘’ ‘’.
def_fcat ‘CYZZGSFL’ ‘制造工时费用费率(差异)’ ‘’ ‘’.

ENDFORM.
&---------------------------------------------------------------------
*& Form frm_get_data
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM frm_get_data .
DATA: l_tabix TYPE sy-tabix.

REFRESH: gt_out.

SELECT f~bukrs, f~kdauf, f~kdpos, f~zprono, f~objnr, k~plnnr, p~aufnr, p~dwerk, p~matnr, p~psmng, p~wemng, p~meins
FROM aufk AS f
JOIN afko AS k ON f~aufnr = k~aufnr
JOIN afpo AS p ON f~aufnr EQ p~aufnr
INTO TABLE @DATA(lt_data)
WHERE f~bukrs EQ @p_bukrs
AND f~aufnr IN @s_aufnr
AND f~kdauf IN @s_kdauf
AND f~kdpos IN @s_kdpos
AND f~zprono IN @s_zprono
AND p~matnr IN @s_matnr.

CHECK lt_data[] IS NOT INITIAL.

SELECT objnr, j~stat, chgnr, udate, utime, txt30
FROM jcds AS j
JOIN tj02t AS t ON j~stat = t~istat AND t~spras EQ @sy-langu
FOR ALL ENTRIES IN @lt_data
WHERE objnr = @lt_data-objnr
AND inact = ‘’
INTO TABLE @DATA(lt_stat).

"取标准和实际费用
SELECT a~kalnr, a~matnr, a~bwkey, a~vbeln, a~posnr, b~bdatj, b~poper, b~prtyp, b~kst001, b~kst003,
b~kst005, b~kst007, b~kst009, b~kst011, b~kst019, b~kst013, b~kst015, b~kst017
FROM ckmlhd AS a
JOIN ckmlprkeph AS b ON a~kalnr EQ b~kalnr
FOR ALL ENTRIES IN @lt_data
WHERE a~matnr EQ @lt_data-matnr
AND a~bwkey EQ @lt_data-dwerk
AND a~vbeln EQ @lt_data-kdauf
AND a~posnr EQ @lt_data-kdpos
AND b~bdatj IN @s_gjahr
AND b~poper IN @s_monat
AND b~keart EQ ‘H’
AND b~prtyp IN ( ‘V’, ‘S’ )
AND b~kkzst EQ ‘’
AND b~curtp EQ ‘10’
INTO TABLE @DATA(lt_ckmlprkeph).

"取标准和实际工时
SELECT a~aufpl, a~aplzl, a~plnnr, b~vgw01, b~vgw02, b~vgw03, b~ism01, b~ism02, b~ism03
FROM afvc AS a
JOIN afvv AS b ON a~aufpl = b~aufpl AND a~aplzl = b~aplzl
FOR ALL ENTRIES IN @lt_data
WHERE a~plnnr = @lt_data-plnnr
INTO TABLE @DATA(lt_afvv).

DATA(lt_stat_d) = lt_stat[].
DELETE lt_stat_d WHERE NOT ( stat = ‘I0012’ OR stat = ‘I0045’ ).
SORT lt_stat_d BY objnr stat.
SORT lt_stat BY objnr udate DESCENDING utime DESCENDING.
DELETE ADJACENT DUPLICATES FROM lt_stat COMPARING objnr.

SELECT * FROM makt INTO TABLE @DATA(lt_makt)
WHERE spras = ‘1’
ORDER BY matnr.

SORT lt_ckmlprkeph BY matnr bwkey vbeln posnr prtyp.
SORT lt_afvv BY plnnr aufpl aplzl.

LOOP AT lt_data INTO DATA(ls_data).

READ TABLE lt_ckmlprkeph TRANSPORTING NO FIELDS WITH KEY matnr = ls_data-matnr
                                                         bwkey = ls_data-dwerk
                                                         vbeln = ls_data-kdauf
                                                         posnr = ls_data-kdpos BINARY SEARCH.
IF sy-subrc = 0.
  l_tabix = sy-tabix.

  LOOP AT lt_ckmlprkeph INTO DATA(ls_ckmlprkeph) FROM l_tabix.
    IF NOT ( ls_ckmlprkeph-matnr = ls_data-matnr AND ls_ckmlprkeph-bwkey = ls_data-dwerk AND
             ls_ckmlprkeph-vbeln = ls_data-kdauf AND ls_ckmlprkeph-posnr = ls_data-kdpos ).
      EXIT.
    ENDIF.

    CLEAR: wa_out.
    MOVE-CORRESPONDING ls_data TO wa_out.

    wa_out-bdatj = ls_ckmlprkeph-bdatj.
    wa_out-poper = ls_ckmlprkeph-poper.

    CASE ls_ckmlprkeph-prtyp.
      WHEN 'S'.
        wa_out-bzycl += ls_ckmlprkeph-kst001."原材料(标准)
        wa_out-bzbcp += ls_ckmlprkeph-kst003."半成品(标准)
        wa_out-bzccp += ls_ckmlprkeph-kst005."产成品(标准)
        wa_out-bzwwfccl += ls_ckmlprkeph-kst007."委外发出材料(标准)
        wa_out-bzwwjgf += ls_ckmlprkeph-kst009."委外加工费(标准)
        wa_out-bzwwjz += ls_ckmlprkeph-kst011."委外-结转(标准)
        wa_out-bzgxwxfy += ls_ckmlprkeph-kst019."工序外协费用(标准)
        wa_out-bzrgfy += ls_ckmlprkeph-kst013."人工费用(标准)
        wa_out-bzjqgsfy += ls_ckmlprkeph-kst015."机器工时费用(标准)
        wa_out-bzzzgsfy += ls_ckmlprkeph-kst017."制造工时费用(标准)
      WHEN 'V'.
        wa_out-sjycl += ls_ckmlprkeph-kst001."原材料(实际)
        wa_out-sjbcp += ls_ckmlprkeph-kst003."半成品(实际)
        wa_out-sjccp += ls_ckmlprkeph-kst005."产成品(实际)
        wa_out-sjwwfccl += ls_ckmlprkeph-kst007."委外发出材料(实际)
        wa_out-sjwwjgf += ls_ckmlprkeph-kst009."委外加工费(实际)
        wa_out-sjwwjz += ls_ckmlprkeph-kst011."委外-结转(实际)
        wa_out-sjgxwxfy += ls_ckmlprkeph-kst019."工序外协费用(实际)
        wa_out-sjrgfy += ls_ckmlprkeph-kst013."人工费用(实际)
        wa_out-sjjqgsfy += ls_ckmlprkeph-kst015."机器工时费用(实际)
        wa_out-sjzzgsfy += ls_ckmlprkeph-kst017."制造工时费用(实际)
      WHEN OTHERS.
    ENDCASE.
    COLLECT wa_out INTO gt_out.
  ENDLOOP.
ENDIF.

ENDLOOP.

SORT lt_data BY aufnr.

LOOP AT gt_out INTO wa_out.
READ TABLE lt_data INTO ls_data WITH KEY aufnr = wa_out-aufnr BINARY SEARCH.
IF sy-subrc = 0.
wa_out-psmng = ls_data-psmng.
wa_out-wemng = ls_data-wemng.
ENDIF.

READ TABLE lt_afvv TRANSPORTING NO FIELDS WITH KEY plnnr = ls_data-plnnr BINARY SEARCH.
IF sy-subrc = 0.
  l_tabix = sy-tabix.

  LOOP AT lt_afvv INTO DATA(ls_afvv) FROM l_tabix.
    IF NOT ls_afvv-plnnr = ls_data-plnnr.
      EXIT.
    ENDIF.

    wa_out-bzrggs += ls_afvv-vgw01."人工工时(标准)
    wa_out-bzjqgs += ls_afvv-vgw02."机器工时(标准)
    wa_out-bzzzgs += ls_afvv-vgw03."制造工时(标准)

    wa_out-sjrggs += ls_afvv-ism01."人工工时(实际)
    wa_out-sjjqgs += ls_afvv-ism02."机器工时(实际)
    wa_out-sjzzgs += ls_afvv-ism03."制造工时(实际)

  ENDLOOP.
ENDIF.

wa_out-cyycl = wa_out-bzycl - wa_out-sjycl."原材料(差异)= 原材料(标准)- 原材料(实际)
wa_out-cybcp = wa_out-bzbcp - wa_out-sjbcp."半成品(差异)= 半成品(标准)- 半成品(实际)
wa_out-cyccp = wa_out-bzccp - wa_out-sjccp."产成品(差异)= 产成品(标准)- 产成品(实际)
wa_out-cywwfccl = wa_out-bzwwfccl - wa_out-sjwwfccl."委外发出材料(差异)= 委外发出材料(标准)- 委外发出材料(实际)
wa_out-cywwjgf = wa_out-bzwwjgf - wa_out-sjwwjgf."委外加工费(差异)= 委外加工费(标准)- 委外加工费(实际)
wa_out-cywwjz = wa_out-bzwwjz - wa_out-sjwwjz."委外-结转(差异)= 委外-结转(标准)- 委外-结转(实际)
wa_out-cygxwxfy = wa_out-bzgxwxfy - wa_out-sjgxwxfy."工序外协费用(差异)= 工序外协费用(标准)- 工序外协费用(实际)
wa_out-cyrgfy = wa_out-bzrgfy - wa_out-sjrgfy."人工费用(差异)= 人工费用(标准)- 人工费用(实际)
wa_out-cyjqgsfy = wa_out-bzjqgsfy - wa_out-sjjqgsfy."机器工时费用(差异)= 机器工时费用(标准)- 机器工时费用(实际)
wa_out-cyzzgsfy = wa_out-bzzzgsfy - wa_out-sjzzgsfy."制造工时费用(差异)= 制造工时费用(标准)- 制造工时费用(实际)

"材料总计(原材料+半成品+成品)
wa_out-bzclzj = wa_out-bzycl + wa_out-bzbcp + wa_out-bzccp.
wa_out-sjclzj = wa_out-sjycl + wa_out-sjbcp + wa_out-sjccp.
wa_out-cyclzj = wa_out-bzclzj - wa_out-sjclzj."材料(差异)= 材料(标准)- 材料(实际)


wa_out-cyrggs = wa_out-bzrggs - wa_out-sjrggs."人工工时(差异)= 人工工时(标准)- 人工工时(实际)
wa_out-cyjqgs = wa_out-bzjqgs - wa_out-sjjqgs."机器工时(差异)= 机器工时(标准)- 机器工时(实际)
wa_out-cyzzgs = wa_out-bzzzgs - wa_out-sjzzgs."制造工时(差异)= 制造工时(标准)- 制造工时(实际)

IF wa_out-bzrggs <> 0.
  wa_out-bzrgfl = wa_out-bzrgfy / wa_out-bzrggs."人工费率(标准)= 人工费用(标准)/ 人工工时(标准)
ENDIF.
IF wa_out-bzjqgs <> 0.
  wa_out-bzjqgsfl = wa_out-bzjqgsfy / wa_out-bzjqgs."机器工时费率(标准)= 机器工时费用(标准)/ 机器工时(标准)
ENDIF.
IF wa_out-bzzzgs <> 0.
  wa_out-bzzzgsfl = wa_out-bzzzgsfy / wa_out-bzzzgs."制造工时费率(标准)= 制造工时费用(标准)/ 制造工时(标准)
ENDIF.

IF wa_out-sjrggs <> 0.
  wa_out-sjrgfl = wa_out-sjrgfy / wa_out-sjrggs."人工费率(实际)= 人工费用(实际)/ 人工工时(实际)
ENDIF.
IF wa_out-sjjqgs <> 0.
  wa_out-sjjqgsfl = wa_out-sjjqgsfy / wa_out-sjjqgs."机器工时费率(实际)= 机器工时费用(实际)/ 机器工时(实际)
ENDIF.
IF wa_out-sjzzgs <> 0.
  wa_out-sjzzgsfl = wa_out-sjzzgsfy / wa_out-sjzzgs."制造工时费率(实际)= 制造工时费用(实际)/ 制造工时(实际)
ENDIF.

wa_out-cyrgfl = wa_out-bzrgfl - wa_out-sjrgfl."人工工时(差异)= 人工工时(标准)- 人工工时(实际)
wa_out-cyjqgsfl = wa_out-bzjqgsfl - wa_out-sjjqgsfl."机器工时(差异)= 机器工时(标准)- 机器工时(实际)
wa_out-cyzzgsfl = wa_out-bzzzgsfl - wa_out-sjzzgsfl."制造工时(差异)= 制造工时(标准)- 制造工时(实际)


READ TABLE lt_makt INTO DATA(ls_makt) WITH KEY matnr = ls_data-matnr BINARY SEARCH.
IF sy-subrc = 0.
  wa_out-maktx = ls_makt-maktx.
ENDIF.

READ TABLE lt_stat INTO DATA(ls_stat) WITH KEY objnr = ls_data-objnr BINARY SEARCH.
IF sy-subrc = 0.
  wa_out-txt30 = ls_stat-txt30.
ENDIF.

"JCDS-STAT=“I0012”时把字段JCDS-UDATE 填入“入库日期”
READ TABLE lt_stat INTO ls_stat WITH KEY objnr = ls_data-objnr stat = 'I0012' BINARY SEARCH.
IF sy-subrc = 0.
  wa_out-rkdat = ls_stat-udate.
ENDIF.

"JCDS-STAT=“I0045”时把字段JCDS-UDATE 填入“完成日期”即TECO日期;
READ TABLE lt_stat INTO ls_stat WITH KEY objnr = ls_data-objnr stat = 'I0045' BINARY SEARCH.
IF sy-subrc = 0.
  wa_out-wcdat = ls_stat-udate.
ENDIF.

MODIFY gt_out FROM wa_out.

ENDLOOP.

SORT gt_out BY bukrs aufnr bdatj poper.
ENDFORM.

你可能感兴趣的:(SAP-ABAP,sap)