简体   繁体   English

如何在 AMDP 方法中进行 REDUCE 计算?

[英]How to do REDUCE calculation in AMDP method?

how can we achieve REDUCE like the below logic inside an AMDP method.我们如何在 AMDP 方法中实现像下面的逻辑一样的 REDUCE。

lv_total = reduce tslxx9( init x type tslxx9 for lwa_out in lt_out
                              where ( companycode     = <lf_wa>-bukrs and
                                      ryear           = <lf_wa>-year  and
                                      currency        = <lf_wa>-currency
                                    )
                                      next x = x + lwa_out-amount ).

The direct translation to SQLScript would be to perform a SELECT on a local table variable with a GROUP BY clause and the SUM aggregation function.直接转换为 SQLScript 是使用 GROUP BY 子句和 SUM 聚合 function 对本地表变量执行 SELECT。 Something like this:像这样的东西:

  METHOD sum_amdp BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT.
     lv_total = SELECT SUM( amount )
       FROM :it_out
       WHERE companycode = :lf_wa.bukrs
         AND ryear = :lf_wa.year
         AND currency = :lf_wa.currency
       GROUP BY companycode, ryear, currency;
  ENDMETHOD.

This method is of course rather pointless to implement in AMDP because it doesn't even access the database.这种方法在 AMDP 中实现当然是毫无意义的,因为它甚至不访问数据库。 But it demonstrates how SQLScript is able to perform complex SQL statements on variables.但它演示了 SQLScript 如何能够对变量执行复杂的 SQL 语句。 Which only makes sense in the context of a larger SQLScript method which either does this to process data from a database query it just performed or to prepare data for a database query it is going to perform.这仅在更大的 SQLScript 方法的上下文中才有意义,该方法要么执行此操作以处理刚刚执行的数据库查询中的数据,要么为将要执行的数据库查询准备数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM