问题
When a program is running in SAP ECC, the "system stack" stores all global variable irrespective of what modules/programs are called in that single session.
When it's calling RFC-enabled Function Modules (FM), a new system stack is created in the called system and only the export parameters defined in the called FM can be retrieved in ECC when the called FM has finished.
Is there a way to access another system stack's global variables in ABAP?
For example, in my case:
- The FM
BAPI_MATERIAL_AVAILABILITY
in the ECC system calls via RFC the FMBAPI_APOATP_CHECK
in the APO system. - When the APO FM finishes, I want to access some global variables of the APO system stack apart from the parameters defined in the APO RFC Function module. I need to access GTC object reference in ECC system.
PS: normally we use below ABAP statement to access memory from same stack, but it doesn't work when the memory is in another system:
ASSIGN '(PrgmName)Globalvariable' TO FIELD-SYMBOLS(<lo_data>).
回答1:
As the RFC connection is not automatically closed after the call, the memory of the user session is retained, right after this call, so you may call a custom RFC-enabled function module that you create in the APO system, that accesses the memory you wish and return its value. Note that an object reference cannot be passed via RFC.
So that you better understand, I adapted the official figure about memory areas to show how a RFC call reuses the memory when the connection is not closed between 2 ABAP systems:
Legend (arrows "1" and "2"):
- At the first RFC call, a connection is opened, a new User Session is created, ABAP session and internal session. The global variables are stored in the block entitled "(Data) Object" inside the internal session. At the end of the call, the connection is retained, including the first internal session and its global variables.
- At the next RFC call using the same connection (the existing connection is reused), the user session is reused (along with its ABAP and internal sessions) to execute the function module, consequently it may access the global variables of the previous call(s).
来源:https://stackoverflow.com/questions/57231124/accessing-stack-memory-of-rfc-called-system