In the Overview of SAP Web AS ABAP, we saw that a user can open up to six SAP windows within an SAP GUI. Each of these windows corresponds to a session on the ABAP application server with its own area of shared memory.
The first ABAP application program that you start in a session opens an internal session within the main session. The internal session has a memory area that contains the ABAP program and its associated data. When the program calls external routines (methods, subroutines or function modules) their main program and working data are also loaded into the memory area of the internal session.
Only one internal session is ever active. If the active application program calls a further application program, the system opens another internal session. Here, there are two possible cases: If the second program does not return control to the calling program when it has finished running, the called program replaces the calling program in the internal session. The contents of the memory of the calling program are deleted. If the second program does return control to the calling program when it has finished running, the session of the calling program is not deleted. Instead, it becomes inactive, and its memory contents are placed on a stack.
The memory area of each session contains an area called ABAP memory. The ABAP memory is available to all internal sessions. ABAP programs can use the EXPORT and IMPORTstatements to access this shared memory. Data within this area remains intact during a whole sequence of program calls. To pass data to a program that you are calling, the data needs to be placed in ABAP memory before the call is made from the internal calling session using the EXPORT statement. The internal session of the called program then replaces that of the calling program. The program called can then read from the ABAP memory using the IMPORT statement. If control is then returned to the program which made the initial call, the same process operates in reverse.
All ABAP programs can also access the SAP memory. This is a memory area to which all sessions within an SAP GUI have access. You can use SAP memory either to pass data from one program to another within a session, or to pass data from one session to another. Application programs that use SAP memory must do so using SPA/GPA parameters. These parameters are often used to preassign values to input fields. You can set them individually for users, or globally according to the flow of an application program. SAP memory is the only connection between the different sessions within an SAP GUI.
The following figure shows how an application program accesses the different areas within shared memory:

In the diagram, an ABAP program is active in the second internal session of the first main session. It can access the memory of its own internal session, ABAP memory and SAP memory. The program in the first internal session has called the program which is currently active, and its own data is currently inactive on the stack. If the program currently active calls another program but will itself carry on once that program has finished running, the new program will be activated in a third internal session.
