*----------------------------------------------------------------------* * Program Name : ZFISRHZ09 * * Purpose : * * Created by : Stonemason * * Create on : 2007-10-25 * * T code : zfir009 * * Functional Consultant : * * Description : 对账单 * *----------------------------------------------------------------------* * Modification Log * *Date Programmer Corr. # Description * *2006/MM/DD xxxxxxxxxx xxxxxxxxxx Initial pgm dev * *----------------------------------------------------------------------* REPORT zfisrhz09. TYPE-POOLS:slis. TABLES:lfa1,lfb1,mseg,mkpf,mara,marc,makt,resb,ekbe. *********globle data******* DATA:BEGIN OF itab_mseg OCCURS 0, mblnr LIKE mseg-mblnr,"物料凭证 zeile LIKE mseg-zeile, matnr LIKE mseg-matnr,"物料编码 ebeln LIKE mseg-ebeln,"采购订单 smbln LIKE mseg-smbln,"物料凭证 meins LIKE mseg-meins,"单位 menge LIKE mseg-menge,"数量 dmbtr LIKE mseg-dmbtr,"总金额 END OF itab_mseg.
DATA:BEGIN OF itab_mseg1 OCCURS 0, mblnr LIKE mseg-mblnr,"物料凭证 zeile LIKE mseg-zeile, matnr LIKE mseg-matnr,"物料编码 ebeln LIKE mseg-ebeln,"采购订单 smbln LIKE mseg-smbln,"物料凭证 meins LIKE mseg-meins,"单位 maktx LIKE makt-maktx,"物料描述 danj TYPE p DECIMALS 4, menge LIKE mseg-menge,"数量 dmbtr LIKE mseg-dmbtr,"总金额 bldat LIKE mkpf-bldat, budat LIKE mkpf-budat, END OF itab_mseg1.
DATA:BEGIN OF itab_ekbe OCCURS 0, ebeln LIKE mseg-ebeln,"采购订单 ebelp LIKE ekbe-ebelp,"采购凭证的项目编号 belnr LIKE ekbe-belnr,"物料凭证 bwart LIKE ekbe-bwart,"移动类型 budat LIKE ekbe-budat,"记帐日期 menge LIKE mseg-menge,"数量 dmbtr LIKE mseg-dmbtr,"总金额本位币 wrbtr LIKE ekbe-wrbtr,"货币金额 waers LIKE ekbe-waers,"货币类型 txz01 LIKE ekpo-txz01, matnr LIKE ekbe-matnr,"物料 * maktx LIKE makt-maktx,"物料描述 meins LIKE mseg-meins,"单位 lifnr LIKE mseg-lifnr, shkzg LIKE mseg-shkzg, END OF itab_ekbe.
DATA:BEGIN OF itab_ekbe1 OCCURS 0, ebeln LIKE mseg-ebeln,"采购订单 ebelp LIKE ekbe-ebelp,"采购凭证的项目编号 belnr LIKE ekbe-belnr,"物料凭证 budat LIKE ekbe-budat,"记帐日期 danj TYPE p DECIMALS 4, menge LIKE mseg-menge,"数量 dmbtr LIKE mseg-dmbtr,"总金额本位币 wrbtr LIKE ekbe-wrbtr,"货币金额 waers LIKE ekbe-waers,"货币类型 txz01 LIKE ekpo-txz01, matnr LIKE ekbe-matnr,"物料 maktx LIKE makt-maktx,"物料描述 meins LIKE mseg-meins, lifnr LIKE mseg-lifnr, END OF itab_ekbe1.
DATA:BEGIN OF itab_ekbe2 OCCURS 0, ebeln LIKE mseg-ebeln,"采购订单 ebelp LIKE ekbe-ebelp,"采购凭证的项目编号 belnr LIKE ekbe-belnr,"物料凭证 budat LIKE ekbe-budat,"记帐日期 danj TYPE p DECIMALS 4, menge LIKE mseg-menge,"数量 dmbtr LIKE mseg-dmbtr,"总金额本位币 wrbtr LIKE ekbe-wrbtr,"货币金额 waers LIKE ekbe-waers,"货币类型 txz01 LIKE ekpo-txz01, matnr LIKE ekbe-matnr,"物料 maktx LIKE makt-maktx,"物料描述 meins LIKE mseg-meins, danw LIKE mseg-menge,"单位定额 xhze LIKE mseg-dmbtr,"消耗总额 shij LIKE mseg-dmbtr,"实际总额 chayi LIKE mseg-dmbtr,"差异 lifnr LIKE mseg-lifnr, matnr1 LIKE ekbe-matnr,"物料 maktx1 LIKE makt-maktx,"物料描述 END OF itab_ekbe2.
DATA:BEGIN OF itab_ekpo OCCURS 0, ebeln LIKE ekpo-ebeln, ebelp LIKE ekpo-ebelp, txz01 LIKE ekpo-txz01, matnr LIKE ekpo-matnr, netpr LIKE ekpo-netpr,"净价值 menge LIKE ekpo-menge,"数量 netwr LIKE ekpo-netwr, END OF itab_ekpo.
DATA:BEGIN OF itab_resb OCCURS 0, rsnum LIKE resb-rsnum,"预留 matnr LIKE resb-matnr, bdter LIKE resb-bdter,"需求日期 baugr LIKE resb-baugr,"溯源需求物料 ebeln LIKE resb-ebeln,"采购凭证号码 bdmng LIKE resb-bdmng, enmng LIKE resb-enmng, sbter LIKE resb-sbter, END OF itab_resb.
DATA:itab_ekbe3 LIKE itab_ekbe OCCURS 0 WITH HEADER LINE. DATA:itab_resb1 LIKE itab_resb OCCURS 0 WITH HEADER LINE. DATA:BEGIN OF itab_mkpf OCCURS 0, mblnr LIKE mseg-mblnr, bldat LIKE mkpf-bldat, budat LIKE mkpf-budat, END OF itab_mkpf. DATA:p_grid_title(70) VALUE '对账单'.
********selection-screen**** SELECTION-SCREEN BEGIN OF BLOCK handsome WITH FRAME TITLE text-001. SELECT-OPTIONS::p_bukrs FOR ekbe-werks DEFAULT '2110'."ekbe~werks PARAMETERS:p_gjahr LIKE mseg-gjahr DEFAULT sy-datum(4). SELECT-OPTIONS: s_lifnr FOR mseg-lifnr, * OBLIGATORY," s_mblnr FOR mseg-mblnr, s_ebeln FOR mseg-ebeln, s_datum FOR sy-datum OBLIGATORY. * OBLIGATORY. PARAMETERS:p_box AS CHECKBOX. SELECTION-SCREEN END OF BLOCK handsome.
*INITIALIZATION. * DATA:gjahr LIKE mseg-mjahr,monat LIKE bkpf-monat, * gjahr_1 LIKE sy-datum. * gjahr = sy-datum(4). * monat = sy-datum+4(2). * CONCATENATE gjahr monat '01' INTO gjahr_1. * s_datum-low = gjahr_1. * s_datum-high = sy-datum. * APPEND s_datum.
START-OF-SELECTION. IF p_box = ''. * PERFORM get_data. PERFORM get_data1. * IF p_box = ''. * PERFORM cut_data. * PERFORM chuli_data. PERFORM print_alv. ELSE.
SUBMIT zfisrhz09_2 WITH p_bukrs IN p_bukrs WITH p_gjahr = p_gjahr WITH s_lifnr IN s_lifnr WITH s_mblnr IN s_mblnr WITH s_ebeln IN s_ebeln WITH s_datum IN s_datum AND RETURN. ENDIF. *&---------------------------------------------------------------------* *& Form get_data1 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM get_data1 .
SELECT ekbe~ebeln ekbe~ebelp ekbe~belnr ekbe~bwart ekbe~budat"委外后产生物料凭证 ekbe~menge ekbe~dmbtr ekbe~wrbtr ekbe~waers ekpo~txz01 ekbe~matnr mseg~meins mseg~lifnr mseg~shkzg INTO TABLE itab_ekbe FROM ekbe JOIN mseg ON mseg~mblnr = ekbe~belnr AND mseg~ebeln = ekbe~ebeln AND"matnr mseg~ebelp = ekbe~ebelp AND mseg~matnr = ekbe~matnr JOIN ekpo ON mseg~ebelp = ekpo~ebelp AND mseg~ebeln = ekpo~ebeln WHERE ekbe~gjahr = p_gjahr AND ekbe~ebeln IN s_ebeln AND ekbe~budat IN s_datum AND ekbe~belnr IN s_mblnr AND ekbe~werks IN p_bukrs AND mseg~lifnr IN s_lifnr AND ekbe~bwart IN ('101','102','121','122','161','162'). * AND ( ekbe~bwart = '101' OR * ekbe~bwart = ' 102').
SELECT ekbe~ebeln ekbe~ebelp ekbe~belnr ekbe~bwart ekbe~budat"委外发送的原料 ekbe~menge ekbe~dmbtr ekbe~wrbtr ekbe~waers ekbe~matnr mseg~meins mseg~lifnr mseg~shkzg INTO TABLE itab_ekbe3 FROM ekbe JOIN mseg ON mseg~mblnr = ekbe~belnr AND mseg~ebeln = ekbe~ebeln "matnr AND mseg~matnr = ekbe~matnr WHERE ekbe~gjahr = p_gjahr AND ekbe~ebeln IN s_ebeln AND ekbe~belnr IN s_mblnr AND ekbe~werks IN p_bukrs AND mseg~lifnr IN s_lifnr AND ekbe~bwart IN ('543','544' ). * AND ( ekbe~bwart <> '101' OR * ekbe~bwart <> '102').
SELECT ebeln ebelp txz01 matnr netpr menge netwr INTO TABLE itab_ekpo FROM ekpo"订单价格和数量 FOR ALL ENTRIES IN itab_ekbe WHERE ebeln = itab_ekbe-ebeln AND ebeln IN s_ebeln AND matnr IN s_mblnr AND werks IN p_bukrs AND pstyp = '3'.
SELECT rsnum matnr bdter baugr ebeln bdmng enmng sbter INTO TABLE itab_resb FROM resb"委外数量 FOR ALL ENTRIES IN itab_ekbe * WHERE baugr = itab_ekbe-matnr WHERE ebeln = itab_ekbe-ebeln AND werks IN p_bukrs.
* SELECT rsnum matnr bdter baugr ebeln bdmng sbter INTO TABLE itab_resb1 FROM resb" * FOR ALL ENTRIES IN itab_ekbe * WHERE matnr = itab_ekbe-matnr ** AND ebeln = itab_ekbe-ebeln * AND werks = p_bukrs.
SORT itab_ekbe BY ebeln ebelp. SORT itab_ekpo BY ebeln ebelp. DATA:maktx LIKE makt-maktx. LOOP AT itab_ekbe. IF itab_ekbe-bwart = '122' OR itab_ekbe-bwart = '102' OR itab_ekbe-bwart = '162' . itab_ekbe-menge = -1 * itab_ekbe-menge. ENDIF. IF itab_ekbe-wrbtr <> 0 AND itab_ekbe-menge <> 0.
itab_ekbe1-danj = itab_ekbe-wrbtr / itab_ekbe-menge . ELSE. itab_ekbe1-danj = 0. ENDIF.
* READ TABLE itab_ekpo WITH KEY ebeln = itab_ekbe-ebeln * ebelp = itab_ekbe-ebelp. * IF sy-subrc = 0 . * itab_ekbe1-maktx = itab_ekpo-txz01 . * ENDIF. * SELECT SINGLE maktx INTO maktx FROM makt WHERE matnr = itab_ekbe-matnr. * * itab_ekbe1-maktx = maktx. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = itab_ekbe-matnr IMPORTING output = itab_ekbe-matnr.
MOVE-CORRESPONDING itab_ekbe TO itab_ekbe1. IF itab_ekbe1-menge < 0. itab_ekbe1-dmbtr = -1 * itab_ekbe1-dmbtr . ENDIF.
APPEND itab_ekbe1. CLEAR itab_ekbe1. CLEAR maktx. ENDLOOP.
ENDFORM. " get_data1 *&---------------------------------------------------------------------* *& Form print_alv *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM print_alv . DATA:ls_fieldcat TYPE slis_fieldcat_alv, gt_fieldcat TYPE slis_t_fieldcat_alv," gs_layout TYPE slis_layout_alv.
CLEAR ls_fieldcat. ls_fieldcat-fieldname = 'EBELN'."EBELN,MBLNR ls_fieldcat-seltext_l = '订单号码'. APPEND ls_fieldcat TO gt_fieldcat. CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BUDAT'. ls_fieldcat-seltext_l = '交货日期'. APPEND ls_fieldcat TO gt_fieldcat. CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BELNR'."KSTAR ls_fieldcat-seltext_l = '物料凭证'. APPEND ls_fieldcat TO gt_fieldcat. CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MATNR'. "txz01 ls_fieldcat-seltext_l = '物料号'. APPEND ls_fieldcat TO gt_fieldcat. CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TXZ01'. ls_fieldcat-seltext_l = '物料描述'. APPEND ls_fieldcat TO gt_fieldcat. CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'WAERS'. ls_fieldcat-seltext_l = '货币类型'. APPEND ls_fieldcat TO gt_fieldcat. CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'DANJ'. ls_fieldcat-seltext_l = '采购单价'. APPEND ls_fieldcat TO gt_fieldcat. CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MENGE'."menge ls_fieldcat-seltext_l = '数量'. APPEND ls_fieldcat TO gt_fieldcat. CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MEINS'."meins ls_fieldcat-seltext_l = '单位'. APPEND ls_fieldcat TO gt_fieldcat. CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'DMBTR'."dmbtr ls_fieldcat-seltext_l = '金额'. APPEND ls_fieldcat TO gt_fieldcat. CLEAR ls_fieldcat.
* ls_fieldcat-fieldname = 'WKG500'. * ls_fieldcat-seltext_l = '备注'. * APPEND ls_fieldcat TO gt_fieldcat. * CLEAR ls_fieldcat.
*设置布局,背景色交错、优化宽度、是否允许修改数据 gs_layout-zebra = 'X'. "设置每行的背景颜色交错显示。
gs_layout-colwidth_optimize = 'X'. "ALV输出时候自动优化宽度 IF itab_ekbe1[] IS INITIAL. MESSAGE i000(00) WITH '客户没有数据,请重新选择!'. STOP. ENDIF. * DATA:p_grid_title(10) VALUE '对账单'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = sy-cprog i_grid_title = p_grid_title is_layout = gs_layout it_fieldcat = gt_fieldcat[] i_save = 'A' TABLES t_outtab = itab_ekbe1 EXCEPTIONS program_error = 1 OTHERS = 2.
ENDFORM. " print_alv