一、自定义表结构
二、生产工单出口增强
三、查询报表
一、自定义表结构
表ZPCO02
MANDT MANDT CLNT 3 0 客户端
AUFNR AUFNR CHAR 12 0 订单号
MATNR MATNR CHAR 18 0 物料号
FILED FIELDNAME CHAR 30 0 字段名
AENAM AENAM CHAR 12 0 对象更改人员的名称
LAEDA LAEDA DATS 8 0 上次更改的日期
TCODE TCODE CHAR 20 0 事务代码
CHNID CDCHNGIND CHAR 1 0 修改类型 (U, I, E, D)
HOSTIP CHAR20 CHAR 20 0 字符 20
HOST MSHOST2 CHAR 32 0 Name of Application Server
VALUE_OLD CHAR20 CHAR 20 0 字符 20
VALUE_NEW CHAR20 CHAR 20 0 字符 20
TIMES CDUZEIT TIMS 6 0 时间已更改
LOOPID SYTABIX INT4 10 0
ALPOS ALPOS CHAR 1 0 指示符:替代项目
STTXT CO_STTXT CHAR 40 0 系统状态
BDMNG BDMNG QUAN 13 3 需求量
二、生产工单出口增强
PPCO0001
EXIT_SAPLCOBT_001
ZXCO1U01
check sy-tcode ne 'CO01'.
*&保存工单更改的历史记录
tables:caufv,resb.
data: begin of old_resb occurs 0, "更改后未保存之RESB.
aufnr like resb-aufnr,
posnr like resb-posnr,
matnr like resb-matnr,
rsnum like resb-rsnum,
rspos like resb-rspos,
xloek like resb-xloek,
bdmng like resb-bdmng,
objnr like resb-objnr,
lgort like resb-lgort,
end of old_resb.
data: begin of new_resb occurs 0. "数据库中的RESB.
include structure old_resb.
data: end of new_resb.
data: begin of obj_resb occurs 0. "插入的RESB
include structure old_resb.
data: end of obj_resb.
data: i_zpco02 like zpco02 occurs 0 with header line.
data: i_temp like zpco02 occurs 0 with header line.
data: iporg like msxxlist-hostadr,
ipdec(16) type c,
host(18) type c.
data: char1(20) type c,
char2(20) type c.
data: licl type c.
data: inst_flg type c value 'N',
chan_had type c value 'N'.
* teco_flg TYPE c VALUE 'N',
* read_flg TYPE c .
data: l_str type string.
data: i_msgty like sy-msgty.
data: tabix like sy-tabix.
*BREAK-POINT.
clear: i_temp, iporg, ipdec, host.
** Get user IP,hostname
call function 'TH_USER_INFO' " Get user IP,hostname
exporting
client = sy-mandt
user = sy-uname
importing
hostaddr = iporg
terminal = host
exceptions
others = 1.
**"Conv.IP addr to format 'xxx.xxx.xxx.xxx'
call function 'GWY_IPADR2STRING' "Conv.IP addr
exporting
ipadr = iporg
importing
string = ipdec.
***Common var.
move: sy-mandt to i_temp-mandt,
sy-uname to i_temp-aenam,
sy-datum to i_temp-laeda,
sy-uzeit to i_temp-times,
sy-tcode to i_temp-tcode,
ipdec to i_temp-hostip,
host to i_temp-host,
* { INCERT
header_table-sttxt to i_temp-sttxt, "工单状态
* INCERT } DEVK905414 ADD:工单状态取值
header_table-aufnr to i_temp-aufnr.
***Check M/O header
select single gamng gltrp gstrp into (caufv-gamng, caufv-gltrp,caufv-gstrp)
from caufv where aufnr eq header_table-aufnr.
**qty
if header_table-gamng ne caufv-gamng.
move: caufv-gamng to char1, header_table-gamng to char2.
move-corresponding i_temp to i_zpco02.
move: '更改工单总数' to i_zpco02-filed,
'U' to i_zpco02-chnid,
char1 to i_zpco02-value_old,
char2 to i_zpco02-value_new.
append i_zpco02.
inst_flg = 'Y'.
chan_had = 'Y'.
endif.
**增加开始日期修改记录(MODIFY BY LU.X 2010.09.26)
if header_table-gstrp ne caufv-gstrp.
move-corresponding i_temp to i_zpco02.
move: '更改开始时间' to i_zpco02-filed,
'U' to i_zpco02-chnid,
caufv-gstrp to i_zpco02-value_old,
header_table-gstrp to i_zpco02-value_new.
append i_zpco02.
inst_flg = 'Y'.
endif.
if header_table-gltrp ne caufv-gltrp.
move-corresponding i_temp to i_zpco02.
move: '更改完成时间' to i_zpco02-filed,
'U' to i_zpco02-chnid,
caufv-gltrp to i_zpco02-value_old,
header_table-gltrp to i_zpco02-value_new.
append i_zpco02.
inst_flg = 'Y'.
endif.
if inst_flg = 'Y'.
insert zpco02 from table i_zpco02 accepting duplicate keys.
inst_flg = 'N'.
endif.
loop at component_table where vbkz eq 'U'
or vbkz eq 'I'
or vbkz eq 'D'.
clear licl.
case component_table-vbkz.
when 'I'.
move-corresponding i_temp to i_zpco02.
move: '新增组件' to i_zpco02-filed,
'I' to i_zpco02-chnid,
'' to i_zpco02-value_old, "old_resb-matnr
component_table-matnr to i_zpco02-value_new,
'新增的组件' to i_zpco02-matnr,
* read_flg TO i_zpco02-readf,
component_table-alpos to i_zpco02-alpos,
component_table-bdmng to i_zpco02-bdmng,
sy-tabix to i_zpco02-loopid.
append i_zpco02.
inst_flg = 'Y'.
when 'D'.
move-corresponding i_temp to i_zpco02.
move: '删除组件' to i_zpco02-filed,
'D' to i_zpco02-chnid,
resb-xloek to i_zpco02-value_old,
component_table-xloek to i_zpco02-value_new,
component_table-matnr to i_zpco02-matnr,
* read_flg TO i_zpco02-readf,
component_table-alpos to i_zpco02-alpos,
sy-tabix to i_zpco02-loopid.
append i_zpco02.
inst_flg = 'Y'.
when 'U'.
* { INCERT
if component_table-xloek is not initial.
* { INCERT
search i_temp-sttxt for 'TECO'.
case sy-subrc.
when 4.
* } DEVK910121
move-corresponding i_temp to i_zpco02.
move: '删除组件' to i_zpco02-filed,
'D' to i_zpco02-chnid,
resb-xloek to i_zpco02-value_old,
component_table-xloek to i_zpco02-value_new,
component_table-matnr to i_zpco02-matnr,
* read_flg TO i_zpco02-readf,
component_table-alpos to i_zpco02-alpos,
sy-tabix to i_zpco02-loopid.
append i_zpco02.
inst_flg = 'Y'.
* { INCERT
endcase.
* } DEVK910121 忽略由工单关闭引起的组件删除
else.
* INCERT } DEVK905414 FIX BUG:删除组件无记录
select single matnr bdmng lgort into (resb-matnr, resb-bdmng,resb-lgort)
from resb where aufnr eq component_table-aufnr
and posnr eq component_table-posnr
and matnr eq component_table-matnr
and rsnum eq component_table-rsnum
and rspos eq component_table-rspos.
if component_table-matnr ne resb-matnr.
move-corresponding i_temp to i_zpco02.
move: '更改组件' to i_zpco02-filed,
'U' to i_zpco02-chnid,
resb-matnr to i_zpco02-value_old,
component_table-matnr to i_zpco02-value_new,
'更改的工单组件' to i_zpco02-matnr,
* read_flg TO i_zpco02-readf,
component_table-alpos to i_zpco02-alpos,
sy-tabix to i_zpco02-loopid.
append i_zpco02.
inst_flg = 'Y'.
elseif component_table-bdmng ne resb-bdmng.
* { DELETE
* CHECK chan_had NE 'Y'.
* DELETE } DEVK905414 FIX BUG:抬头数量修改引起的组件数量修改无记录
move: component_table-bdmng to char1, resb-bdmng to char2.
move-corresponding i_temp to i_zpco02.
move: '需求数量' to i_zpco02-filed,
'U' to i_zpco02-chnid,
char2 to i_zpco02-value_old,
char1 to i_zpco02-value_new,
component_table-matnr to i_zpco02-matnr,
* read_flg TO i_zpco02-readf,
component_table-alpos to i_zpco02-alpos,
sy-tabix to i_zpco02-loopid.
append i_zpco02.
inst_flg = 'Y'.
* wangkai 发料仓库变更的记录
elseif component_table-lgort ne resb-lgort .
move: component_table-lgort to char1, resb-lgort to char2.
move-corresponding i_temp to i_zpco02.
move: '发料仓库' to i_zpco02-filed,
'U' to i_zpco02-chnid,
char2 to i_zpco02-value_old,
char1 to i_zpco02-value_new,
component_table-matnr to i_zpco02-matnr,
* read_flg TO i_zpco02-readf,
component_table-alpos to i_zpco02-alpos,
sy-tabix to i_zpco02-loopid.
append i_zpco02.
inst_flg = 'Y'.
* { INCERT
endif.
* INCERT } DEVK905414
endif.
endcase.
endloop.
if inst_flg = 'Y'.
insert zpco02 from table i_zpco02 accepting duplicate keys.
if sy-subrc eq 0.
inst_flg = 'N'.
chan_had = 'N'.
free: i_zpco02.
clear: i_temp.
endif.
endif.
三、查询报表
REPORT ZCOHS.
tables: zpco02, afko.
data: i_zpco02 like zpco02 occurs 0 with header line.
data: i_clear like zpco02 occurs 0 with header line.
*data: i_aufnr
selection-screen begin of block block1 with frame. title text-001 .
select-options s_aufnr for afko-aufnr."生产订单
*SELECT-OPTIONS s_matnr FOR ZPCO02-MATNR.
select-options s_aenam for zpco02-aenam."更改者
select-options s_laeda for zpco02-laeda modif id gp2."修改日期
"PARAMETERS: p_clear AS CHECKBOX MODIF ID gp1.
selection-screen end of block block1 .
top-of-page.
perform. write_header.
at selection-screen output.
loop at screen.
if screen-group1 = 'GP1'.
screen-intensified = '1'.
modify screen.
continue.
endif.
endloop.
*&---------------------------------------------------------------------*
*& Event START-OF-SELECTION
*&---------------------------------------------------------------------*
start-of-selection.
perform. get_data.
*&---------------------------------------------------------------------*
*& Event END-OF-SELECTION
*&---------------------------------------------------------------------*
end-of-selection.
perform. report_output.
form. get_data .
select zpco02~mandt zpco02~aufnr zpco02~matnr zpco02~filed zpco02~aenam zpco02~laeda zpco02~tcode
zpco02~chnid zpco02~hostip zpco02~host zpco02~value_old zpco02~value_new zpco02~times zpco02~loopid
zpco02~alpos zpco02~sttxt zpco02~bdmng
into corresponding fields of table i_zpco02
from zpco02
inner join afpo on zpco02~aufnr = afpo~aufnr
where afpo~posnr = 1
and afpo~elikz = ''
and zpco02~aufnr in s_aufnr
and zpco02~aenam in s_aenam
and zpco02~laeda in s_laeda
.
check i_zpco02[] is initial or sy-subrc eq 4.
message id 'ZX' type 'S'
number '000' with '没有找到数据'.
endform. " get_data
*&---------------------------------------------------------------------*
*& Form write_header
*&---------------------------------------------------------------------*
form. write_header .
data: l_pos1 type i,
l_pos2 type i,
l_pos3 type i,
l_title(33) type c value '工单更改历史记录'.
* CONCATENATE l_title v_bom_til INTO l_title.
l_pos1 = sy-linsz / 2 - 15.
l_pos2 = sy-linsz - 15.
l_pos3 = l_pos2 + 6.
skip 2.
write /l_pos1 l_title.
uline at /l_pos1(16).
skip.
write at: /(11) '生产订单',
(16) '组件/表头',
(16) '更改动作',
(20) '新字段值',
(20) '旧字段值',
(08) '替代',
(08) '需求数',
(08) '更改帐号',
(15) '更改者IP',
(10) '更改者PC',
(10) '更改日期',
(10) '更改时间',
* { INCERT
(35) '工单状态'.
* INCERT } DEVK910078
uline.
endform. " write_header
*&---------------------------------------------------------------------*
*& Form report_output
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form. report_output .
* { REPLACE
* SORT i_zpco02 BY aufnr aenam laeda.
sort i_zpco02 by aufnr laeda times matnr.
* REPLACE } DEVK910078
data qty(13) type c .
loop at i_zpco02.
write at: /(11) i_zpco02-aufnr , " '生产订单',
(16) i_zpco02-matnr , " '物料号码',
(16) i_zpco02-filed . " '更改动作',
* { INCERT
set left scroll-boundary.
* INCERT } DEVK910078
if i_zpco02-filed = '新增组件' .
qty = i_zpco02-bdmng .
else .
qty = ''.
endif .
write at: (20) i_zpco02-value_new
color 2, " '新字段值',
(20) i_zpco02-value_old
color 3, " '旧字段值',
(08) i_zpco02-alpos
color 4,
(08) qty
color 5, " '需求数'
(08) i_zpco02-aenam , " '更改帐号',
(15) i_zpco02-hostip , " '更改者IP',
(10) i_zpco02-host , " '更改者PC',
(10) i_zpco02-laeda , " '更改日期',
(10) i_zpco02-times , " '更改时间'.
(35) i_zpco02-sttxt. "'工单状态'.
endloop.
endform. " report_output