当前位置:   article > 正文

用chatGPT增强SAP FICO功能 【现金流量预测】_sap 现金流量表 shkzg

sap 现金流量表 shkzg

如开发基于SAP银行的回单进行企业现金流量表的预测功能

promot :查询SAP中基于银行回单的现金流量预测 ABAP代码

  1. REPORT z_cash_flow_forecast.
  2. * 获取当前日期
  3. DATA: date TYPE dats.
  4. date = sy-datum.
  5. * 获取最近6个月的银行回单
  6. SELECT febep~belnr, febep~budat, febep~xblnr, febep~lifnr, febep~werks,
  7. febep~bukrs, febep~kostl, febep~prctr, febep~hkont, febep~shkzg,
  8. febep~dmbtr, bseg~sgtxt
  9. INTO TABLE @DATA(receipts)
  10. FROM febep
  11. INNER JOIN bseg ON febep~belnr = bseg~belnr AND febep~ebeln = bseg~ebeln
  12. WHERE febep~budat >= date - 180
  13. AND febep~shkzg = 'H'
  14. AND febep~dmbtr <> 0.
  15. * 按月份和公司代码分组,并计算每个月的现金流量
  16. SELECT RIGHT(febep~budat, 6) AS month,
  17. febep~bukrs,
  18. SUM(febep~dmbtr) AS amount
  19. INTO TABLE @DATA(cash_flows)
  20. FROM febep
  21. WHERE febep~budat >= date - 180
  22. AND febep~shkzg = 'H'
  23. AND febep~dmbtr <> 0
  24. GROUP BY month, febep~bukrs.
  25. * 获取公司代码描述
  26. SELECT bukrs, butxt
  27. INTO TABLE @DATA(company_codes)
  28. FROM t001.
  29. * 计算现金流量预测
  30. TYPES: BEGIN OF cash_flow_forecast,
  31. month TYPE char6,
  32. bukrs TYPE bukrs,
  33. days TYPE i,
  34. amount TYPE dmbtr,
  35. END OF cash_flow_forecast.
  36. DATA: cash_flow_forecasts TYPE TABLE OF cash_flow_forecast WITH HEADER LINE.
  37. LOOP AT company_codes INTO DATA(company_code).
  38. DO 3 TIMES.
  39. DATA: days TYPE i,
  40. forecast_date TYPE dats,
  41. forecast_month TYPE char6,
  42. forecast_amount TYPE dmbtr.
  43. CASE sy-index.
  44. WHEN 1.
  45. days = 60.
  46. WHEN 2.
  47. days = 120.
  48. WHEN 3.
  49. days = 240.
  50. ENDCASE.
  51. forecast_date = date + days.
  52. forecast_month = RIGHT( sy-datum + days, 6 ).
  53. SELECT SUM(febep~dmbtr)
  54. INTO @forecast_amount
  55. FROM febep
  56. WHERE febep~bukrs = company_code-bukrs
  57. AND febep~budat BETWEEN date AND forecast_date
  58. AND febep~shkzg = 'H'
  59. AND febep~dmbtr <> 0.
  60. cash_flow_forecasts-month = forecast_month.
  61. cash_flow_forecasts-bukrs = company_code-bukrs.
  62. cash_flow_forecasts-days = days.
  63. cash_flow_forecasts-amount = forecast_amount.
  64. APPEND cash_flow_forecasts.
  65. ENDDO.
  66. ENDLOOP.
  67. * 输出结果
  68. WRITE: / '月份', 20 '公司代码', 30 '预测天数', 40 '现金流量'.

假设此业务所有的现金都基于银行回单设计,

此代码将基于SAP FEBEP银行回单表进行拆解,现金部分 批量上传导入银行回单表;

将ABAP代码转为 java类( 如netweaver代码实现方式)

  1. import java.sql.*;
  2. import java.time.LocalDate;
  3. import java.time.format.DateTimeFormatter;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. public class CashFlowForecast {
  7. private static final String URL = "jdbc:sap://host:port/?autocommit=false&reconnect=true";
  8. private static final String USERNAME = "username";
  9. private static final String PASSWORD = "password";
  10. public static void main(String[] args) {
  11. Connection conn = null;
  12. Statement stmt = null;
  13. ResultSet rs = null;
  14. try {
  15. conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
  16. stmt = conn.createStatement();
  17. // 获取当前日期
  18. LocalDate date = LocalDate.now();
  19. // 获取最近6个月的银行回单
  20. List<Receipt> receipts = new ArrayList<>();
  21. String receiptSql = "SELECT febep.belnr, febep.budat, febep.xblnr, febep.lifnr, febep.werks, " +
  22. "febep.bukrs, febep.kostl, febep.prctr, febep.hkont, febep.shkzg, febep.dmbtr, bseg.sgtxt " +
  23. "FROM febep INNER JOIN bseg ON febep.belnr = bseg.belnr AND febep.ebeln = bseg.ebeln " +
  24. "WHERE febep.budat >= '" + date.minusMonths(6) + "' " +
  25. "AND febep.shkzg = 'H' " +
  26. "AND febep.dmbtr <> 0";
  27. rs = stmt.executeQuery(receiptSql);
  28. while (rs.next()) {
  29. String belnr = rs.getString("belnr");
  30. LocalDate budat = rs.getDate("budat").toLocalDate();
  31. String xblnr = rs.getString("xblnr");
  32. String lifnr = rs.getString("lifnr");
  33. String werks = rs.getString("werks");
  34. String bukrs = rs.getString("bukrs");
  35. String kostl = rs.getString("kostl");
  36. String prctr = rs.getString("prctr");
  37. String hkont = rs.getString("hkont");
  38. String shkzg = rs.getString("shkzg");
  39. double dmbtr = rs.getDouble("dmbtr");
  40. String sgtxt = rs.getString("sgtxt");
  41. receipts.add(new Receipt(belnr, budat, xblnr, lifnr, werks, bukrs, kostl, prctr, hkont, shkzg, dmbtr, sgtxt));
  42. }
  43. // 按月份和公司代码分组,并计算每个月的现金流量
  44. List<CashFlow> cashFlows = new ArrayList<>();
  45. String cashFlowSql = "SELECT RIGHT(febep.budat, 6) AS month, febep.bukrs, SUM(febep.dmbtr) AS amount " +
  46. "FROM febep " +
  47. "WHERE febep.budat >= '" + date.minusMonths(6) + "' " +
  48. "AND febep.shkzg = 'H' " +
  49. "AND febep.dmbtr <> 0 " +
  50. "GROUP BY month, febep.bukrs";
  51. rs = stmt.executeQuery(cashFlowSql);
  52. while (rs.next()) {
  53. String month = rs.getString("month");
  54. String bukrs = rs.getString

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/414264
推荐阅读
相关标签
  

闽ICP备14008679号