* ABAP/4报表:正常生产订单打印/两种选择
* By :lake
* date: 2002-10-22
***********************************************
* 修改事项:
* 修改人:
* 修改日期:
***********************************************
report ypp012
no standard page heading
message-id y001
line-size 125 "A4纸的宽度
line-count 60(3). "每张纸的长度
initialization.
tables: afko, "订单表头数据PP订单,aufpl
afpo, "订单项
afvv, "工序中数量/日期/值的DB
afvc, "订单的工序,aufpl,arbid
resb, "预定/相关需求
makt, "商品描述
crhd, "工作中心表头,arbid
crtx. "工作中心或生产资源/工具文
* 内部表1定义:连接两张透明表:afko,afpo;
* 放入与每张生产订单相关的数据
data: begin of i_tab1 occurs 0,
dwerk like afpo-dwerk, "工厂
matnr like afpo-matnr, "物料号
charg like afpo-charg, "批次
aufnr like afpo-aufnr, "订单号
dispo like afko-dispo, "mrp控制者
ftrmi like afko-ftrmi, "实际下达日期
gltri like afko-gltri, "实际结束日期
gltrp like afko-gltrp, "基本完成日期
gamng like afko-gamng, "计划数
gmein like afko-gmein, "基本计量单位
plnnr like afko-plnnr, "任务清单组码
plnal like afko-plnal, "组计数器
aufpl like afko-aufpl, "订单中工序的工艺路线号
stlal like afko-stlal, "可选的BOM
end of i_tab1.
* 内部表2定义:连接三个表:afvv,afvc,crhd
* 生产订单--〉按工序号,工作中心,(工作中心描述)
* 计划数,生产开始日期,生产完成日期
data: begin of i_tab2 occurs 0,
aufpl like afvv-aufpl, "订单中工序的工艺路线号
aplzl like afvv-aplzl, "计数器
mgvrg like afvv-mgvrg, "工序数量
ssavd like afvv-ssavd, "最迟计划开始:执行
ssedd like afvv-ssedd, "最迟计划完成:执行
arbid like afvc-arbid, "资源的对象 ID
vornr like afvc-vornr, "工序号
end of i_tab2.
* 有关物料的内部表,连接两个透明表:resb,maktx.
data: begin of i_tab3 occurs 0,
aufnr like resb-aufnr, "订单号
aufpl like resb-aufpl, "订单中工序的工艺路线号
aplzl like resb-aplzl, "计数器
matnr like resb-matnr, "物料号码
bdmng like resb-bdmng, "需求量
meins like resb-meins, "基本计量单位
maktx like makt-maktx, "物料描述
end of i_tab3.
* 工作中心相关数据,连接两个表:crhd,crtx.
data: begin of i_tab4 occurs 0,
arbpl like crhd-arbpl, "工作中心
objid like crhd-objid, "资源的对象 ID
ktext like crtx-ktext, "短描述
end of i_tab4.
* 产生选择屏幕,获得查询条件输入界面
select-options s_1 for afpo-dwerk "工厂
obligatory "参数:设为必填项
no intervals "参数:单个输入框
no-extension "参数:不产生扩展图标
default 'PL01'. "定义缺省值
select-options s_2 for afko-dispo "MRP控制者
obligatory "参数:设为必填项
no intervals "参数:单个输入框
no-extension "参数:不产生扩展图标
default '001'. "定义缺省值
select-options s_3 for afko-aufnr. "生产订单
select-options s_4 for afpo-matnr "产品代码
no intervals "参数:单个输入框
no-extension. "参数:不产生扩展图标
select-options s_5 for sy-datum "时间范围
obligatory. "参数:设为必填项
selection-screen begin of block rad1
with frame title text-001.
parameters p_main radiobutton group gr1. "生产订单
parameters p_detail radiobutton group gr1. "生产订单工序、物料明细
selection-screen end of block rad1.
* 判断订单号和日期范围是否同时为空,如果是则出错终止程序运行
* 因为可能造成庞大的数据访问量,出现资源问题。
at selection-screen.
if s_3 = '' and s_4 is initial and s_5 is initial.
message e007.
endif.
start-of-selection.
perform get_data. "获取数据,主要流程
if p_main = 'X'. "如果是只输出生产订单
perform output_data_m.
else. "如果是输出明细
perform output_data. "调用子程序:输出数据明细
endif.
top-of-page.
perform pagetitle. "调用页眉子程序
if p_main = 'X'. "如果是只输出生产订单
perform output_tablehead_m. "输出表头
else. "如果是输出明细
perform output_tablehead. "调用子程序:显示表头部分
endif.
end-of-page.
perform endpage. "调用页脚子程序
*&---------------------------------------------------------------------*
*& Form pagetitle
*&---------------------------------------------------------------------*
* 输出页眉子程序
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form pagetitle.
write: /3 'QG/ZN22.15.03-03-A', 38 '中南铝合金轮毂有限公司',
80 '工厂:',s_1-low.
write: /46 '生产订单',80 '第' no-gap, (4) sy-pagno no-gap,'页' no-gap.
endform. " 显示页眉的子程序
*&---------------------------------------------------------------------*
*& Form endpage
*&---------------------------------------------------------------------*
* 输出页脚子程序
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form endpage.
uline.
write: /3 '说明:关键工序的工作中心内部机台生产计划详细排',
'产按‘工序日生产计划排程表’要求。'.
write: /3 '批准:',23 '审核:',43 '计划员:',63 '打印日期:',sy-datum.
endform. " 显示页脚的子程序
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* 获取数据子程序
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data.
* 按照输入的条件把符合选择条件的关于订单的数据放入内部表i_tab1,
* 产生表头所需数据,连接两个表:afko,afpo.
select afpo~dwerk afpo~matnr afpo~charg
afko~aufnr afko~dispo afko~ftrmi afko~gltri
afko~gamng afko~gmein afko~plnnr afko~plnal
afko~aufpl afko~plnbez afko~stlal afko~gltrp
into corresponding fields of table i_tab1
from afko inner join afpo on afko~aufnr = afpo~aufnr
where afpo~dwerk in s_1 "工厂
and afko~dispo in s_2 "mrp控制者
and afko~aufnr in s_3 "订单号
and afpo~matnr in s_4 "产品代码
and afko~ftrmi in s_5. "时间
* 判断是否有符合条件的订单,没有记录就出错退出。
if sy-subrc <> 0.
message e001.
endif.
* 联结两个透明表:afvv,afvc;根据内部表1的工艺路线号
* 将符合条件的记录放入内部表:i_tab2;主要是工序数据
select afvv~aufpl afvv~aplzl afvv~mgvrg afvv~ssavd afvv~ssedd
afvc~arbid afvc~vornr
into corresponding fields of table i_tab2
from afvv inner join afvc
on afvv~aufpl = afvc~aufpl and afvv~aplzl = afvc~aplzl
for all entries in i_tab1
where afvv~aufpl = i_tab1-aufpl. "条件为以内部表1中的工艺
sort i_tab2 by aufpl aplzl. "将i_tab2排序
* 联结两个透明表:resb,makt;根据内部表2的工艺路线号和计数器
* 将符合条件的记录放入内部表:i_tab3;主要是物料数据
select resb~aufnr resb~matnr resb~bdmng resb~meins
resb~aufpl resb~aplzl resb~stlal resb~vornr
makt~maktx
into corresponding fields of table i_tab3
from resb inner join makt
on resb~matnr = makt~matnr
for all entries in i_tab2
where resb~aufpl = i_tab2-aufpl
and resb~aplzl = i_tab2-aplzl.
* 联结两个透明表:crhd,crtx;根据内部表2的资源的对象ID
* 将符合条件的记录放入内部表:i_tab4;主要是工作中心数据
select crhd~arbpl crhd~objid crtx~ktext
into corresponding fields of table i_tab4
from crhd inner join crtx
on crhd~objid = crtx~objid
for all entries in i_tab2
where crhd~objid = i_tab2-arbid.
endform. " 主程序
*&---------------------------------------------------------------------*
*& Form output_tablehead
*&---------------------------------------------------------------------*
* 输出明细表表头
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form output_tablehead.
write: /3 '产品代码:',i_tab1-matnr,31 '状态:',i_tab1-charg,41
'数量:',i_tab1-gamng left-justified decimals 0,
59 '单位:',i_tab1-gmein,
'生产订单号:',i_tab1-aufnr.
write: /3 '订单开始日期:',i_tab1-ftrmi,31
'订单完成日期:',i_tab1-gltri,70
'工艺路线:',i_tab1-plnnr,'_',i_tab1-plnal.
uline at /2(92).
write: /2 sy-vline,
3 '工序号' color col_heading,
10 sy-vline,
11 '工作中心' color col_heading,
20 sy-vline,
21 '工作中心描述' color col_heading,
45 sy-vline,
46 '计划数' color col_heading,
56 sy-vline,
60 '生产开始日期' color col_heading,
77 sy-vline,
78 '生产完成日期' color col_heading,
93 sy-vline.
uline at /2(92).
endform. " 显示明细表表头部分
*&---------------------------------------------------------------------*
*& Form output_data
*&---------------------------------------------------------------------*
* 输出工作中心明细数据
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form output_data.
sort i_tab1 by aufnr. "按订单号排序 i_tab1
loop at i_tab1.
* 将可选BOM为“DE”的订单在批次编号前加“S”字符,表示“试制”
if i_tab1-stlal = 'DE'.
concatenate 'S' i_tab1-charg into i_tab1-charg.
modify i_tab1.
endif.
sort i_tab2 by aufpl aplzl. "按工作中心排序 i_tab2
loop at i_tab2 where aufpl = i_tab1-aufpl.
* 清除i_tab4的表头记录,防止未指定工作中心时输出前一张订单的数据。
* 这个问题存在于使用read读内部表时,key的条件不成立时不会清表头。
clear i_tab4.
read table i_tab4 with key objid = i_tab2-arbid.
write: /2 sy-vline,
i_tab2-vornr under '工序号',
10 sy-vline,
i_tab4-arbpl under '工作中心',
20 sy-vline,
i_tab4-ktext under '工作中心描述',
45 sy-vline,
i_tab2-mgvrg under '计划数' left-justified decimals 0,
56 sy-vline,
i_tab2-ssavd under '生产开始日期',
77 sy-vline,
i_tab2-ssedd under '生产完成日期',
93 sy-vline.
uline at /2(92).
endloop.
perform frm_detail. "调用“物料明细输出”子程序,输出物料明细
endloop.
endform. " 输出工作中心明细数据
*&---------------------------------------------------------------------*
*& Form frm_detail
*&---------------------------------------------------------------------*
* 物料明细输出
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
form frm_detail.
* '物料需求明细清单'表头:
write: /40 '物料需求明细清单'.
uline at /2(92).
write: /2 sy-vline,
3 '物料代码' color col_heading,
15 sy-vline,
16 '物料描述' color col_heading,
50 sy-vline,
51 '数量' color col_heading,
60 sy-vline,
61 '单位' color col_heading,
65 sy-vline,
66 '使用工作中心' color col_heading,
93 sy-vline.
uline at /2(92).
sort i_tab3 by aufnr matnr.
loop at i_tab3 where aufnr = i_tab1-aufnr. "按同一订单循环
* 循环输出i_tab3中的物料明细数据
* 通过i_tab2搭桥找出i_tab4中的工作中心
clear i_tab2.
clear i_tab4.
read table i_tab2 with key
aufpl = i_tab3-aufpl
aplzl = i_tab3-aplzl.
read table i_tab4 with key objid = i_tab2-arbid.
write: /2 sy-vline,
i_tab3-matnr under '物料代码',
15 sy-vline,
i_tab3-maktx under '物料描述',
50 sy-vline,
i_tab3-bdmng under '数量' left-justified,
60 sy-vline,
i_tab3-meins under '单位',
65 sy-vline,
i_tab4-arbpl under '使用工作中心',
93 sy-vline.
uline at /2(92).
endloop.
skip 57.
endform. " 物料明细输出
*&---------------------------------------------------------------------*
*& Form output_tablehead_m
*&---------------------------------------------------------------------*
* 生产订单表头部分
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form output_tablehead_m.
* 判断给出的查询条件,做输出
if s_5 is initial.
write: /2 '订单日期范围:未输入'.
else.
write: /2 '订单日期范围:',s_5-low,'-',s_5-high.
endif.
if s_3 = ''.
write: /2 '订单号码范围:未输入',80 '单位:PC'.
else.
write: /2 '订单号码范围:',s_3-low,'-',s_3-high,80 '单位:PC'.
endif.
uline at /2(96).
write: /2 sy-vline,
3 '生产订单号' color col_heading,
13 sy-vline,
14 '产品代码' color col_heading,
30 sy-vline,
31 '状态' color col_heading,
35 sy-vline,
36 '数量' color col_heading,
52 sy-vline,
53 '工艺路线' color col_heading,
75 sy-vline,
76 '开始日期' color col_heading,
86 sy-vline,
87 '完成日期' color col_heading,
97 sy-vline.
uline at /2(96).
endform. " 生产订单表头部分
*&---------------------------------------------------------------------*
*& Form output_data_M
*&---------------------------------------------------------------------*
* 只输出生产订单,不包含明细
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form output_data_m.
sort i_tab1 by aufnr.
loop at i_tab1.
* 将可选BOM为“DE”的订单在批次编号前加“S”字符,表示“试制”
if i_tab1-stlal = 'DE'.
concatenate 'S' i_tab1-charg into i_tab1-charg.
endif.
write: /2 sy-vline,
i_tab1-aufnr under '生产订单号',
13 sy-vline,
i_tab1-matnr under '产品代码',
30 sy-vline,
i_tab1-charg under '状态',
35 sy-vline,
i_tab1-gamng under '数量' decimals 0,
52 sy-vline,
i_tab1-plnnr,'_',i_tab1-plnal,
75 sy-vline,
i_tab1-ftrmi under '开始日期',
86 sy-vline,
i_tab1-gltrp under '完成日期',
97 sy-vline.
uline at /2(96).
at last.
sum.
write: /2 sy-vline,
'合计' color col_total,
35 sy-vline,
i_tab1-gamng under '数量' decimals 0 color col_total,
52 sy-vline,
97 sy-vline.
uline at /2(96).
endat.
endloop.
skip 57.
endform. " 输出生产订单
原文地址:http://blog.chinaunix.net/uid-9907184-id-1995964.html