报表逻辑和解决的业务:
在SAP系统中出生产车间每天的报工数量和入库数量。
本报表针对按单生产的物料,逻辑:
1、从aufm表中找到在当月发生过101移动类型的生产订单
2、与销售订单对比,删除掉半成品
3、根据601移动类型从mseg表中找出出货数量
4、从afru表中找出订单每天的确认数量
5、从aufm表中找出生产订单的入库数量
6、利用case写出31天每天的确认和入库数量
*&---------------------------------------------------------------------*
*& Report ZCHANT_PP_10
*&
*&---------------------------------------------------------------------*
*&报表逻辑:选择一个月份,根据选择月份对所有带有销售订单的产成品进行跟踪,
*&入库数量和完工数量从SAP系统抓出,计算到每天。销售订单出货数量根据移动
*&类型计算交货数量。(601/602/901/902/903/904/905/906/Y01/Y02/Y03/Y04/
*&Z21/Z22.
*&---------------------------------------------------------------------*
REPORT zchant_pp_10.
TABLES:aufm,afpo,t001w,afko,afvc,afru.
"定义ALV输出内表
DATA:BEGIN OF t_alv OCCURS 0,
kunnr TYPE vbak-kunnr,"客户代码
sortl TYPE kna1-sortl,"客户检索
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
edatu TYPE vbep-edatu,"交货日期
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"交货工厂
kwmeng TYPE p,"销售订单数量
menge TYPE p,"出货数量
mng02 TYPE p,"库存数量
zstock TYPE p,"生产累计入库数量
zchayi TYPE p,"生产欠数
zgoods TYPE p,"当月累计入库数量
zconfi TYPE p,"当月累计确认数量
zgoods1 TYPEp,"1号入库数量
zconfi1 TYPEp,"1号确认数量
zgoods2 TYPEp,"2入库数量
zconfi2 TYPEp,"2号确认数量
zgoods3 TYPEp,"3号入库数量
zconfi3 TYPEp,"3号确认数量
zgoods4 TYPEp,"4号入库数量
zconfi4 TYPEp,"4号确认数量
zgoods5 TYPEp,"5号入库数量
zconfi5 TYPEp,"5号确认数量
zgoods6 TYPEp,"6号入库数量
zconfi6 TYPEp,"6号确认数量
zgoods7 TYPEp,"7号入库数量
zconfi7 TYPEp,"7号确认数量
zgoods8 TYPEp,"8号入库数量
zconfi8 TYPEp,"8号确认数量
zgoods9 TYPEp,"9号入库数量
zconfi9 TYPEp,"9号确认数量
zgoods10 TYPEp,"10号入库数量
zconfi10 TYPEp,"10号确认数量
zgoods11 TYPEp,"11号入库数量
zconfi11 TYPEp,"11号确认数量
zgoods12 TYPEp,"12号入库数量
zconfi12 TYPEp,"12号确认数量
zgoods13 TYPEp,"13号入库数量
zconfi13 TYPEp,"13号确认数量
zgoods14 TYPEp,"14号入库数量
zconfi14 TYPEp,"14号确认数量
zgoods15 TYPEp,"15号入库数量
zconfi15 TYPEp,"15号确认数量
zgoods16 TYPEp,"16号入库数量
zconfi16 TYPEp,"16号确认数量
zgoods17 TYPEp,"17号入库数量
zconfi17 TYPEp,"17号确认数量
zgoods18 TYPEp,"18号入库数量
zconfi18 TYPEp,"18号确认数量
zgoods19 TYPEp,"19号入库数量
zconfi19 TYPEp,"19号确认数量
zgoods20 TYPEp,"20号入库数量
zconfi20 TYPEp,"20号确认数量
zgoods21 TYPEp,"21号入库数量
zconfi21 TYPEp,"21号确认数量
zgoods22 TYPEp,"22号入库数量
zconfi22 TYPEp,"22号确认数量
zgoods23 TYPEp,"23号入库数量
zconfi23 TYPEp,"23号确认数量
zgoods24 TYPEp,"24号入库数量
zconfi24 TYPEp,"24号确认数量
zgoods25 TYPEp,"25号入库数量
zconfi25 TYPEp,"25号确认数量
zgoods26 TYPEp,"26号入库数量
zconfi26 TYPEp,"26号确认数量
zgoods27 TYPEp,"27号入库数量
zconfi27 TYPEp,"27号确认数量
zgoods28 TYPEp,"28号入库数量
zconfi28 TYPEp,"28号确认数量
zgoods29 TYPEp,"29号入库数量
zconfi29 TYPEp,"29号确认数量
zgoods30 TYPEp,"30号入库数量
zconfi30 TYPEp,"30号确认数量
zgoods31 TYPEp,"31号入库数量
zconfi31 TYPEp,"31号确认数量
maktx TYPE makt-maktx,"物料描述
END OF t_alv.
"定义当月有入库的物料
DATA:BEGIN OF lt_aufm OCCURS 0,
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"工厂
aufnr TYPE aufm-aufnr,"生产订单号码
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
menge TYPE aufm-menge,"入库数量
bwart TYPE aufm-bwart,"移动类型
END OF lt_aufm,
"删除重复记录的内表
lf_aufm LIKE TABLE OF lt_aufm WITH HEADER LINE.
"取出生产订单挂在销售订单上的内表
DATA:BEGIN OF lt_afpo OCCURS 0,
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"工厂
aufnr TYPE aufm-aufnr,"生产订单号码
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
END OF lt_afpo,
"删除重复记录的内表
lm_afpo LIKE TABLE OF lt_afpo WITH HEADER LINE,
"取出生产订单与销售订单相同的物料
lt_matnr TYPE vbap-matnr.
"取客户简称,客户检索词,销售订单数量,出货数量,交货日期,库存数量
DATA:BEGIN OF lt_vbap OCCURS 0,
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"工厂
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
kunnr TYPE vbak-kunnr,"客户代码
sortl TYPE kna1-sortl,"客户检索
edatu TYPE vbep-edatu,"交货日期
kwmeng TYPE vbap-kwmeng,"销售订单数量
menge TYPE mseg-menge,"出货数量
mng02 TYPE mseg-menge,"库存数量
END OF lt_vbap,
"删除重复记录的内表
lm_vbap LIKE TABLE OF lt_vbap WITH HEADER LINE,
"取销售订单出货数量的辅助字段
"移动类型601/901/903/905/Y01/Y03/Z21
lt_gmnga TYPE vbap-kwmeng,
"移动类型602/902/904/906/Y02/Y04/Z22
lt_kwmeng TYPE vbap-kwmeng.
"取生产订单工艺路线号,提高程序运行速度内表
DATA:BEGIN OF lt_afru OCCURS 0,
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"工厂
aufnr TYPE aufm-aufnr,"生产订单号码
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
aufpl TYPE afvc-aufpl,"工艺路线号
vornr TYPE afvc-vornr,"工序
rueck TYPE afvc-rueck,"确认号码
END OF lt_afru,
"取出工序号码和确认号码
ls_afru LIKE TABLE OF lt_afru WITH HEADER LINE,
"取生产订单的最后一道工序
lt_afvc LIKE TABLE OF lt_afru WITH HEADER LINE,
"删除重复的生产订单号码
lm_afvc LIKE TABLE OF lt_afru WITH HEADER LINE,
"取生产订单每天的确认数量
BEGIN OF lm_afru OCCURS 0,
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"工厂
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
budat TYPE afru-budat,"记账日期
gmnga TYPE afru-gmnga,"确认数量
stokz TYPE afru-stokz,"冲销标识
END OF lm_afru,
"取消确认数量为负数的内表处理
BEGIN OF lp_afru OCCURS 0,
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"工厂
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
budat TYPE afru-budat,"记账日期
gmnga TYPE afru-gmnga,"确认数量
END OF lp_afru,
"合计每天确认数量内表
lf_afru LIKE TABLE OF lp_afru WITH HEADER LINE,
"计算当月累计确认数量
BEGIN OF lk_month OCCURS 0,
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"工厂
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
gmnga TYPE afru-gmnga,"确认数量
END OF lk_month,
"删除重复记录
lj_month LIKE TABLE OF lk_month WITH HEADER LINE.
"取生产订单每天的入库数量
DATA:BEGIN OF lt_stock OCCURS 0,
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"工厂
aufnr TYPE aufm-aufnr,"生产订单号码
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
budat TYPE aufm-budat,"记账日期
menge TYPE aufm-menge,"入库数量
END OF lt_stock,
"删除生产订单号码内表
BEGIN OF lm_stock OCCURS 0,
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"工厂
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
budat TYPE aufm-budat,"记账日期
menge TYPE aufm-menge,"入库数量
END OF lm_stock,
"合计每天入库数量内表
lf_stock LIKE TABLE OF lm_stock WITH HEADER LINE.
"计算生产累计入库数量和生产欠数
DATA:BEGIN OF lt_total OCCURS 0,
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"工厂
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
END OF lt_total,
"删除重复记录的销售订单号码+行项目号码
ln_total LIKE TABLE OF lt_total WITH HEADER LINE,
"读取销售订单号码+行项目号码所对应的所有生产订单号码
*BEGIN OF lg_total OCCURS 0,
*matnr TYPE aufm-matnr,"物料编码
*werks TYPE aufm-werks,"工厂
*kdauf TYPE afpo-kdauf,"销售订单号码
*kdpos TYPE afpo-kdpos,"行项目号码
*aufnr TYPE afpo-aufnr,"生产订单号码
*wemng TYPE afpo-wemng,"入库数量
*END OF lg_total,
*"去掉生产订单号码内表
BEGIN OF lf_total OCCURS 0,
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"工厂
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
wemng TYPE afpo-wemng,"入库数量
END OF lf_total,
"合计生产入库数量内表
BEGIN OF lm_total OCCURS 0,
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"工厂
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
wemng TYPE afpo-wemng,"入库数量
END OF lm_total,
"读取内表销售订单数量,计算生产欠数
BEGIN OF lp_total OCCURS 0,
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"工厂
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
wemng TYPE afpo-wemng,"入库数量
kwmeng TYPE vbap-kwmeng,"销售订单数量
zchayi TYPE mseg-menge,"生产欠数
END OF lp_total.
"计算当月累计入库数量内表
DATA:BEGIN OF lt_month OCCURS 0,
matnr TYPE aufm-matnr,"物料编码
werks TYPE aufm-werks,"工厂
kdauf TYPE afpo-kdauf,"销售订单号码
kdpos TYPE afpo-kdpos,"行项目号码
menge TYPE aufm-menge,"入库数量
END OF lt_month,
"合计当月累计入库数量
lf_month LIKE TABLE OF lt_month WITH HEADER LINE.
"检查输入的工厂一定存在
DATA:lt_werks TYPE aufm-werks."工厂
"定义当月第一天和最后一天
DATA:frist_day TYPE sy-datum,
last_day TYPE sy-datum.
"当前月与查询月对比
DATA:lh_month TYPE s012-spmon.
"声明处理每天数据交换的CASE值
DATA:lt_case(2) TYPE c.
"定义ALV输出时日期比较
DATA:lt_day(2) TYPE c.
"定义ALV输出参数
TYPE-POOLS:slis."声明函数组
DATA:i_callback_program TYPE sy-repid,"定义函数使用的程序名称
is_layout TYPE slis_layout_alv,"定义函数输出列格式
"定义ALV单元格
it_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
"查询界面定义
SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:s_matnr FOR afpo-matnr.
PARAMETERS:s_werks LIKE aufm-werks OBLIGATORY,
s_month LIKE s012-spmon OBLIGATORY.
SELECTION-SCREEN END OF BLOCK a1.
INITIALIZATION.
AT SELECTION-SCREEN.
CLEAR:t_alv,t_alv[],lt_aufm,lt_aufm[],lf_aufm,lf_aufm[],
lt_afpo,lt_afpo[],lm_afpo,lm_afpo[],lt_matnr,
lt_vbap,lt_vbap[],lm_vbap,lm_vbap[],lt_afru,
lt_afru[],lt_afvc,lt_afvc[],lm_afvc,lm_afvc[],
lm_afru,lm_afru[],lp_afru,lp_afru[],lf_afru,
lf_afru[],lt_stock,lt_stock[],lm_stock,lm_stock[],
lf_stock,lf_stock[],lt_total,lt_total[],lf_total,
lf_total[],lm_total,lm_total[],lp_total,lp_total[],
lt_month,lt_month[],lf_month,lf_month[],lt_werks,
ls_afru,ls_afru[],frist_day,last_day,lh_month,
ln_total,ln_total[],lt_day,lk_month,lk_month[],
lj_month,lj_month[].
lh_month = sy-datum+0(6).
IF lh_month < s_month.
MESSAGE '3'TYPE 'E'.
ELSE.
SELECTSINGLE werks INTO lt_werks
FROM t001w
WHERE werks EQ s_werks.
IF sy-subrc<> 0.
MESSAGE e102(m3) WITH s_werks.
ELSE.
CONCATENATE s_month '01' INTO frist_day.
*CALL FUNCTION 'LAST_DAY_OF_MONTHS'
*EXPORTING
*day_in= frist_day
*IMPORTING
*last_day_of_month = last_day
*EXCEPTIONS
*day_in_no_date= 1
*OTHERS= 2.
*IF sy-subrc <> 0.
*MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*ENDIF.
DATA: januar(2) VALUE'01',
december(2) VALUE '12',
lowdate(4)VALUE '1800',
frist(2)VALUE '01'.
DATA: BEGIN OF highdate,
j(4) VALUE '9999',
m(2) VALUE '12',
t(2) VALUE '31',
END OF highdate.
DATA: BEGIN OF date,
j(4),
m(2),
t(2),
END OF date.
DATA: zahl TYPE i.
date = frist_day.
IF date-m LT januar OR date-m GT december.
RAISE frist_day_no_date.
ENDIF.
IF date-j LT lowdate.
RAISE frist_day_no_date.
ENDIF.
IF date-j EQ highdate-j AND
date-m EQ highdate-m.
last_day = highdate.
ELSE.
IF date-m EQ december.
zahl = date-j + 1.
UNPACK zahl TO date-j.
date-m = frist.
ELSE.
zahl = date-m + 1.
UNPACK zahl TO date-m.
ENDIF.
date-t = frist.
last_day = date.
SUBTRACT 1 FROM last_day.
ENDIF.
ENDIF.
ENDIF.
START-OF-SELECTION.
AUTHORITY-CHECK OBJECT 'M_MATE_WRK'
ID 'ACTVT' DUMMY
ID 'WERKS' FIELD s_werks.
IF sy-subrc = 0.
PERFORMzfrm_goods_receipt_data."在查询月期间有过货物移动的订单
PERFORMzfrm_sales_order_data."取与生产订单一致的销售订单
PERFORMzfrm_porder_goods_receipt_data."每日入库的生产订单NO
PERFORMzfrm_porder_confirmation_data."每日确认的生产订单NO
PERFORMzfrm_inittables_process_data."内表数据处理
PERFORMzfrm_output_alv_data."ALV数据输出
ENDIF.
END-OF-SELECTION.