|
|
发表于 2008/12/25 21:09:39
|
显示全部楼层
看了這么多,偶也是新人,不過還好找到這么好的論壇,心裡終於有底了。。嘿嘿。我也献丑,发下刚完成的ALERT的程式,BOM与WIP工单用料不一致警示。代码可能太过累赘,还请见谅。
SELECT a.org, a.job_no, a.primary_item_no, a.item_no, a.item_id,
a.primary_item_id,
(SELECT COUNT (*)
FROM bom_bill_of_materials bom,
bom_inventory_components bic
WHERE bic.bill_sequence_id = bom.bill_sequence_id
AND bom.assembly_item_id = a.primary_item_id
AND bic.component_item_id = a.item_id) bom_count,
(SELECT COUNT (*)
FROM wip_entities we, wip_requirement_operations wro
WHERE we.wip_entity_id = wro.wip_entity_id
AND we.wip_entity_name = a.job_no
AND we.primary_item_id = a.primary_item_id
AND wro.inventory_item_id = a.item_id) wip_count,
TO_CHAR (SYSDATE-1, 'yyyy-mm-dd') date1
--into &org , &job_no ,&primary_item_no, &item_no , &item_id , &primary_item_id, &bom_count , &wip_count ,&date1
FROM ((SELECT DISTINCT DECODE (wro.organization_id,
47, 'JPD',
48, 'PPD',
49, 'SYS',
95, 'PCD'
) org,
we.wip_entity_name job_no,
msi1.segment1 primary_item_no,
msi.segment1 item_no,
wro.inventory_item_id item_id,
we.primary_item_id primary_item_id
FROM wip_entities we,
wip_requirement_operations wro,
wip_discrete_jobs wdj,
mtl_system_items_b msi,
mtl_system_items_b msi1
WHERE we.wip_entity_id = wdj.wip_entity_id
AND we.wip_entity_id = wro.wip_entity_id
AND wdj.job_type = 1
AND wdj.status_type IN (12)
AND we.organization_id = wro.organization_id
AND msi.organization_id = wro.organization_id
AND msi.inventory_item_id = wro.inventory_item_id
AND msi1.organization_id = wro.organization_id
AND msi1.inventory_item_id = we.primary_item_id
AND wro.wip_supply_type = 1
AND substr(we.wip_entity_name,1,1) not like 'P'
AND TRUNC (wdj.last_update_date) = TRUNC (SYSDATE) - 1
AND ASCII (SUBSTR (msi1.segment1, 1, 1)) BETWEEN ASCII
('A')
AND ASCII
('Z'))
UNION
(SELECT DISTINCT DECODE (wro.organization_id,
47, 'JPD',
48, 'PPD',
49, 'SYS',
95, 'PCD'
) org,
we.wip_entity_name job_no,
msii2.segment1 primary_item_no,
msii.segment1 item_no,
bic.component_item_id item_id,
we.primary_item_id primary_item_id
FROM wip_entities we,
wip_requirement_operations wro,
wip_discrete_jobs wdj,
bom_bill_of_materials bom,
bom_inventory_components bic,
mtl_system_items msii,
mtl_system_items msii2
WHERE we.wip_entity_id = wro.wip_entity_id
AND wdj.wip_entity_id = we.wip_entity_id
AND TRUNC (wdj.last_update_date) = TRUNC (SYSDATE) - 1
AND wdj.job_type = 1
AND wdj.status_type IN (12)
AND bom.assembly_item_id = we.primary_item_id
AND bic.bill_sequence_id = bom.bill_sequence_id
AND we.organization_id = msii.organization_id
AND msii.inventory_item_id = bic.component_item_id
AND TO_CHAR (NVL (bic.disable_date, SYSDATE), 'yyyymmdd') >
TO_CHAR (SYSDATE - 1, 'YYYYMMDD')
AND msii2.organization_id = we.organization_id
AND msii2.inventory_item_id = we.primary_item_id
AND substr(we.wip_entity_name,1,1) not like 'P'
AND ASCII (SUBSTR (msii2.segment1, 1, 1))
BETWEEN ASCII ('A')
AND ASCII ('Z'))) a
WHERE (SELECT COUNT (*)
FROM bom_bill_of_materials bom, bom_inventory_components bic
WHERE bic.bill_sequence_id = bom.bill_sequence_id
AND bom.assembly_item_id = a.primary_item_id
AND bic.component_item_id = a.item_id) <= 0
OR (SELECT COUNT (*)
FROM wip_entities we, wip_requirement_operations wro
WHERE we.wip_entity_id = wro.wip_entity_id
AND we.wip_entity_name = a.job_no
AND we.primary_item_id = a.primary_item_id
AND wro.inventory_item_id = a.item_id) <= 0 |
|