ABAP创建对象
下面是创建对象的代码片段。
Form userexit_save_document_prepare.
data: /bks/exitmanager type ref to /bks/exit_manager.
create object /bks/exitmanager
exporting main_prog = 'SAPMV45A'
exit_form = 'USEREXIT_SAVE_DOCUMENT_PREPARE'.
include /bks/exitman.
ENDFORM.
我从文档中得到了这个
出于性能原因,在用户退出的情况下,应填写参数“main_prog”和“exit_form”,这些参数经常像“SAPMV45A”中的“user_field_modification”一样执行,为每个屏幕字段调用。< /p>
1)当调用 create object /bks/exitmanager 时到底发生了什么?为对象分配的内存等?
2)出于性能原因,为什么需要填写创建对象的导出参数?
Below is a code snippet that is creating object.
Form userexit_save_document_prepare.
data: /bks/exitmanager type ref to /bks/exit_manager.
create object /bks/exitmanager
exporting main_prog = 'SAPMV45A'
exit_form = 'USEREXIT_SAVE_DOCUMENT_PREPARE'.
include /bks/exitman.
ENDFORM.
I got this from the documentation
For performance reasons, the parameters "main_prog" and "exit_form" should be filled, in the case of userexits, which are performed very often like "user_field_modification" in "SAPMV45A" which is called for every single screen-field.
1) What happened exactly behind when create object /bks/exitmanager is called? memory allocated for the object etc?
2) Why for performance reasons the exporting parameters of create object needs to be filled?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不是 100% 确定,但这是我最好的猜测:
构造了一个名为 /bks/exitmanager 的对象(它是 /bks/exit_manager 类的对象,或者更具体地说是指向一个对象的引用/“指针”)此类的对象).. 所需的内存分配等,而且还调用“构造函数”代码(可能设置一些传递给调用的实例变量)。
如果您显式传递这些参数,则不必在运行时“计算”它们(例如通过查看调用堆栈)。这应该可以节省一些时间,特别是如果必须经常执行(如文档中所述)。
I'm not 100% sure, but here is my best guess:
an object called /bks/exitmanager is constructed (which is an oject of the class /bks/exit_manager or more specific a reference/"pointer" to an object of this class) .. the required memory allocated etc., but also the "constructor" code is called (probably sets some instance variables as passed to the call).
If you're explicitly passing these parameters, they don't have to be "calculated" at run-time (e.g. by looking at the call stack). This should save some time, especially if it would have to be done quite often (as described in the documentation).
这将有助于了解 /bks/exit_manager 实际上是什么,以及您想要完成的任务的简要说明。
扩展 IronGoofy 所写内容:
data: /bks/exitmanager type ref to /bks/exit_manager
这会在程序的 ABAP 内存中创建一个引用指针,非常类似于字段符号。而且它必须已经声明过。如果它在包含文件中,则需要移动包含文件。
创建对象 /bks/exitmanager
导出 main_prog = 'SAPMV45A'
exit_form = 'USEREXIT_SAVE_DOCUMENT_PREPARE'。
这将根据声明的类创建一个对象实例,并将其分配给引用指针。它通过首先调用构造函数方法来实现这一点。
只有通过检查 /bks/exit_manager 才能准确找到需要导出的内容。
It would help to see what /bks/exit_manager actually is, and a brief explanation of what you are trying to accomplish.
Expanding on what IronGoofy wrote:
data: /bks/exitmanager type ref to /bks/exit_manager
This creates a reference pointer in the ABAP memory of your program, much like a field symbol. Also it must be already delared. If it is in the include, you need to move the include.
create object /bks/exitmanager
exporting main_prog = 'SAPMV45A'
exit_form = 'USEREXIT_SAVE_DOCUMENT_PREPARE'.
This creates an object instance based on the declared class, and assigns it to the referance pointer. It does this by calling the constructor method first.
Only by examing /bks/exit_manager will you find out exactly what you need to export.
如果不查看 /BKS/EXIT_MANAGER 的构造函数,就不可能知道发生了什么以及为什么应该传递参数。不过,保留设置缓冲区是一种常见的模式(想象一个静态哈希表,其键是参数,值保存复杂且耗时的获取内容)。在这种情况下,我期望有一个无法直接访问的受保护构造函数,而只能使用静态工厂方法,该方法使用哈希表来保留退出处理程序本身的引用 - 最好使用弱引用...
It's impossible to tell what's going on and why the parameters should be passed without taking a look at the constructor of /BKS/EXIT_MANAGER. It's a common pattern though to keep a buffer of settings (think of a static hashed table with the key being the parameters and the value holding whatever is complicated and time-consuming to fetch). In this case, I would have expected a protected constructor that cannot be accessed directly, but only using a static factory method that uses a hashed table to keep the references of the exit handler itself - optimally using weak references...