在Sbo中通过单据事务日志进行物料的期初、期末、出入库综合分析

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介:
一个非常有用的Sbo业务查询分析,利用Sbo单据事务日志表OINM,对指定期间的物料的期初、期末、入库、出库以及特殊类型的出库入库--在此我们分析了采购入库和采购退货两种特殊的业务类型--进行了统计分析。
 
当然可以进行扩展,进而加上一些分析条件,比如对指定的仓库、指定的物料类型、排除指定的物料等条件进行约束。以下语句在某合作单位的生产环境上测试通过,并用于其生产分析。
 
_declare @dt1 smalldatetime, @dt2 smalldatetime, @ItemCode nvarchar(20)
_select @dt1=t0.docDate FROM OINM t0 WHERE t0.createDate=[%0]
_select @dt2=t1.docDate FROM OINM t1 WHERE t1.createDate=[%1]
_select @ItemCode=t2.ItemCode from OITM t2 where t2.ItemCode = '[%2]'
_select tc.ItmsGrpNam N'物料组名称',tc.ItmsGrpCod N'物料组',ta.itemcode N'物料号',tb.ItemName N'物料名称',sum(ta.begqty) N'期初数量',sum(ta.begtotal) N'期初金额', sum(Buyqty) N'采购入库数量',sum(Buytotal) N'采购入库金额',sum(Retqty) N'采购退货数量',sum(Rettotal) N'采购退货金额',sum(inqty) N'库存收货数量',sum(intotal) N'库存收货金额',sum(outqty) N'库存发货数量',sum(outtotal) N'库存发货金额',sum(endqty) N'期未数量',sum(endtotal) N'期未余额'
from (
 _select ItemCode,sum(begqty) begqty,sum(begtotal) begtotal,sum(inqty)inqty,sum(intotal)intotal,sum(outqty) outqty,sum(outtotal) outtotal,sum(endqty) endqty,sum(endtotal) endtotal, sum(BuyQty) BuyQty, sum(BuyTotal) BuyTotal, sum(RetQty) RetQty, sum(RetTotal) RetTotal
  FROM 
   (
       _select a.ItemCode,sum(IsNull(IsNull(a.InQty,0),0)-IsNull(IsNull(a.OutQty,0),0)) begqty,sum(a.TransValue) begtotal,0 inqty,0 intotal,0 outqty,0 outtotal,0 endqty,0 endtotal, 0 BuyQty, 0 BuyTotal, 0 RetQty, 0 RetTotal
        from oinm a 
    where ( a.ItemCode=@ItemCode or IsNull(@ItemCode,'')='') and a.CreateDate < IsNull(@dt1, cast('2001-1-1' as smalldatetime))
       group by a.ItemCode
       union all
       _select a.ItemCode,0,0,sum(IsNull(a.InQty,0)),sum(case when a.TransValue>=0 then a.TransValue else 0 end),sum(IsNull(a.OutQty,0)),sum(case when a.TransValue<0 then a.TransValue else 0 end),0,0,0,0,0,0
        from oinm a 
    where ( a.ItemCode=@ItemCode or IsNull(@ItemCode,'')='') and a.CreateDate between IsNull(@dt1, cast('2001-1-1' as smalldatetime)) and IsNull(@dt2,getdate()) And a.TransType not in ('20','21')
        group by a.ItemCode
       union all
       _select a.ItemCode,0,0,0,0,0,0,sum(IsNull(IsNull(a.InQty,0),0)-IsNull(IsNull(a.OutQty,0),0)),sum(a.TransValue),0,0,0,0
        from oinm a 
    where ( a.ItemCode=@ItemCode or IsNull(@ItemCode,'')='') and a.CreateDate<=IsNull(@dt2,getdate())
        group by a.ItemCode
       union all
       _select a.ItemCode,0,0,0,0,0,0,0,0,sum(IsNull(IsNull(a.InQty,0),0)-IsNull(IsNull(a.OutQty,0),0)),sum(a.TransValue),0,0
        from oinm a 
    where ( a.ItemCode=@ItemCode or IsNull(@ItemCode,'')='') and a.CreateDate between IsNull(@dt1, cast('2001-1-1' as smalldatetime)) and IsNull(@dt2,getdate()) and a.TransType='20'
        group by a.ItemCode
       union all
       _select a.ItemCode,0,0,0,0,0,0,0,0,0,0,sum(IsNull(IsNull(a.InQty,0),0)-IsNull(IsNull(a.OutQty,0),0)),sum(a.TransValue)
        from oinm a 
    where ( a.ItemCode=@ItemCode or IsNull(@ItemCode,'')='') and a.CreateDate between IsNull(@dt1, cast('2001-1-1' as smalldatetime)) and IsNull(@dt2,getdate()) and a.TransType='21'
        group by a.ItemCode
   ) tmp 
   group by ItemCode) ta 
  inner join oitm tb on ta.itemcode = tb.ItemCode 
  inner join oitb tc on tb.ItmsGrpCod = tc.ItmsGrpCod 
group by tc.ItmsGrpNam, tc.ItmsGrpCod, ta.itemcode, tb.ItemName


本文转自foresun  51CTO博客,原文链接:http://blog.51cto.com/foresun/104533,如需转载请自行联系原作者
相关实践学习
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
相关文章
|
8月前
|
存储 运维 监控
SelectDB 实现日志高效存储与实时分析,完成任务可领取积分、餐具套装/水杯/帆布包!
SelectDB 实现日志高效存储与实时分析,完成任务可领取积分、餐具套装/水杯/帆布包!
|
3月前
|
监控 安全 搜索推荐
使用EventLog Analyzer进行日志取证分析
EventLog Analyzer助力企业通过集中采集、归档与分析系统日志及syslog,快速构建“数字犯罪现场”,精准追溯安全事件根源。其强大搜索功能可秒级定位入侵时间、人员与路径,生成合规与取证报表,确保日志安全防篡改,大幅提升调查效率,为执法提供有力证据支持。
145 0
|
8月前
|
SQL 监控 数据挖掘
SLS 重磅升级:超大规模数据实现完全精确分析
SLS 全新推出的「SQL 完全精确」模式,通过“限”与“换”的策略切换,在快速分析与精确计算之间实现平衡,满足用户对于超大数据规模分析结果精确的刚性需求。标志着其在超大规模日志数据分析领域再次迈出了重要的一步。
564 117
|
5月前
|
监控 安全 NoSQL
【DevOps】Logstash详解:高效日志管理与分析工具
Logstash是ELK Stack核心组件之一,具备强大的日志收集、处理与转发能力。它支持多种数据来源,提供灵活的过滤、转换机制,并可通过插件扩展功能,广泛应用于系统日志分析、性能优化及安全合规等领域,是现代日志管理的关键工具。
743 0
|
7月前
|
自然语言处理 监控 安全
阿里云发布可观测MCP!支持自然语言查询和分析多模态日志
阿里云可观测官方发布了Observable MCP Server,提供了一系列访问阿里云可观测各产品的工具能力,包含阿里云日志服务SLS、阿里云应用实时监控服务ARMS等,支持用户通过自然语言形式查询
849 0
阿里云发布可观测MCP!支持自然语言查询和分析多模态日志
|
6月前
|
人工智能 运维 监控
Aipy实战:分析apache2日志中的网站攻击痕迹
Apache2日志系统灵活且信息全面,但安全分析、实时分析和合规性审计存在较高技术门槛。为降低难度,可借助AI工具如aipy高效分析日志,快速发现攻击痕迹并提供反制措施。通过结合AI与学习技术知识,新手运维人员能更轻松掌握复杂日志分析任务,提升工作效率与技能水平。
|
9月前
|
存储 消息中间件 缓存
MiniMax GenAI 可观测性分析 :基于阿里云 SelectDB 构建 PB 级别日志系统
基于阿里云SelectDB,MiniMax构建了覆盖国内及海外业务的日志可观测中台,总体数据规模超过数PB,日均新增日志写入量达数百TB。系统在P95分位查询场景下的响应时间小于3秒,峰值时刻实现了超过10GB/s的读写吞吐。通过存算分离、高压缩比算法和单副本热缓存等技术手段,MiniMax在优化性能的同时显著降低了建设成本,计算资源用量降低40%,热数据存储用量降低50%,为未来业务的高速发展和技术演进奠定了坚实基础。
362 1
MiniMax GenAI 可观测性分析 :基于阿里云 SelectDB 构建 PB 级别日志系统
|
9月前
|
SQL 存储 自然语言处理
让跨 project 联查更轻松,SLS StoreView 查询和分析实践
让跨 project 联查更轻松,SLS StoreView 查询和分析实践
178 1
|
11月前
|
机器学习/深度学习 人工智能 运维
智能日志分析:用AI点亮运维的未来
智能日志分析:用AI点亮运维的未来
3268 15
|
10月前
|
SQL 分布式计算 Serverless
基于阿里云 EMR Serverless Spark 版快速搭建OSS日志分析应用
基于阿里云 EMR Serverless Spark 版快速搭建OSS日志分析应用
242 0

热门文章

最新文章