ZLU_IDOCASSURE. Собирает статистику по необработанным документам и помещает ее в табличку ZLU_IDOCASSURE
Code:
*&---------------------------------------------------------------------*
*& Report ZLU_IDOCASSURE *
*& *
*&---------------------------------------------------------------------*
*& Idocs maintance preparation. Build statistics table *
*& Have to be scheduled to run once or twice a day to get fresh info *
*&---------------------------------------------------------------------*
report zlu_idocassure .
tables:
zlu_idocassure.
constants:
failed type i value 51,
inbound type i value 2.
types:
begin of t_repa,
docnum type edidc-docnum,
end of t_repa,
begin of t_reps,
docnum type edidc-docnum,
stamid type edids-stamid,
stamno type edids-stamno,
qty type i,
countr type edids-countr,
statxt type edids-statxt,
mestyp type edidc-mestyp,
stapa1 type edids-stapa1,
stapa2 type edids-stapa2,
stapa3 type edids-stapa3,
stapa4 type edids-stapa4,
end of t_reps.
data: wa type t_repa,
ws type t_reps,
wx type t_reps,
it_stat type t_reps occurs 1000 with header line,
itrows type i.
select-options:
s_mestyp for ws-mestyp.
new-page line-size 200.
select t_00~docnum
t_00~mestyp
max( t_01~countr ) as countr
count( * ) as qty
into corresponding fields of table it_stat
from edidc as t_00
join edids as t_01
on
t_01~mandt = t_00~mandt
and t_00~docnum = t_01~docnum
and t_00~status = t_01~status
where t_00~mandt = sy-mandt
and t_00~status = failed
and ( t_00~direct = inbound )
group by t_00~docnum t_00~mestyp.
delete from zlu_idocassure
where mestyp in s_mestyp.
describe table it_stat lines itrows.
if itrows > 0.
select * from edids
into corresponding fields of ws
for all entries in it_stat
where docnum eq it_stat-docnum
and countr eq it_stat-countr.
move-corresponding ws to zlu_idocassure.
* read mestyp field value
read table it_stat into wx
with key docnum = ws-docnum.
zlu_idocassure-mestyp = wx-mestyp.
modify zlu_idocassure.
write:/ ws-docnum, ws-stamid, ws-stamno, ws-statxt, ws-countr,
wx-mestyp.
endselect.
endif.
ZLU_IDOCMAIN. Интерфейс к табличке с функциями доп. обработки документов.
Code:
*&---------------------------------------------------------------------*
*& Report ZLU_IDOCMAIN *
*& *
*&---------------------------------------------------------------------*
*& IDOC maintance. Statistics, reprocess and set 'do not touch' status *
*& *
*&---------------------------------------------------------------------*
report zlu_idocmain .
constants:
batchsize type i value 500,
idocfailed type i value 51,
idocchanged type i value 69.
tables:
edidc,
mara,
mard.
types:
begin of trep,
docnum type edidc-docnum,
stamid type edids-stamid,
stamno type edids-stamno,
qty type i,
countr type edids-countr,
statxt type edids-statxt,
mestyp type edidc-mestyp,
stapa1 type edids-stapa1,
stapa2 type edids-stapa2,
stapa3 type edids-stapa3,
stapa4 type edids-stapa4,
end of trep.
data:
wa type trep
, wd type trep
, it type standard table of trep with header line
, stamp(1) type c
, rows type i
, items type i
, flush type i
.
select-options s_mestyp for wa-mestyp.
set pf-status 'MAI_MNU'.
data:
it_docnum type standard table of edidc-docnum with header line.
select asu~mestyp asu~stamid asu~stamno asu~statxt count( * ) as qty
into corresponding fields of table it
from zlu_idocassure as asu
join edidc as edc
on asu~docnum = edc~docnum
where asu~mestyp in s_mestyp
and ( edc~status = idocfailed )
group by asu~mestyp asu~stamid asu~stamno asu~statxt.
select status count( * ) as qty
into corresponding fields of wa
from edidc
where status = idocchanged
group by status
.
it-mestyp = 'CHANGED'.
it-qty = wa-qty.
append it.
endselect.
sort it by mestyp qty descending.
data: prevmsgtyp type edidc-mestyp.
prevmsgtyp = ''.
loop at it into wa.
if wa-mestyp ne prevmsgtyp.
prevmsgtyp = wa-mestyp.
skip.
endif.
write:/ stamp as checkbox, wa-mestyp, wa-statxt, wa-qty.
hide: wa-mestyp, wa-stamid, wa-stamno, wa-statxt.
endloop.
rows = sy-linno.
at user-command.
data:
fil_docnum type bdrg_doc_tab,
fd_entry type bdrg_doc,
fil_docnum2 type bdrg_doc_tab,
fd_entry2 type bdrg_doc,
s_docnum type bdrg_doc_tab,
s_docnum_entry type bdrg_doc,
s_credat type bdrg_doc_tab,
s_credat_entry type bdrg_doc,
jobname type tbtcjob-jobname,
jobnumber type tbtcjob-jobcount.
refresh fil_docnum.
fd_entry-sign = 'I'.
fd_entry-option = 'EQ'.
stamp = space.
do rows times.
read line sy-index field value stamp.
skip.
if stamp = 'X'.
select * from zlu_idocassure
into corresponding fields of wd
where mestyp = wa-mestyp
and stamid = wa-stamid
and stamno = wa-stamno.
fd_entry-low = wd-docnum.
append fd_entry to fil_docnum.
endselect.
endif.
enddo.
case sy-ucomm.
when 'CHOOSE'.
perform show_details.
when 'PROCESS'.
submit rbdmani2
with so_docnu in fil_docnum
via selection-screen and return.
when 'DISABLE'.
submit zidoc_change_status
with s_docnum in fil_docnum
via selection-screen and return.
when 'MASS'.
describe table fil_docnum lines items.
if items > 10.
jobname = 'make idoc storno'.
call function 'JOB_OPEN'
exporting
jobname = jobname
importing
jobcount = jobnumber.
if sy-subrc ne 0.
write:/ 'job create failed ', sy-subrc.
else.
flush = 0.
loop at fil_docnum into fd_entry2.
append fd_entry2 to fil_docnum2.
add 1 to flush.
if flush eq batchsize.
perform [censored].
flush = 0.
endif.
endloop.
if flush > 0.
perform [censored].
endif.
endif.
else.
write:/ 'not enough rows'.
endif.
when 'SHOWIDOC'.
get cursor line sy-lilli.
read line sy-lilli field value wd-docnum.
refresh s_credat.
refresh s_docnum.
s_docnum_entry-sign = 'I'.
s_docnum_entry-option = 'EQ'.
s_docnum_entry-low = wd-docnum.
append s_docnum_entry to s_docnum.
submit rseidoc2
with docnum in s_docnum
with credat in s_credat
and return.
when 'STOCK'.
call transaction 'MB1B'.
endcase.
at line-selection.
perform show_details.
*&--------------------------------------------------------------------*
*& Form [censored]
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
form [censored].
submit zidoc_change_status
with s_docnum in fil_docnum2
with p_update eq 'X'
user sy-uname
via job jobname number jobnumber
and return.
refresh fil_docnum2.
endform. "[censored]
*&--------------------------------------------------------------------*
*& Form show_details
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
form show_details.
new-page line-size 400.
set pf-status 'DET_MNU'.
stamp = space.
do rows times.
read line sy-index field value stamp.
new-page.
if stamp = 'X'.
write:/ '>', wa-mestyp, wa-statxt.
select * from zlu_idocassure
join edidc
on zlu_idocassure~docnum = edidc~docnum
into corresponding fields of wd
where zlu_idocassure~mestyp = wa-mestyp
and zlu_idocassure~stamid = wa-stamid
and zlu_idocassure~stamno = wa-stamno
and edidc~status = 51.
data: stuff1 type string,
stuff2 type string,
stuff3 type string,
stuff4 type string,
stuff0 type string.
stuff0 = wd-statxt.
stuff1 = wd-stapa1.
stuff2 = wd-stapa2.
stuff3 = wd-stapa3.
stuff4 = wd-stapa4.
write:/ wd-docnum, stuff0, stuff1, stuff2, stuff3, stuff4.
hide: wd-docnum.
if wa-stamid = 'M7' and wa-stamno = '021'.
constants:
c_zero type mara-matnr value '000000000000000000'.
data:
wa_matnr like mara-matnr,
wa_lgort like mard-lgort,
wa_werks like mard-werks,
stuff(50) type c .
shift wd-stapa4 by 2 places.
split wd-stapa4 at ' ' into wa_matnr stuff.
shift wa_matnr right deleting trailing space.
overlay wa_matnr with c_zero.
split stuff at ' ' into wa_werks stuff.
split stuff at ' ' into wa_lgort stuff.
select * from mard
where matnr = wa_matnr
and ( lgort <> wa_lgort or werks <> wa_werks )
and ( labst > 0 or speme > 0 or insme > 0 ).
stuff1 = mard-matnr + 0.
write:/ ' * HAVE * '.
write: mard-lgort, stuff1, ':'.
write: mard-labst, mard-speme, mard-insme.
endselect.
endif.
endselect.
endif.
enddo.
endform. "show_details
основная идея - обеспечить возможность разделения по типам ошибок и обработки большого количества документов (до 300000 работает без проблем). классификация ошибок позволяет разбить документы на ошибки ввода (например, изменен и не деблокирован заказ на закупку, в то время как поставка уже подтверждается idoc-ом) или не введен номер склада для ПМ, ошибки блокирования основных записей (потребуется повторная обработка чуть позже), косяки (типа подтверждение отгрузки по отсутствующим поставкам) и т.д.
насчет уведомлений по обработке документов - это отдельная песня. по rfc с презентационной машины выполняется соединение с sap, выгружается табличка zlu_idocassure, форматируется в html и отправляется по почте (обычной) админу. помимо нее выгружаются данные по периодическим работам и доп. служебная информация для облегчения разбора полетов. думаю, что можно сделать и проще, но у нас есть серьезные ограничения на использование возможностей sap, типа невозможности отправки почты непосредственно из него.