Sunday, January 19, 2014

TAW10 - PROGRAM CALLS AND DATA STORAGE MANAGEMENT

SYNCHRONOUS PROGRAM


Two options in ABAP for executing a program within a program are the SUBMIT and the CALL TRANSACTION (or LEAVE TO TRANSACTION) statements.
These statements can differ in their effects:
In case one – Insert – the process flow of the calling program pauses while the called program is executed and inserted. After this, the calling program is continued.
In case two – New start – the calling program is terminated as soon as the called program is initiated. When the called program is started, the command inWorking memory is Start new program 2.



CALLING AN EXECUTABLE PROGRAM

Let us designate Program 1 as the calling program and Program 2 as the called program, facilitated by the SUBMIT statement.
You can use the SUBMIT statement to start an executable (type 1) program and exercise some options:
  If you use VIA SELECTION-SCREEN, the standard selection screen of the called program (if any) is displayed.

  If you use AND RETURN, the system resumes processing with the first statement of the calling program after the SUBMIT statement once the called program is finished.


CALLING A TRANSACTION

The system terminates the current program and starts the transaction with the transaction code T_CODE when you use the LEAVE TO TRANSACTION ‘T_CODE’ statement.
This statement is equivalent to entering /NT_CODE in the command field.
The CALL TRANSACTION ‘T_CODE’ statement allows you to insert a program with a transaction code into the call chain.
The LEAVE PROGRAM statement is used to force the termination of a program. The system does not display the contents of the first screen in the transaction with AND SKIP FIRST SCREEN addition.


LOGICAL MEMORY MODEL

There is a distinction between internal and external sessions:
  Generally, an external session corresponds to an SAP GUI window.

  External sessions are subdivided into internal sessions placed in a stack.

  Each program that is started occupies its own internal session.


BEFORE INSERTING A PROGRAM


This slide illustrates how a stack inside an external session changes with various program calls. The starting point can be executed by a SUBMIT ... AND RETURN or CALL TRANSACTION statement within a program.


THE INSERTED PROGRAM RUNS


The system creates a new internal session containing the new program context whenever a program is inserted. The new session along with the program context of the calling program remains in the stack.

AFTER THE INSERTED PROGRAM ENDS


The internal session from the top of the stack is deleted with the end of the called program. The processing is resumed in the next highest internal session in the stack.


BEFORE STARTING A NEW EXECUTABLE PROGRAM
While ending a program and starting a new one, keep in mind the distinction between calling an executable program and calling a transaction, with respect to memory areas.
The starting point for the second case (calling a transaction) is the execution of a SUBMIT statement within a program.


THE NEW EXECUTABLE PROGRAM RUNS

If you call an executable program using its program name, you automatically end the calling program. Therefore, the system destroys the internal session of the program that you are terminating, which is the top one from the stack. The system creates a new internal session in the stack, which contains the program context of the called program.
Program contexts created before are retained.


BEFORE STARTING A NEW TRANSACTION
The starting point for a new transaction is the execution of a LEAVE TO TRANSACTION statement within a program.

THE NEW TRANSACTION RUNS

The system creates a new internal session when a transaction code is used to start a program. This internal session contains the program context of the called program. As all the previous internal sessions in the stack are destroyed, the complete stack of internal sessions is initialized, which also means that the ABAP memory is initialized after the call.


PROGRAM GROUPS WITHIN AN INTERNAL SESSION

Let us see how the system responds when a program calls a subroutine of another program.
The system starts an internal session with the creation of a main program group.
It can create any number of additional program groups in the same internal session. Each program group has exactly one main program.
The main program of the subroutine is loaded into the program group of the calling program with the call of an external subroutine.


MAIN/ADDITIONAL PROGRAM


An additional program group is created when a function module or a method is called. This happens when neither the relevant function group nor the class definition is loaded.

DATA TRANSFER BETWEEN PROGRAMS: OVERVIEW

There are various ways of exchanging data between programs that are running in separate program contexts or internal sessions.
Some platform-independent methods can transfer data transiently:
  Using the interface of the called program (usually a standard selection screen)

  By means of the ABAP memory

  Using the SAP memory

  Using database tables

  By means of local files on the presentation server



PASSING DATA USING THE PROGRAM INTERFACE


You can pass data for the input fields when ABAP programs with standard selection screen are called.
You can do so by specifying
  a variant for the selection screen; or

  specific values for the input fields.


PREASSIGNMENT OF INPUT FIELDS


Using WITH in the SUBMIT statement allows you to assign values to the fields on a standard selection screen.
You can also use the RANGE type instead of individual WITH additions to set several choices for a selection option. You can fill the resulting selection table and then pass the whole table to the executable program.
You can use VIA SELECTION-SCREEN to display the standard selection screen when you call the program.
When you use the SUBMIT statement, use the Pattern function in the ABAP Editor to insert an appropriate statement pattern for the program you want to call.
The pattern automatically supplies the names of the parameters and selection options that are available on the standard selection screen.

PASSING DATA USING AN INTERNAL TABLE

You can call a transaction using the CALL TRANSACTION 'T_CODE' USING bi_itab. This helps you access the values from the internal table bi_itab in the screen fields.
This internal table should have the structure BDCDATA. You fill it accordingly.
The return code (sy-subrc) tells you whether the transaction was executed successfully.


FIELDS IN THE GLOBAL TYPE BDCDATA
You can fill an internal table in the batch input format:
  You identify each screen in a transaction by a line in which only the PROGRAM, DYNPRO, and DYNBEGIN fields are filled. Only then can you fill in the screens and process them automatically.

  You also use a new BDCDATA record for each field you want to fill, after a record identifies the screen. These records use the FNAM and FVAL fields.

DATA TRANSFER USING AN INTERNAL TABLE: APPLICATION SAMPLE


The program calls the transaction with the creation of a new customer entry.
If the operation is successful, the new customer record can be entered in the waiting list.
At runtime, you enter the customer name from the input field in CURRENT_NAME and the relevant city in CURRENT_CITY.
To address the command field, use BDC_OKCODE.


RANGE OF ABAP MEMORY AND SAP MEMORY
You can use both the SAP memory and the ABAP memory when you cannot always specify the data to be transferred between two programs:
  The SAP memory is a user-specific memory area for storing field values.

  It can be used between external sessions in the same user session.

  All external sessions of a user session can access the SAP memory.

  The ABAP memory is also user-specific.

  There is a local ABAP memory for each external session.

  It helps exchange ABAP data objects between the internal sessions in the same external session.



PASSING DATA USING THE ABAP MEMORY

You use the EXPORT ... TO MEMORY statement to copy any number of ABAP data objects with their current values to a data cluster in the ABAP memory. With the ID addition, you can identify different clusters.
To copy data from ABAP memory to the corresponding fields of your ABAP program , you use the IMPORT ... FROM MEMORY ID ... statement.


PASSING PARAMETERS USING SAP MEMORY
The memory areas or parameters can be defined in the SAP memory in various ways.
The SET PARAMETER ID statement helps you fill the memory areas directly, and the GET PARAMETER ID statement to read from them.

No comments:

Post a Comment