text SAP API查询 - 带有Measurement Docs脚本的工作订单
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text SAP API查询 - 带有Measurement Docs脚本的工作订单相关的知识,希望对你有一定的参考价值。
BEGIN
OPEN :rcursor FOR
WITH
SubQuery1 AS
(select
ValidEquipWithObjnr.tplnr,
ValidEquipWithObjnr.objnr,
ValidEquipWithObjnr.iloan,
ValidEquipWithObjnr.equnr,
ValidEquipWithObjnr.datab,
ValidEquipWithObjnr.datbi,
ValidEquipWithObjnr.aedat,
ValidStats.stat
from
(select
ValidEquip.tplnr,
equi.objnr,
ValidEquip.iloan,
ValidEquip.equnr,
ValidEquip.datab,
ValidEquip.datbi,
ValidEquip.aedat
from
(select iloa.tplnr, iloa.iloan, equz.equnr, equz.datab, equz.datbi, equz.aedat from
sapsr3.iloa@prd
inner join
sapsr3.equz@prd
on iloa.iloan = equz.iloan
where (equz.equnr is not null and equz.equnr not like ' ')
and (iloa.tplnr is not null and iloa.tplnr not like ' ')) ValidEquip
inner join
sapsr3.equi@prd
on ValidEquip.equnr = equi.equnr) ValidEquipWithObjnr
inner join
-- Select only those active equipment with only one status, and that status is 'I0100' or 'I0116' (i.e. system status of INST or ASEQ, respectively)
(select EquipWithOneStatus.objnr, fullJestTable.stat from
-- Select only those active equipment with only one status (either system status or user status)
(select objnr, count(objnr) from
-- Select all active equipment (note that the JEST table is confirmed to contains all equipment like the EQUI table)
(select objnr, stat from sapsr3.jest@prd
where (objnr like 'IE%' and objnr not like 'IEI%' and objnr not like 'IEPR%')
and (inact not like 'X')
order by OBJNR asc)
group by objnr
having count(objnr)=1) EquipWithOneStatus
inner join sapsr3.jest@prd fullJestTable on EquipWithOneStatus.objnr = fullJestTable.objnr
where (fullJestTable.stat like 'I0100' or fullJestTable.stat like 'I0116') and fullJestTable.inact not like 'X'
order by EquipWithOneStatus.objnr asc) ValidStats
on ValidEquipWithObjnr.objnr = ValidStats.objnr),
Q1_AllFLsWithCurrentEquip AS
(select
*
from (
select
SubQuery1.tplnr,
SubQuery1.objnr,
SubQuery1.iloan,
SubQuery1.equnr,
SubQuery1.datab,
SubQuery1.datbi,
SubQuery1.aedat,
SubQuery1.stat,
RANK() OVER (partition by SubQuery1.equnr order by SubQuery1.aedat desc) aedat_rank
from SubQuery1
) where aedat_rank = 1
and (TO_CHAR(SYSDATE, 'YYYYMMDD') >= datab and TO_CHAR(SYSDATE, 'YYYYMMDD') <= datbi)
and equnr not like 'I%'),
SubQuery2 AS
-- Get Maintenance Plan details for the Object List records (probably not needed)
(select FinalOLs.obknr, FinalOLs.objvw, FinalOLs.iloan, FinalOLs.equnr, FinalOLs.ihnum, FinalOLs.bautl, FinalOLs.tplnr, mpos.wapos, mpos.warpl, mpos.wppos, mpos.pstxt from
-- Like with the equipment numbers below, attach the Fun Loc for those records with a Notification Number. We should now have a complete list of Object Lists with equipment numbers and/or Fun Locs, where found
(select EquipFromNotifNos.obknr, EquipFromNotifNos.objvw, EquipFromNotifNos.iloan, EquipFromNotifNos.AllOLs_equnr||EquipFromNotifNos.NotifNums_equnr equnr, EquipFromNotifNos.ihnum, EquipFromNotifNos.bautl, EquipFromNotifNos.AllOLs_tplnr||FLsFromNotifNos.tplnr tplnr from
-- Those Object List records with a Notifiction Number generally have a Equipment number attached, so lets grab
(select AllOLs.obknr, AllOLs.objvw, AllOLs.iloan, AllOLs.equnr AllOLs_equnr, AllOLs.ihnum, AllOLs.bautl, AllOLs.tplnr AllOLs_tplnr, NotifNums.equnr NotifNums_equnr from
-- Attach Fun Locs to the Object Lists
(select AllOLsNoFLs.obknr, AllOLsNoFLs.objvw, AllOLsNoFLs.iloan, AllOLsNoFLs.equnr, AllOLsNoFLs.ihnum, AllOLsNoFLs.bautl, FLsWithILOAN.tplnr from
-- Select ALL Object Lists, both PM Order and Maintenance Item types, though in reality we are only interested in PM Order types as these are what are assigned to Work Orders
(select
obknr,
iloan,
(case objvw when 'A' then 'PM order'
when 'W' then 'Maintenance item'
end) objvw,
equnr,
ihnum,
bautl
from sapsr3.objk@prd) AllOLsNoFLs
left join
(select
tplnr,
iloan
from sapsr3.iloa@prd) FLsWithILOAN
on AllOLsNoFLs.iloan = FLsWithILOAN.iloan) AllOLs
left join
(select
qmnum,
equnr
from
sapsr3.afih@prd
where qmnum not like ' ' and qmnum is not null and equnr not like ' ' and equnr is not null) NotifNums
on AllOLs.ihnum = NotifNums.qmnum) EquipFromNotifNos
left join
(select qmih.qmnum, iloa.tplnr from
sapsr3.qmih@prd
inner join
sapsr3.iloa@prd
on qmih.iloan = iloa.iloan) FLsFromNotifNos
on EquipFromNotifNos.ihnum = FLsFromNotifNos.qmnum) FinalOLs
left join
sapsr3.mpos@prd
on FinalOLs.obknr = mpos.obknr),
Q2_AllOLsWithWOs AS
-- Results of "SubQuery2" with a WO number. This is to be appended to the results of "Q3_AllWOs"
(select afih.aufnr, SubQuery2.obknr, SubQuery2.objvw, SubQuery2.iloan, SubQuery2.equnr, SubQuery2.ihnum, SubQuery2.bautl, SubQuery2.tplnr, SubQuery2.wapos, SubQuery2.warpl, SubQuery2.wppos, SubQuery2.pstxt
from sapsr3.afih@prd
inner join SubQuery2
on afih.obknr = SubQuery2.obknr),
SubQuery3 AS
-- Select ALL Work Orders
-- AFIH by default contains all work orders that are not in a historical status (i.e. IPHAS != 5)
(select
afih.aufnr,
afih.obknr,
afih.iloan,
iloa.tplnr,
afih.equnr,
afih.qmnum,
afih.addat,
afih.gewrk,
afih.iphas
from sapsr3.afih@prd
left join
sapsr3.iloa@prd
on afih.iloan = iloa.iloan),
Q3_FilteredOilSampleWOs AS
(select
FilteredOilSampleWOs.WO_aufnr,
FilteredOilSampleWOs.WO_iloan,
FilteredOilSampleWOs.WO_obknr,
FilteredOilSampleWOs.WO_qmnum,
FilteredOilSampleWOs.WO_tplnr,
FilteredOilSampleWOs.WO_equnr,
FilteredOilSampleWOs.WO_period,
FilteredOilSampleWOs.WO_iphas,
AllActualOrderCosts.WO_TotalActualCosts,
FilteredOilSampleWOs.WO_objnr,
FilteredOilSampleWOs.WO_ktext
from
-- Filter on only those below filtered work orders for those with "oil sample" (case insensitive) in the description
(select
FilteredWOs.WO_aufnr,
FilteredWOs.WO_iloan,
FilteredWOs.WO_obknr,
FilteredWOs.WO_qmnum,
FilteredWOs.WO_tplnr,
FilteredWOs.WO_equnr,
FilteredWOs.WO_period,
FilteredWOs.WO_iphas,
aufk.objnr WO_objnr,
aufk.ktext WO_ktext
from
-- With all the WOs from of "SubQuery3", filter it down to only those valid closed Work Orders
-- i.e. select all Work Orders that match the following conditions:
-- those "completed" work orders (i.e. IPHAS == 3 or 6) (note: "historical" work orders had already been excluded - see "Q3_AllWOs")
-- and those without a notif. num
-- and main work cent not 406 (these are "analysis" WCs)
(select
SubQuery3.aufnr WO_aufnr,
SubQuery3.iloan WO_iloan,
SubQuery3.obknr WO_obknr,
SubQuery3.qmnum WO_qmnum,
SubQuery3.tplnr WO_tplnr,
SubQuery3.equnr WO_equnr,
nvl(decode(SubQuery3.addat,'00000000',to_date('01/01/1900','dd/mm/yyyy'),to_date(SubQuery3.addat,'yyyymmdd')),to_date('01/01/1900','dd/mm/yyyy')) WO_period,
(case SubQuery3.iphas when '3' then 'TECO Technically completed' -- Should this be ignored?
when '6' then 'CLSD Closed'
end) WO_iphas
from
SubQuery3
where
(SubQuery3.iphas like '3' -- Should this be ignored?
or SubQuery3.iphas like '6')
and SubQuery3.gewrk not like '10000380' -- 10000380 == main work cent. 406
and (SubQuery3.qmnum like ' ' or SubQuery3.qmnum is null)
and nvl(decode(SubQuery3.addat,'00000000',to_date('01/01/1900','dd/mm/yyyy'),to_date(SubQuery3.addat,'yyyymmdd')),to_date('01/01/1900','dd/mm/yyyy')) >= :paramWorkOrderStart
and nvl(decode(SubQuery3.addat,'00000000',to_date('01/01/1900','dd/mm/yyyy'),to_date(SubQuery3.addat,'yyyymmdd')),to_date('01/01/1900','dd/mm/yyyy')) <= :paramWorkOrderEnd
) FilteredWOs
inner join
sapsr3.aufk@prd
on aufk.aufnr = FilteredWOs.WO_aufnr
where lower(aufk.ktext) like '%oil sample%') FilteredOilSampleWOs
left join
-- Get total actual costs
(select
objnr,
-- for some reason, the Work Order costs in SAP are split over 17 table fields, so we need to sum them all up to get the total
SUM (WRT00)+
SUM (WRT01)+
SUM (WRT02)+
SUM (WRT03)+
SUM (WRT04)+
SUM (WRT05)+
SUM (WRT06)+
SUM (WRT07)+
SUM (WRT08)+
SUM (WRT09)+
SUM (WRT10)+
SUM (WRT11)+
SUM (WRT12)+
SUM (WRT13)+
SUM (WRT14)+
SUM (WRT15)+
SUM (WRT16) WO_TotalActualCosts
from sapsr3.pmco@prd
where wrttp like '04' -- '04' == Actual (not planned) costs
and pmco.vorga not like 'KOAO' -- This should exclude "settlement" costs (should this be included?) KOAO == Settlement of primary costs
and pmco.vorga not like 'KOAL' -- This should exclude "settlement" costs (should this be included?) KOAL == Activity allocation settlement
and pmco.vorga not like 'KOAR' -- This should exclude "settlement" costs (should this be included?) KOAR == Settlement???
/* I'm not sure if the below filters are needed?
and pmco.versn like '000'
*/
group by objnr) AllActualOrderCosts
on FilteredOilSampleWOs.WO_objnr = AllActualOrderCosts.objnr),
Q4_FilteredOilSampleWOsWithOLs AS
-- Append the filtered oil sample Work Orders with the Object List entries associated with these filtered oil sample Work Orders
-- Also get the fields that we're missing from "Q3_FilteredOilSampleWOs"
(select
FilteredOilSampleWOsWithOLs.WO_aufnr,
FilteredOilSampleWOsWithOLs.WO_iloan,
FilteredOilSampleWOsWithOLs.WO_obknr,
FilteredOilSampleWOsWithOLs.WO_qmnum,
FilteredOilSampleWOsWithOLs.WO_tplnr,
FilteredOilSampleWOsWithOLs.WO_equnr,
FilteredOilSampleWOsWithOLs.IS_OL,
Q3_FilteredOilSampleWOs.WO_period,
Q3_FilteredOilSampleWOs.WO_iphas,
Q3_FilteredOilSampleWOs.WO_TotalActualCosts,
Q3_FilteredOilSampleWOs.WO_objnr,
Q3_FilteredOilSampleWOs.WO_ktext
from
-- Grab all filtered oil sample Work Orders
(select
WO_aufnr,
WO_iloan,
WO_obknr,
WO_qmnum,
WO_tplnr,
WO_equnr,
'False' as IS_OL
from
Q3_FilteredOilSampleWOs
UNION ALL
-- Grab all those Object List entries that are associated with the filtered oil sample Work Orders
(select
Q2_AllOLsWithWOs.aufnr,
Q2_AllOLsWithWOs.iloan,
Q2_AllOLsWithWOs.obknr,
Q2_AllOLsWithWOs.ihnum,
Q2_AllOLsWithWOs.tplnr,
Q2_AllOLsWithWOs.equnr,
'True' as IS_OL
from
Q3_FilteredOilSampleWOs
inner join
Q2_AllOLsWithWOs
on Q3_FilteredOilSampleWOs.WO_obknr = Q2_AllOLsWithWOs.obknr)) FilteredOilSampleWOsWithOLs
inner join
Q3_FilteredOilSampleWOs
on FilteredOilSampleWOsWithOLs.WO_aufnr = Q3_FilteredOilSampleWOs.WO_aufnr),
Q5_FinalWOList AS
-- Attach the current equipment numbers to the results of "Q4_FilteredOilSampleWOsWithOLs".
-- Whilst some of the WOs collected below may already have equipment numbers associated with them at the time of the work order,
-- much of these equipment numbers may not be active anymore and/or not currently installed. So we'll use the results of "Q1_AllFLsWithCurrentEquip" to get
-- all of the current active and installed equipment associated with a Fun. Loc., and attach them to our work orders.
-- (It would be rather pointless to check for oil samples of equipment that doesn't even exist anymore)
(select
Q4_FilteredOilSampleWOsWithOLs.WO_aufnr,
Q4_FilteredOilSampleWOsWithOLs.WO_iloan,
Q4_FilteredOilSampleWOsWithOLs.WO_obknr,
Q4_FilteredOilSampleWOsWithOLs.WO_qmnum,
Q4_FilteredOilSampleWOsWithOLs.WO_tplnr,
Q4_FilteredOilSampleWOsWithOLs.WO_equnr,
Q1_AllFLsWithCurrentEquip.equnr CUR_equnr,
Q1_AllFLsWithCurrentEquip.objnr CUR_equip_objnr,
Q4_FilteredOilSampleWOsWithOLs.IS_OL,
Q4_FilteredOilSampleWOsWithOLs.WO_period,
Q4_FilteredOilSampleWOsWithOLs.WO_iphas,
Q4_FilteredOilSampleWOsWithOLs.WO_TotalActualCosts,
Q4_FilteredOilSampleWOsWithOLs.WO_objnr,
Q4_FilteredOilSampleWOsWithOLs.WO_ktext
from
Q4_FilteredOilSampleWOsWithOLs
inner join
Q1_AllFLsWithCurrentEquip
on Q4_FilteredOilSampleWOsWithOLs.WO_tplnr = Q1_AllFLsWithCurrentEquip.tplnr)
select
FinalWOsWithPoints.WO_aufnr WO_No,
FinalWOsWithPoints.WO_qmnum WO_Notif_No,
FinalWOsWithPoints.WO_period WO_Period,
FinalWOsWithPoints.WO_tplnr WO_Fun_Loc,
FinalWOsWithPoints.WO_equnr WO_Equip_No,
FinalWOsWithPoints.CUR_equnr Current_Equip_No,
FinalWOsWithPoints.WO_ktext WO_Text,
FinalWOsWithPoints.WO_iphas WO_Status,
FinalWOsWithPoints.WO_TotalActualCosts WO_ActualCosts,
FinalWOsWithPoints.IS_OL IS_OL,
FinalWOsWithPoints.point Current_MeasPoint,
FinalWOsWithPoints.pttxt Current_MeasPointText,
FinalWOsWithPoints.mptyp Current_MeasPointCat,
imrg.mdocm Current_MeasDoc,
-- For results where Meas_Doc returns null, force the Meas_Doc_Date to also return null
case when
imrg.mdocm is null then nvl(decode(imrg.idate,'00000000',to_date('01/01/1900','dd/mm/yyyy'),to_date(imrg.idate,'yyyymmdd')),to_date('','dd/mm/yyyy'))
else
nvl(decode(imrg.idate,'00000000',to_date('01/01/1900','dd/mm/yyyy'),to_date(imrg.idate,'yyyymmdd')),to_date('01/01/1900','dd/mm/yyyy'))
end
Current_MeasDocDate
from
-- Get D type meas. points for the final work order list "Q4_FinalOilSampleWOs"
-- Any equipment that gets excluded in this step would simply have no 'D' type measurement points
(select
Q5_FinalWOList.WO_aufnr,
Q5_FinalWOList.WO_iloan,
Q5_FinalWOList.WO_obknr,
Q5_FinalWOList.WO_qmnum,
Q5_FinalWOList.WO_period,
Q5_FinalWOList.WO_tplnr,
Q5_FinalWOList.WO_equnr,
Q5_FinalWOList.CUR_equnr,
Q5_FinalWOList.CUR_equip_objnr,
Q5_FinalWOList.WO_objnr,
Q5_FinalWOList.WO_ktext,
Q5_FinalWOList.WO_iphas,
Q5_FinalWOList.WO_TotalActualCosts,
Q5_FinalWOList.IS_OL,
imptt.point,
imptt.pttxt,
imptt.mptyp
from
Q5_FinalWOList
inner join
sapsr3.imptt@prd
on Q5_FinalWOList.CUR_equip_objnr = imptt.mpobj
where imptt.mptyp like 'D') FinalWOsWithPoints
left join
sapsr3.imrg@prd
on FinalWOsWithPoints.point = imrg.point
order by
FinalWOsWithPoints.WO_tplnr asc,
FinalWOsWithPoints.WO_equnr asc,
FinalWOsWithPoints.WO_aufnr asc,
FinalWOsWithPoints.point asc,
imrg.mdocm asc;
END;
以上是关于text SAP API查询 - 带有Measurement Docs脚本的工作订单的主要内容,如果未能解决你的问题,请参考以下文章
通过带有参数的 JDBC 从 SAP HANA 数据库中选择
.Net 连接器,用于带有 .Net Core 的 SAP HANA
Dynamics CRM2016 Web API之获取查找字段的text及选项集的text