我希望我能正确理解您的问题,因为我不确定您所说的“出于调试目的”是什么意思,但这里是:
您可以使用以下方法访问加载在同一会话的内存中的另一个程序的变量(我很确定它不需要在调用堆栈中):
ASSIGN ('(PROGRAM)VARIABLE') TO LV_LOCAL.
使用参考变量,它变得有点棘手,但这里有一个示例,将有助于演示。
这是我们的调用程序,其中包含一个LR_TEST
我们想要在其他地方访问的引用变量。为了演示的目的,我引用了一个本地定义的类(因为这是我从你的问题中收集到的)。
REPORT ZCALLER.
class lcl_test definition.
public section.
data: myval type i.
methods: my_meth exporting e_val type i.
endclass.
data: lr_test type ref to lcl_test.
CREATE OBJECT lr_test.
lr_test->MYVAL = 22.
perform call_me(zcallee).
class lcl_test implementation.
method my_meth.
* Export the attribute myval as param e_val.
e_val = myval.
endmethod.
endclass.
这是我们要从上述程序访问变量的程序。
REPORT ZCALLEE.
form call_me.
field-symbols: <ref>.
data: ld_test type ref to object.
data: lv_val type i.
* Exhibit A: Gettinf a reference to a 'foreign' object instance
assign ('(ZCALLER)LR_TEST') to <ref>.
* <ref> now contains a reference to the class instance from the program
* ZCALLER (not very useful, except for passing around maybe)
* Exhibit B: Getting a public attribute from a 'foreign' class instance
assign ('(ZCALLER)LR_TEST->MYVAL') to <ref>.
* <ref> now contains the value of the attribute MYVAL
* Exhibit C: Getting a reference to an instance and calling a method
assign ('(ZCALLER)LR_TEST') to <ref>. "Again the class reference
if sy-subrc = 0. "Rule: Always check sy-subrc after assign before
"accessing a field symbol! (but you know that)
ld_test = <ref>. "Now we have a concrete handle
* Now we make a dynamic method call using our instance handle
CALL METHOD ld_test->('MY_METH')
IMPORTING
e_val = lv_val.
endif.
endform.