English 中文(简体)
SAP ABAP Tutorial

SAP ABAP Useful Resources

Selected Reading

SAP ABAP - Include Programs
  • 时间:2024-11-05

SAP ABAP - Include Programs


Previous Page Next Page  

Include programs are global repository objects used to modularize the source code. They allow you to use the same source code in different programs. Include programs also allow you to manage complex programs in an orderly way. In order to use an include program in another program, we use the following syntax −

INCLUDE <program_name>.

INCLUDE statement has the same effect as copying the source code of the include program <program_name> into another program. As include program can’t run independently, it has to be built into other programs. You may also nest include programs.

Following are a couple of restrictions while writing the code for Include programs −

    Include programs can t call themselves.

    Include programs must contain complete statements.

Following are the steps to create and use an Include program −

Step 1 − Create the program (Z_TOBEINCLUDED) to be included in ABAP Editor. Code to be included in ABAP Editor is −

PROGRAM Z_TOBEINCLUDED.  
Write: /  This program is started by: , SY-UNAME,
       /  The Date is: , SY-DATUM,
       /  Time is , SY-UZEIT.

Step 2 − Set the Type of the program to INCLUDE program, as shown in the following screenshot.

Include Programs

Step 3 − Cpck the ‘Save’ button and save the program in a package named ZINCL_PCKG.

Step 4 − Create another program where the program Z_TOBEINCLUDED has to be used. Here we have created another program named Z_INCLUDINGTEST and assigned the type for the program as Executable program.

Step 5 − The coding for Z_INCLUDINGTEST program includes the Z_TOBEINCLUDED program with the help of the INCLUDE statement as shown in the following code.

REPORT Z_INCLUDINGTEST.  
INCLUDE Z_TOBEINCLUDED. 

Step 6 − Save, activate and execute the program.

The above code produces the following output −

This program is started by: SAPUSER 
The Date is: 06.10.2015 
Time is 13:25:11
Advertisements