SAP Tech Pro

SAP Technical Blog

SAP ABAP: Different ways to Call a Program or Transaction Code in ABAP

SAP ABAP: Different ways to Call a Program or Transaction Code in ABAP

Calling Programs

SAP ABAP: Different ways to Call a Program (SUBMIT) in ABAP

The first application program started opens an internal session within the main session. The internal session has a memory area containing 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. If the active application program calls a further application program, the system opens another internal session:-

  • 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 called program is not deleted,but becomes inactive, and its memory contents are placed on a stack.

 

The memory area of each session contains an area called ABAP memory. ABAP memory is available to all internal sessions. ABAP programs can use the EXPORT and IMPORT statements to access it. Data within this area remains intact during a whole sequence of program calls. To pass data to a program which you are calling, the data needs to be placed in ABAP memory before the call is made.

All ABAP programs can also access the SAP memory. This is a memory area to which all sessions within a 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 (also known as SET/GET parameters).

 

Calling Executable Programs

SUBMIT <rep>|(<field>) [AND RETURN] [<options>].

The name of the report to be called can be specified statically in the program or dynamically . If ON RETURN is used , then the control returns to the calling program on completion of the called program at the point from which the called program was invited, else control returns to the level from which you started the calling program.

 

Filling the Selection Screen of a Called Program

SUBMIT... [VIA SELECTION-SCREEN] [USING SELECTION-SET <var>] [WITH <sel> <criterion>] [WITH FREE SELECTIONS <freesel>] [WITH SELECTION-TABLE <rspar>].

 

  • •VIA SELECTION-SCREEN

The selection screen of the called executable program (report) appears. If you transfer values to the program using one or more of the other options, the corresponding input fields in the selections screen are filled. The user can change these values. By default, the system does not display a selection screen after SUBMIT.

  • •USING SELECTION-SET <var>

This option tells the system to start the called program with the variant <var>.

 

  • •WITH <sel> <criterion>

Use this option to fill individual elements <sel> of the selection screen (selection tables and parameters). Use one of the elements <criterion>:

  • •<op> <f> [SIGN <s>], for single value selection

If <sel> is a selection criterion, use <op> to fill the OPTION field, <f> to fill the LOW field, and <s> to fill the SIGN field of the selection table <sel> in the called program.

If <sel> is a parameter, you can use any operator for <op>. The parameter <sel> is always filled with <f>.

  • •[NOT] BETWEEN <f 1> AND <f 2> [SIGN <s>], for interval selection

  • •IN <seltab>, transferring a selection table

  • •This addition fills the selection table <sel> in the called program with the values of the table <seltab> in the calling program. Table <seltab> must have the structure of a selection table. Use the RANGES statement to create selection tables.

 

Affecting Lists in Called Programs

Modifying the List Structure

You can modify the list structure of a called program by using the following additions in the SUBMIT statement:

SUBMIT... [LINE-SIZE <width>] [LINE-COUNT <length>].

Printing Lists

You can send a list from a called program directly to the spool system instead of displaying it on the screen. To do this, use the TO SAP-SPOOL addition in the SUBMIT statement:

SUBMIT... TO SAP-SPOOL <print-parameters>.

 

Saving Lists

Instead of displaying a list on the screen, you can store it in ABAP memory using the EXPORTING LIST TO MEMORY addition in the SUBMIT statement:

SUBMIT... AND RETURN EXPORTING LIST TO MEMORY.

This statement stores the list in ABAP memory, allowing the calling program to access it once the called program has finished. You must use the AND RETURN addition in this case. You cannot use the additions EXPORTING LIST TO MEMORY and TO SAP-SPOOL together.

The function group SLST provides function modules for accessing the saved list, including for example:

  • •LIST_FROM_MEMORY

  • •WRITE_LIST

  • •DISPLAY_LIST

 

Program Statements to Leave a Called Program

Usually, the user exits a program called using SUBMIT ... AND RETURN by choosing F3 or F15 from list level 0 of the called report.

To execute further statements before returning to the called program (for example, to place data in ABAP memory using the EXPORT statement), you need to modify the user interface of the called program. For example, you can define your own function code for the Back function and process it in the AT USER-COMMAND event. After you have written your additional statements, you can leave the called program using the LEAVE statement.

 

REPORT REP1 NO STANDARD PAGE HEADING. DATA: ITAB TYPE I OCCURS 10, NUM TYPE I. SUBMIT REP2 AND RETURN. IMPORT ITAB FROM MEMORY ID 'HK'. LOOP AT ITAB INTO NUM. WRITE / NUM. ENDLOOP.

REPORT REP2 NO STANDARD PAGE HEADING. DATA: NUMBER TYPE I, ITAB TYPE I OCCURS 10. SET PF-STATUS 'MYBACK'. DO 5 TIMES. NUMBER = SY-INDEX. APPEND NUMBER TO ITAB. ENDDO. TOP-OF-PAGE. WRITE 'Report 2'. ULINE. AT USER-COMMAND. CASE SY-UCOMM. WHEN 'MBCK'. EXPORT ITAB TO MEMORY ID 'HK'. LEAVE. ENDCASE.

Calling Transactions

If you do not want to return to the calling program at the end of the new transaction:-

LEAVE TO TRANSACTION <tcod> [AND SKIP FIRST SCREEN].

If, on the other hand, you do not want to return to the calling program at the end of the new transaction, use the statement:

CALL TRANSACTION <tcod> [AND SKIP FIRST SCREEN] [USING <itab>].

If the first screen calls itself as the next screen, you cannot skip it. The USING ITAB addition in the CALL TRANSACTION statement allows you to pass an internal table <itab> to the new transaction. <itab> has the form of a batch input table.

 

SAP Memory

SAP memory is a memory area to which all main sessions within a SAPgui have access. Can be used 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 (also known as SET/GET parameters). These parameters can be set either for a particular user or for a particular program using the SET PARAMETER statement. Other ABAP programs can then retrieve the set parameters using the GET PARAMETER statement. The most frequent use of SPA/GPA parameters is to fill input fields on screens .

Passing Data Between Programs

ABAP Memory

ABAP memory is a memory area that all ABAP programs within the same internal session can access using the EXPORT and IMPORT statements. Data within this area remains intact during a whole sequence of program calls. To pass data to a program which you are calling, the data needs to be placed in ABAP memory before the call is made. 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 SPA/GPA Parameters

SPA/GPA parameters are values that the system stores in the global, user-specific SAP memory which allows to pass values between programs. A user can access the values stored in the SAP memory during one terminal session for all parallel sessions. Each SPA/GPA parameter is identified by a 20-character code. You can maintain them in the Repository Browser in the ABAP Workbench. The values in SPA/GPA parameters are user-specific.

To fill one: SET PARAMETER ID <pid> FIELD <f>.

To read an SPA/GPA parameter:GET PARAMETER ID <pid> FIELD <f>.

If the system does not find a value for <pid> in the SAP memory, it sets SY-SUBRC to 4, otherwise to 0.

 

On a selection screen, you link fields to parameters using the MEMORY ID addition in the PARAMETERS or SELECT-OPTIONS statement.

On a screen, you link fields to parameters in the Screen Painter. When you define the field attributes of an input field, you can enter the name of an SPA/GPA parameter in the Parameter IDfield in the screen attributes. The SET parameter and GET parameter checkboxes allow you to specify whether the field should be filled from the corresponding SPA/GPA parameter in the PBO event, and whether the SPA/GPA parameter should be filled with the value from the screen in the PAI event.

Add comment

Before Buying, Compare Prices at Topprice.in

Topprice.in