可以在运行时生成 ABAP 报告吗? [英] Generation of ABAP report in runtime possible?

查看:40
本文介绍了可以在运行时生成 ABAP 报告吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可以生成ABAP代码的Function模块.例如:FM以表名和连接条件为输入,生成与之对应的ABAP代码.

Is there any Function module that can generate ABAP code. For eg: FM takes tables name and join conditions as input and generate ABAP code corresponding to that.

谢谢

推荐答案

1.通用报告是可能的.

你的问题是,你必须对什么是通用和什么不是,这意味着,有些东西必须是通用的,那它将处理您之前想做的任何事情(主要是选择),在(主要是操纵--->我会为此提供一个badi)和输出.这意味着,至少有输出步骤,它可以对 ALL 有效之前的步骤产生的数据.考虑一个通用的 ALV-table_output,repo 中有很多示例.如果你想把打印出来的东西简单地列出来,这可能包括更多的工作,例如,结构有多大,何时换行等等,请考虑使用允许切换输出类型的标志.

Your problem is, that You will have to draw a strict frame of what is generic and what not, this means, some stuff MUST be that generic, that it will deal with WHATEVER You want to do before ( mostly the selection ) , during ( mostly manipulation ---> I would offer a badi for that ), and output. This means, that there is at least the output-step, which can be valid for ALL data resulting from the steps before. Consider a generic ALV-table_output, there are a lot of examples in the repo. If You want to be the stuff printed out simple as list, this might include more work, like, how big is the structure, when Dou You wrap a line, and so on, consider using a flag which allows to toggle the type of output .

2.通用报告是可传输的对象.

这是指第一点.定义清晰的阶段和限制.报表能做什么,不能做什么.因为,即使它在客户的命名空间中,每次修改仍然会被放入传输层.因此,必须对特征/限制进行严格的定义,以便由于哦,但我们也需要那个"语句的传输量不会变得无限.

This refers to point one. Define clear stages and limits. What does the report do, and what is it not able to do. Because, even if it is in customer's namespace, each modification still will be put into transport-layers. Therefore a strict definition of features/limits is necessary so that the amount of transports due to "oh, but we also need that"-statements will not become infinite.

2.通用报告很严格.

这是什么意思?如果未正确设置,您可能希望解析传递的数据(表名、连接绑定、选择参数值)并抛出异常.很多工作.你应该为此提供一个badi.如果你不这样做,期待一个转储.让它倾倒.最后,您的 report-api 的用户应该知道(可能通过文档)如何调用它.如果不是,则结果将是动态 SQL 转储.

What does that mean ? You might want to parse the passed data ( table names, join-binding, selection-parameter-values ) and throw exceptions, if not properly set. Much work. You should offer a badi for that. If You do not do this, expect a dump. let it dump. In the end the user of Your report-api should know ( by documentation perhaps) how to call it. If not, a dynamic SQL-dump will be the result.

3.通用报告可能会受益于 badis/exit.

我认为这是不言自明的.特别是数据的通用/动态选择/修改/显示应该是可扩展的自定义修改.当您检查时,f4-search-help 退出的工作原理是什么,您就会明白我的意思.

This is self explanaining, I think. Especially generic/dynamic selection/modification/displaying of data should be extendable in terms of custom-modifications. When You inspect, what a f4-search-help exit works like, You will understand, what I mean.

4.通用编码很难调试,主要是黑盒.自我解释,在下面的代码部分,我可以标记其中的一些部分.

4. Generic coding is hard to debug, mostly a blackbox. Self explaining, in the code-section below I can mark some of those sections.

5.通用编码在 repo 中有一些最好的例子.

不要重新发明轮子.通过调试来检查 se16n 是如何工作的,通过调试来检查 se11 是如何工作的.检查,什么 SQL-Query-builder看起来像在调试器中.你很快就会明白,复制粘贴应该是你工作中最简单的部分.

Do not reinvent the wheel. Check, how the se16n works by debugging it, check how se11 works by debugging it. Check, what the SQL-Query-builder looks like in the debugger. You will get the idea very soon, and the copy-paste should be the most simple part of Your work.

6.这是您可能使用的基本部分.

Where 子句的确定和参数的设置.

Where clause determination and setting the params.

 data lt_range     type rsds_trange.
 data ls_range_f   type rsds_frange.
 data lt_where     type rsds_twhere.
 data ls_where     like line of lt_where.


ls_range_f =  value #( sign   = _sign
                       option = _option
                       low    = _low
                       high   = _high ). 


.
.
.

append ls_frange to lt_range.
.
.
.

 call function 'FREE_SELECTIONS_RANGE_2_WHERE'
  exporting
    field_ranges  = lt_range
  importing
    where_clauses = lt_where.

您有参数,让我们创建选择结果表.

You have the parameter, let us create the select-result-table.

data(lt_key) = value abap_keydescr_tab( for line in _joinfields)
                                                  ( name = fieldname ) ).
data(lo_structdescr) = cast cl_abap_structdescr(    cl_abap_structdescr=>describe_by_name( _struct_name ) ).
data(lo_tabledescr)  = cl_abap_tabledescr=>create( line_type  = lo_structdescr                                                       p_key        = lt_key ).

create data ro_data type handle lo_tabledescr.

...

 select  (sel_st)
    from    (sel_bind)
    into    corresponding fields of table t_data
    where   (dyn_where).

然后将seelct-table-result-reference分配给这个select的通用表.

Then assign the seelct-table-result-reference to the generic table of this select.

您需要更多提示吗?

这篇关于可以在运行时生成 ABAP 报告吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆