【SAP Abap】一条SQL语句实现支持报表项配置的财务报表

【SAP Abap】一条SQL语句实现支持报表项配置的财务报表

  • 1、业务背景
  • 2、配置项特殊处理
  • 3、实现方式(Hana Studio SQL语句)
  • 4、实现方式(Abap OpenSQL语句)
  • 5、总结

1、业务背景

在财务三大报表之外,业务需要使用类似的科目可配置方式,开发一个包括销售、管理、研发、财务的四大费用报表。

报表项配置表如下:
在这里插入图片描述
在这里插入图片描述
报表数据显示格式如下:
在这里插入图片描述
FS取值逻辑如下:
在这里插入图片描述
在这里插入图片描述
每月取值逻辑:根据选择屏幕输入的
公司代码、会计年度、分类账,前面的功能范围、报表项维护的总账科目,取出ACDOCA-POPER等于’01’期间ACDOCA-HSL汇总金额。

2、配置项特殊处理

(1)该报表没有AB左右列区分,使用列编号来区分四大费用类型:A-销售、B-管理、C-研发、D-财务;
(2)明细项太多,每种类型费用汇总项的公式列,写具体公式太麻烦,对未来增加明细项也不太友好,改用“ALL”标识。

3、实现方式(Hana Studio SQL语句)

with lt_acdoca as (select h.zcolumn, h.zrow, h.ztext,a.rbukrs, a.gjahr, a.poper, a.rldnr, a.RFAREA, a.racct, a.DRCRK, ( case when h.REVERSAL = 'X' then - a.hsl else a.hsl end ) as hslfrom ztfi002 as hleft join acdoca as a on a.gjahr = 2023 and a.poper <= 3	--测试数据and (( h.fsaknr = '' and h.tsaknr = '') or ( a.racct between case when h.fsaknr = '' then h.tsaknr else h.fsaknr endand case when h.tsaknr = '' then h.fsaknr else h.tsaknr end)-- 说明:以上or语句在opensql中不兼容,可以改用以下三句等效语句--or ( h.fsaknr = '' and h.tsaknr <> '' and a.racct = h.tsaknr )--or ( h.fsaknr <> '' and h.tsaknr = '' and a.racct = h.fsaknr )--or ( h.fsaknr <> '' and h.tsaknr <> '' and a.racct between h.fsaknr and h.tsaknr )) and (( h.frfarea = '' and h.trfarea = '') or ( a.RFAREA between case when h.frfarea = '' then h.trfarea else h.frfarea endand case when h.trfarea = '' then h.frfarea else h.trfarea end)-- 说明:以上or语句在opensql中不兼容,可以改用以下三句等效语句--or ( h.frfarea = '' and h.trfarea <> '' and a.RFAREA = h.trfarea )--or ( h.frfarea <> '' and h.trfarea = '' and a.RFAREA = h.frfarea )--or ( h.frfarea <> '' and h.trfarea <> '' and a.RFAREA between h.frfarea and h.trfarea )) and ( a.DRCRK = ( case when h.ZJFBS = 'X' then 'S' else '' end )or a.DRCRK = ( case when h.ZDFBS = 'X' then 'H' else '' end )-- 说明:以上两行语句在opensql中不兼容,可以改用以下三行等效语句--( h.ZJFBS = 'X' and h.ZDFBS = 'X' )--or ( h.ZJFBS = 'X' and a.DRCRK = 'S' )--or ( h.ZDFBS = 'X' and a.DRCRK = 'H' ))where h.ztype = 'FE' and h.FORMULA <> 'ALL'and a.poper is not nulland a.rbukrs = 2300  -- 测试数据
)
, lt_lt_acdoca_sum as (select zcolumn, zrow, ztext, poper, sum( coalesce( hsl,0 ) ) as hsl from lt_acdocagroup by zcolumn, zrow, ztext, poper
)
, lt_header as ( select distinct zcolumn, zrow, ztext, ztype, FORMULA from ztfi002 )
select h.zcolumn, h.zrow, h.ztext,sum( coalesce( s.hsl,0 ) ) as hsl,sum( case when s.poper = '001' then coalesce( s.hsl,0 ) else 0 end ) as hsl01,sum( case when s.poper = '002' then coalesce( s.hsl,0 ) else 0 end ) as hsl02,sum( case when s.poper = '003' then coalesce( s.hsl,0 ) else 0 end ) as hsl03,sum( case when s.poper = '004' then coalesce( s.hsl,0 ) else 0 end ) as hsl04,sum( case when s.poper = '005' then coalesce( s.hsl,0 ) else 0 end ) as hsl05,sum( case when s.poper = '006' then coalesce( s.hsl,0 ) else 0 end ) as hsl06,sum( case when s.poper = '007' then coalesce( s.hsl,0 ) else 0 end ) as hsl07,sum( case when s.poper = '008' then coalesce( s.hsl,0 ) else 0 end ) as hsl08,sum( case when s.poper = '009' then coalesce( s.hsl,0 ) else 0 end ) as hsl09,sum( case when s.poper = '010' then coalesce( s.hsl,0 ) else 0 end ) as hsl10,sum( case when s.poper = '011' then coalesce( s.hsl,0 ) else 0 end ) as hsl11,sum( case when s.poper = '012' then coalesce( s.hsl,0 ) else 0 end ) as hsl12,sum( case when s.poper = '013' then coalesce( s.hsl,0 ) else 0 end ) as hsl13,sum( case when s.poper = '014' then coalesce( s.hsl,0 ) else 0 end ) as hsl14,sum( case when s.poper = '015' then coalesce( s.hsl,0 ) else 0 end ) as hsl15,sum( case when s.poper = '016' then coalesce( s.hsl,0 ) else 0 end ) as hsl16
from lt_header as h
left join lt_lt_acdoca_sum as s on s.zcolumn = h.zcolumn and s.zrow = h.zrow
where h.ztype = 'FE' and h.FORMULA <> 'ALL'
group by h.zcolumn, h.zrow, h.ztext
union all
select h.zcolumn, h.zrow, h.ztext,sum( coalesce( s.hsl,0 ) ) as hsl,sum( case when s.poper = '001' then coalesce( s.hsl,0 ) else 0 end ) as hsl01,sum( case when s.poper = '002' then coalesce( s.hsl,0 ) else 0 end ) as hsl02,sum( case when s.poper = '003' then coalesce( s.hsl,0 ) else 0 end ) as hsl03,sum( case when s.poper = '004' then coalesce( s.hsl,0 ) else 0 end ) as hsl04,sum( case when s.poper = '005' then coalesce( s.hsl,0 ) else 0 end ) as hsl05,sum( case when s.poper = '006' then coalesce( s.hsl,0 ) else 0 end ) as hsl06,sum( case when s.poper = '007' then coalesce( s.hsl,0 ) else 0 end ) as hsl07,sum( case when s.poper = '008' then coalesce( s.hsl,0 ) else 0 end ) as hsl08,sum( case when s.poper = '009' then coalesce( s.hsl,0 ) else 0 end ) as hsl09,sum( case when s.poper = '010' then coalesce( s.hsl,0 ) else 0 end ) as hsl10,sum( case when s.poper = '011' then coalesce( s.hsl,0 ) else 0 end ) as hsl11,sum( case when s.poper = '012' then coalesce( s.hsl,0 ) else 0 end ) as hsl12,sum( case when s.poper = '013' then coalesce( s.hsl,0 ) else 0 end ) as hsl13,sum( case when s.poper = '014' then coalesce( s.hsl,0 ) else 0 end ) as hsl14,sum( case when s.poper = '015' then coalesce( s.hsl,0 ) else 0 end ) as hsl15,sum( case when s.poper = '016' then coalesce( s.hsl,0 ) else 0 end ) as hsl16
from lt_header as h
left join lt_lt_acdoca_sum as s on s.zcolumn = h.zcolumn
where h.ztype = 'FE' and h.FORMULA = 'ALL'
group by h.zcolumn, h.zrow, h.ztext
order by h.zcolumn, h.zrow

显示结果如下:
在这里插入图片描述

4、实现方式(Abap OpenSQL语句)

将以上SQL语句复制到Abap代码中,检查代码语句,根据错误提示进行调整,最终调整代码如下:

FORM FRM_GET_DATA.WITH +LT_ACDOCA AS (SELECTH~ZCOLUMN, H~ZROW, H~ZTEXT,A~RBUKRS, A~GJAHR, A~POPER, A~RLDNR,A~RFAREA, A~RACCT, A~DRCRK,( CASE WHEN H~REVERSAL = 'X' THEN - A~HSL ELSE A~HSL END ) AS HSLFROM ZTFI002 AS HLEFT JOIN ACDOCA AS A ON  A~GJAHR = @P_RYEAR AND ( @P_POPER IS INITIAL OR A~POPER <= @P_POPER )AND (( H~FSAKNR = '' AND H~TSAKNR = '')OR ( H~FSAKNR = '' AND H~TSAKNR <> '' AND A~RACCT = H~TSAKNR )OR ( H~FSAKNR <> '' AND H~TSAKNR = '' AND A~RACCT = H~FSAKNR )OR ( H~FSAKNR <> '' AND H~TSAKNR <> '' AND A~RACCT BETWEEN H~FSAKNR AND H~TSAKNR ))AND (( H~FRFAREA = '' AND H~TRFAREA = '')OR ( H~FRFAREA = '' AND H~TRFAREA <> '' AND A~RFAREA = H~TRFAREA )OR ( H~FRFAREA <> '' AND H~TRFAREA = '' AND A~RFAREA = H~FRFAREA )OR ( H~FRFAREA <> '' AND H~TRFAREA <> '' AND A~RFAREA BETWEEN H~FRFAREA AND H~TRFAREA ))AND (( H~ZJFBS = 'X' AND H~ZDFBS = 'X' )OR ( H~ZJFBS = 'X' AND A~DRCRK = 'S' )OR ( H~ZDFBS = 'X' AND A~DRCRK = 'H' ))WHERE H~ZTYPE = 'FE' AND H~FORMULA <> 'ALL'AND A~POPER IS NOT NULLAND A~RBUKRS IN @R_BUKRSAND A~RLDNR = @P_RLDNR), +LT_LT_ACDOCA_SUM AS (SELECT ZCOLUMN, ZROW, ZTEXT, POPER, SUM( COALESCE( HSL,0 ) ) AS HSLFROM +LT_ACDOCAGROUP BY ZCOLUMN, ZROW, ZTEXT, POPER), +LT_HEADER AS ( SELECT DISTINCT ZCOLUMN, ZROW, ZTEXT, ZTYPE, FORMULA FROM ZTFI002 )SELECT H~ZCOLUMN, H~ZROW, H~ZTEXT,SUM( COALESCE( S~HSL,0 ) ) AS HSL,SUM( CASE WHEN S~POPER = '001' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL01,SUM( CASE WHEN S~POPER = '002' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL02,SUM( CASE WHEN S~POPER = '003' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL03,SUM( CASE WHEN S~POPER = '004' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL04,SUM( CASE WHEN S~POPER = '005' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL05,SUM( CASE WHEN S~POPER = '006' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL06,SUM( CASE WHEN S~POPER = '007' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL07,SUM( CASE WHEN S~POPER = '008' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL08,SUM( CASE WHEN S~POPER = '009' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL09,SUM( CASE WHEN S~POPER = '010' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL10,SUM( CASE WHEN S~POPER = '011' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL11,SUM( CASE WHEN S~POPER = '012' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL12,SUM( CASE WHEN S~POPER = '013' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL13,SUM( CASE WHEN S~POPER = '014' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL14,SUM( CASE WHEN S~POPER = '015' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL15,SUM( CASE WHEN S~POPER = '016' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL16FROM +LT_HEADER AS HLEFT JOIN +LT_LT_ACDOCA_SUM AS S ON S~ZCOLUMN = H~ZCOLUMN AND S~ZROW = H~ZROWWHERE H~ZTYPE = 'FE' AND H~FORMULA <> 'ALL'GROUP BY H~ZCOLUMN, H~ZROW, H~ZTEXTUNION ALLSELECT H~ZCOLUMN, H~ZROW, H~ZTEXT,SUM( COALESCE( S~HSL,0 ) ) AS HSL,SUM( CASE WHEN S~POPER = '001' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL01,SUM( CASE WHEN S~POPER = '002' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL02,SUM( CASE WHEN S~POPER = '003' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL03,SUM( CASE WHEN S~POPER = '004' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL04,SUM( CASE WHEN S~POPER = '005' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL05,SUM( CASE WHEN S~POPER = '006' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL06,SUM( CASE WHEN S~POPER = '007' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL07,SUM( CASE WHEN S~POPER = '008' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL08,SUM( CASE WHEN S~POPER = '009' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL09,SUM( CASE WHEN S~POPER = '010' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL10,SUM( CASE WHEN S~POPER = '011' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL11,SUM( CASE WHEN S~POPER = '012' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL12,SUM( CASE WHEN S~POPER = '013' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL13,SUM( CASE WHEN S~POPER = '014' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL14,SUM( CASE WHEN S~POPER = '015' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL15,SUM( CASE WHEN S~POPER = '016' THEN COALESCE( S~HSL,0 ) ELSE 0 END ) AS HSL16FROM +LT_HEADER AS HLEFT JOIN +LT_LT_ACDOCA_SUM AS S ON S~ZCOLUMN = H~ZCOLUMNWHERE H~ZTYPE = 'FE' AND H~FORMULA = 'ALL'GROUP BY H~ZCOLUMN, H~ZROW, H~ZTEXTORDER BY ZCOLUMN, ZROWINTO CORRESPONDING FIELDS OF TABLE @GT_DATA.ENDFORM.

最终结果如下:
在这里插入图片描述
在这里插入图片描述

5、总结

通过以上方法实现的报表,可以大大减少abap代码量,充分利用hana数据库性能,很大程度的提高数据查询效率。

原创文章,转载请注明来源-X档案

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/355221.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

数据库复习——模式分解

模式分解这边主要包括无损分解和保持函数依赖的分解两种形式&#xff0c;简单整理一下。 无损分解 把一个 R R R 分成 ρ { R 1 , R 2 , ⋯ , R k } \rho \{R_1,R_2,\cdots,R_k\} ρ{R1​,R2​,⋯,Rk​}&#xff0c;然后通过自然连接 R 1 ⋈ R 2 ⋈ ⋯ ⋈ R k R_1\bowtie R…

git的远程管理与标签管理

✨前言✨ &#x1f4d8; 博客主页&#xff1a;to Keep博客主页 &#x1f646;欢迎关注&#xff0c;&#x1f44d;点赞&#xff0c;&#x1f4dd;留言评论 ⏳首发时间&#xff1a;2024年6月20日 &#x1f4e8; 博主码云地址&#xff1a;博主码云地址 &#x1f4d5;参考书籍&…

swift使用swift-protobuf协议通讯,使用指北

什么是Protobuf Protobuf&#xff08;Protocol Buffers&#xff09;协议&#x1f609; Protobuf 是一种由 Google 开发的二进制序列化格式和相关的技术&#xff0c;它用于高效地序列化和反序列化结构化数据&#xff0c;通常用于网络通信、数据存储等场景。 为什么要使用Proto…

【python】Sklearn—Cluster

参考学习来自 10种聚类算法的完整python操作示例 文章目录 聚类数据集亲和力传播——AffinityPropagation聚合聚类——AgglomerationClusteringBIRCH——Birch&#xff08;✔&#xff09;DBSCAN——DBSCANK均值——KMeansMini-Batch K-均值——MiniBatchKMeans均值漂移聚类——…

MySQL之复制(七)

复制 定制的复制方案 分离功能 许多应用都混合了在线事务处理(OLTP)和在线数据分析(OLAP)的查询。OLTP查询比较短并且是事务型的。OLAP查询则通常很大&#xff0c;也很慢&#xff0c;并且不要求绝对最新的数据。这两种查询给服务器带来的负担完全不同&#xff0c;因此它们需…

Linux系统部署Samba服务,共享文件夹给Windows

Samba服务是在Linux和UNIX系统上实现SMB协议的一个免费软件&#xff0c;由服务器及客户端程序构成。 Samba服务是连接Linux与Windows的桥梁&#xff0c;它通过实现SMB&#xff08;Server Message Block&#xff09;协议来允许跨平台的文件和打印机共享。该服务不仅支持Linux和…

用React编写一个密码组件表单

theme: condensed-night-purple highlight: atelier-cave-light 背景介绍 我们在使用网站或者应用程序的登录界面或创建帐户界面时&#xff0c;往往避免不了需要用户输入密码这一步骤&#xff0c;而用户是否可以选择看见他们输入的密码是十分重要的一项功能。尤其是在当输入的…

20240620每日后端---------Spring Boot中的 5 大设计模式最佳实践和示例 这些是我经常使用的设计模式并且非常喜欢

在本文中&#xff0c;我们将深入探讨五种基本设计模式&#xff0c;并探讨在 Spring Boot 项目中有效应用它们的最佳实践。每个模式都将附有一个实际示例来演示其实现。 单例模式 Singleton 模式确保一个类只有一个实例&#xff0c;并提供对它的全局访问点。这对于管理资源&am…

【车载开发系列】CAN通信总线再理解(中篇)

【车载开发系列】CAN通信总线再理解&#xff08;中篇&#xff09; 九. CAN总线标准十. CAN物理层十一. CAN数据链路层1&#xff09;CAN的通信帧类型2&#xff09;CAN的标准帧格式1. CAN ID2. 数据场 3&#xff09;CAN总线仲裁 十二. CAN应用层1&#xff09;CANopen2&#xff09…

linux如何部署前端项目和安装nginx

要在Linux上部署前端项目并安装Nginx&#xff0c;你可以按照以下步骤操作&#xff1a; 安装Nginx: sudo apt update sudo apt install nginx 启动Nginx服务: sudo systemctl start nginx 确保Nginx服务开机自启: sudo systemctl enable nginx 部署前端项目&#xff0c;假设前…

Ruby on Rails Post项目设置网站初始界面

在构建了Ruby的Web服务器后&#xff0c;第三步就可以去掉框架的官方页面&#xff0c;设置自己的网页初始页了。 Linux系统安装Ruby语言-CSDN博客 、在Ubuntu中创建Ruby on Rails项目并搭建数据库-CSDN博客、 Ruby语言建立Web服务器-CSDN博客 了解Ruby onRails项目中的主要文件…

Srouce Insight 4出现乱码

今天用SI4打开一个工程文件&#xff0c;一打开发现注释全是乱码。中文全部看不出来&#xff0c;英文和数字可以看得出来。 那是因为中文的编码格式不算特别兼容。所以需要调整编码格式。 于是我在这里调整了编码格式&#xff1a; 找到菜单的Options-Preferences里面的Files 调…

《计算机英语》Unit1 计算机概述

期末试卷组成 1、选择20道 2、判断20道 3、词汇翻译&#xff08;单词词组&#xff0c;参照课后习题&#xff09; 4、翻译2道&#xff08;一道原题&#xff0c;参照作业&#xff09; Unit One Computer Overview 单元1 计算机概述 algorithm n. 算法 operate …

k8s之kubelet证书时间过期升级

1.查看当前证书时间 # kubeadm alpha certs renew kubelet Kubeadm experimental sub-commands kubeadm是一个用于引导Kubernetes集群的工具&#xff0c;它提供了许多命令和子命令来管理集群的一生周期。过去&#xff0c;某些功能被标记为实验性的&#xff0c;并通过kubeadm a…

CVPR 2024揭幕,清华大学论文接收量霸榜,轻松碾压斯坦福、麻省理工

CVPR2024 会议之眼 快讯 会议介绍 2024 年 CVPR &#xff08;Computer Vision and Pattern Recogntion Conference) 即国际计算机视觉与模式识别会议&#xff0c;于6月17日至21日正在美国西雅图召开。CVPR是计算机视觉和模式识别领域的顶级会议之一。与ICCV和ECCV并称为计算…

Java基础 - 练习(四)打印九九乘法表

Java基础练习 打印九九乘法表&#xff0c;先上代码&#xff1a; public static void multiplicationTable() {for (int i 1; i < 9; i) {for (int j 1; j < i; j) {// \t 跳到下一个TAB位置System.out.print(j "" i "" i * j "\t"…

【全网最全最详细】RabbitMQ面试题

一、说下RabbitMQ的架构大致是什么样的&#xff1f; RabbitMQ是一个开源的消息中间件&#xff0c;用于在应用程序之间传递消息。它实现了AMQP&#xff08;高级消息队列协议&#xff09;并支持其它消息传递协议&#xff0c;例如STOMP&#xff08;简单文本定向消息协议&#xff…

【QT5】<重点> QT多线程

文章目录 前言 一、QThread创建多线程 二、QMutex基于互斥量的同步 三、QReadWriteLock线程同步 四、QWaitCondition线程同步 五、QSemaphore基于信号量的同步 前言 本篇记录学习QT多线程的知识&#xff0c;参考视频13.1QThread创建多线程程序_哔哩哔哩。若涉及版权问题…

LeetCode 338.比特位计数

各位朋友们&#xff0c;大家好啊&#xff0c;今天此题我用的方法比较好理解&#xff0c;但时间复杂度比较高如果大家觉得可以的话&#xff0c;不妨给个免费的赞吧&#xff0c;谢谢了^ _ ^ 1.题目要求如图所示: 2.做题步骤: 1.先计算总共多少个数: int count 0;int number 0;…

基于C#开发web网页管理系统模板流程-主界面密码维护功能完善

点击返回目录-> 基于C#开发web网页管理系统模板流程-总集篇-CSDN博客 前言 紧接上篇->基于C#开发web网页管理系统模板流程-主界面统计功能完善-CSDN博客 一个合格的管理系统&#xff0c;至少一定存在一个功能——用户能够自己修改密码&#xff0c;理论上来说密码只能有用…