SUB ROUTINES


Sub routines contains piece of ABAP code which are mainly used for readability and Re-usability
These are also used for local modularization.

SYNTAX
The Syntax contains two steps
      1.Sub routine definition
      2.Sub routine Implementation

Syntax for Subroutine definition

 Using <V1> <V2>
Changing <CH1> <CH2>
Tables <IT1> <IT2>
     Perform <sub routine>
 Actual Parameters
Syntax for Subroutine Implementation

Using <V1> <V2>
Changing <CH1> <CH2> 
Tables <IT1> <IT2>

Form <sub routine>




Formal Parameters
END FORM.
Types of Sub Routines
 There are two types of Sub routines
1. Local Sub Routines
2. Global Sub Routines

LOCAL SUB ROUTINES
 If Sub routine definition and implementation are available in same program

then it is called as local sub routines.
i.e. if PERFORM And FORM…… END FORM, are available in same program
then it is called as local sub routines.

Global sub routines
 If sub routines definition is available in one program and sub routine implementation is available in another program then it is called as global

Subroutines (or) external sub routines.
Syntax:                                           Programe-1
                                                              
Perform <sub routine> in program < program name >
                                                   Using <V1> <V2>
                                                   Changing <CH1> <CH2>
                                                   Tables <IT1> <IT2>.

                                                         Programe-2

Form <sub routine> Using <V1> <V2>
                                      Changing <CH1> <CH2>
                                      Tables <IT1> <IT2>.


PARAMETERS OF SUB ROUTINES:

USING: Importing variables to sub routines are defined with using.
CHANGING: Exporting variables are defined with changing.
TABLES: Internal tables for importing and exporting are defined with tables.



TYPES OF PASSING VALUES :

There are 3 types to send the values from sub routine definition to sub routine implementation

1. Pass by value (or) call by value
2. Pass by reference
3. Pass by value and return

PASS BY REFERENCE:
In this type, the actual and formal parameters will be referring to the same memory location
If any changes are made to the formal parameters the actual parameters will also be effected
Ex Prog :
The Output is:

Here we are changing the formal parameter, the actual parameter is automatically changed…..since both are referring to same memory.



PASS BY VALUE :
In this type the actual and formal parameters will be referring to separate memory locations
If your changes are made to the formal parameters it will not affect the actual parameters.
Pass By Value is identified by the keyword VALUE().


Ex Prog:

The Output is:


Here we are changing the formal parameter, but the actual parameter is not changed…..since both are referring to different memory.

PASS BY VALUE AND RETURN:
In this type the actual and formal parameters will be referring to separate memory locations
If any changes are made to the formal parameters , the actual parameters will be changed
Pass By Value and Return identified by Changing Value().

Only when sub routine implementation (or) the entire sub routine is executed .

Ex Prog:
The output is:


Messages in Abap

All the messages are stored in a class called as message class
SE 91 is the T-code for creating message class
Generally there will be a single message class for entire project.

MESSAGE-ID:
It is a key word which is used to assign the message class to our report so that,
Our report can access all the messages in the message class.

TYPES OF MESSAGES:
             Type
   Description
                E

                S

                W

                I
  
                A
      Error

      Success

     Warning

     Information

     Abort


Message Parameters:

 ‘&’ is the symbol use to substitute a variable or parameter in to the message
 We can substitute a maximum of 4 substitutional parameters

SYNTAX:

1. MESSAGE <MSG TXT> TYPE <MSG TYPE>
2. MESSAGE <MSG TYPE> <MSG NO>
3. MESSAGE <MSG TYPE > <MSG NO> WITH <SV1> <SV2> SV3>……


Ex on Message Class: Go to SE91->provide a name ->create->define the messages as below
MESSAGE                                MESSAGE SHORT TEXT
00                                            Material doesn’t exit
01                                            Material & class not exit ( we generally use in real time)
02                                            & & & &




Previous
Next Post »