Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

subroutines vs includes

Former Member
0 Likes
7,761

hi experts,

what is the difference between subroutines & includes?

includes doesn't have parameter interface, where subroutines have. other than this, i want to know remaining differences.

some one plz help me in this regard.

thanks in advance.

hi experts,

what is the difference between subroutines & includes?

includes doesn't have parameter interface, where subroutines have. other than this, i want to know remaining differences.

some one plz help me in this regard.

thanks in advance.

6 REPLIES 6
Read only

Former Member
0 Likes
4,373

Hi Frd

Subroutines : Subroutines are procedures that you can define in any ABAP program and also call from any program. Subroutines are normally called internally, that is, they contain sections of code or algorithms that are used frequently locally. If you want a function to be reusable throughout the system, use a function module.

A subroutine is a block of code introduced by FORM and concluded by ENDFORM.

FORM <subr> [USING ... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ]

[CHANGING... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ].

...

ENDFORM.

Includes : Include programs are global R/3 Repository objects. They are solely for modularizing source code, and have no parameter interface.

Library: Include programs allow you to use the same source code in different programs. For example, this can be useful if you have lengthy data declarations that you want to use in different programs.

Order. Include programs allow you to manage complex programs in an orderly way. Function groups and module pools use include programs to store parts of the program that belong together. The ABAP Workbench supports you extensively when you create such complex programs by creating the include programs automatically and by assigning them unique names. A special include is the TOP include of a program. If you name it according to the naming convention, it is always included in program navigation and in the syntax check.

Reward Me Points

By

Pari

Read only

Former Member
0 Likes
4,373

Hi,

Include programs allow you to use the same source code in different programs. For example, this can be useful if you have lengthy data declarations that you want to use in different programs.

An include program cannot run independently, but must be built into other programs. Include programs can contain other includes.

Subroutines are procedures that you can define in any ABAP program and also call from any program. Subroutines are normally called internally, that is, they contain sections of code or algorithms that are used frequently locally. If you want a function to be reusable throughout the system, use a function module.

Reward points if helpful.

regards,

Ramya

Read only

ak_upadhyay
Contributor
0 Likes
4,373

Hi,

Subroutines

Subroutines are procedures that you can define in any ABAP program and also call from any program. Subroutines are normally called internally, that is, they contain sections of code or algorithms that are used frequently locally. If you want a function to be reusable throughout the system, use a function module.

Include programs allow you to use the same source code in different programs. For example, this can be useful if you have lengthy data declarations that you want to use in different programs.

An include program cannot run independently, but must be built into other programs. Include programs can contain other includes.

Reward points if useful....

Regards

AK

Read only

Former Member
0 Likes
4,373

hi all,

thank you for ur replies.

but, ur all giving the definitions, about them, which i too have an idea.

what im asking is the difference between subroutine & include.

i know one that is parameter interface. other than this any more differences?

thanks in advance.

Read only

0 Likes
4,373

Hi Mytri,

The differences are :

1. Inlclude is a kind of program which once created can be used any programs

2. User routines are created in program or in incldues where the scope is limited to the particular program and program which uses the particular include

3. Data declared inside the include has global scope and can be used in program which is using th include.

4. Data declared inside the user routine has only local scope and can be used only within the user routine.

Hope this helps you.

Thanks,

Arun

Read only

Former Member
4,373

Hi Mytri,

Actully the purpose of both Subroutines adn Include is Difference... Both r used as Modularization tech but in diff diff situations...

Include prgrams and its data have GLOBAL visibility...

so u can use it by include statement in any other program or include...


INCLUDE ZINCLUDE1.

As Arun Nishore Said.. Subroutines have local visibility ...

But its not alwayse true... U can use subroutines in another prog as well...

two types of subroutines are present..

internal and external...

U can use the subroutine declared in one program say zrep1 to the another program say zrep2.

that is called external subroutin..

Internal subroutines in the sense ..subroutines which are defined and used in a same program…external in the sense if you create a sub routine in one program and you’re calling this subroutine in another program ..then this is external subroutine

or

The name itself implies the internal subroutines defined by form /perform.. can be called within the same prog in which they were declared…

external subroutines can be called outside the program…....

Internal subroutine :

To call a subroutine defined in the same program, you need only specify its name in the PERFORM statement:


PERFORM subr USING p1 p2... 
CHANGING p1 p2... .

External subroutine:

You can specify the name of a subroutine and, in the case of external calls, the name of the program in which it occurs, dynamically as follows:


PERFORM <fsubr> IN PROGRAM <fprog> <USING p1 p2... >
<CHANGING p1 p2... >

Still Doubts...

Include is a Source Code Modules

Source Code Modules

When you modularize source code, you place a sequence of ABAP statements in a module. Then, instead of placing all of the statements in your main program, you just call the module.

When the program is generated, the source code in the modularization unit is treated as though it were actually physically present in the main program. Source code modules help you to avoid repeatedly writing the same set of statements and to make your programs easier to read and understand. They are not used to modularize tasks and functions. You should use procedures for this purpose.

Subroutine is used to define processing block and comes under proceduer...

Procedures contain a set of statements, and are called from other ABAP programs.

You define procedures in ABAP programs. When the program is generated, they remain as standalone modules. You can call procedures in the program in which they are defined, or from external programs. Procedures have an interface for passing data, and can also contain local data.

ABAP contains the following kinds of procedures:

Subroutines

Subroutines are principally for local modularization, that is, they are generally called from the program in which they are defined. You can use subroutines to write functions that are used repeatedly within a program. You can define subroutines in any ABAP program.

Function Modules

Function modules are for global modularization, that is, they are always called from a different program. Function modules contain functions that are used in the same form by many different programs. They are important in the R/3 System for encapsulating processing logic and making it reusable. Function modules must be defined in a function group, and can be called from any program.

Methods

Methods describe the functions and behavior of classes and their instances in ABAP Objects. Methods must be defined in classes. When you call them, you must observe certain special rules of object-oriented programming.

You can call procedures either internally or externally. If you call procedures externally, it is important that you understand how memory is organized in the R/3 System, how screens are processed, and how interface work areas are used.

Hope it will solve your problem..

Reward points if useful..

Thanks & Regards

ilesh 24x7