Subroutines
Subroutines
What is a subroutine?
What are subroutines in SAP Programs?
Explain Subroutine in SAP ABAP?
Subroutines are procedures that can define in any program and call from any ABAP program. Subroutines normally contains sections code or algorithms.
Subroutines can be defined anywhere in the program and no restriction on where to define. Subroutines can be defined using FORM and ENDFORM statements.
PERFORM statement used to call the subroutine. PERFORM and FORM must contain the same number of parameters.
What are the various types of parameters and how are they distinguished from one another?
What are different types of parameters? How can you distinguish between different kinds of parameters?
The different types of parameters by their coding placement are -
- Formal Parameters - These are defined during the definition of subroutine with the 'FORM' statement.
- Actual Parameters - These are specified during the call of a subroutine with the 'PERFORM' statement.
The different kind of parameters by their functionality are -
- Input parameters are used to pass data to subroutines.
- Output parameters are used to pass data from subroutines.
Describe the Difference Between Macro and Subroutine?
Macros can only be used in the program they are defined in and only after the definition are expanded at compilatio/ generation. A MACRO is more or less an abbreviation for some lines of code that are used more than once or twice.Since debugging a MACRO is not really possible, prevent the use of them (I’ve never used them, but seen them in action).
Subroutines (FORM) can be called from both the program they are defined in and other programs. A FORM is a local subroutine (which can be called external). A FUNCTION is (more or less) a subroutine that is called external. If the subroutine is used only local (called internal) use a FORM. If the subroutine is called external (used by more than one program) use a FUNCTION.
What are the parameters that are used?
The two main parameters used and those are - formal parameters and actual parameters.
What are the ways in which both formal and actual parameters are different?
The manner of functionality is the only thing that differentiates formal and actual parameters.
What is the difference between PASS BY VALUE and PASS BY REFERENCE?
These concepts are generally used for Function modules or Subroutines etc.
For example, we are passing a variable lv_num using the function module -
CALL FUNCTION 'NEW_FM1'
EXPORTING
VAR = lv_num.
When we PASS lv_num by VALUE, the actual value of lv_num is copied into VAR.
When we PASS lv_num by REFERENCE, the reference, or the memory address of lv_num is passed to the Function module. So, VAR and lv_num refers to the same memory address and have the same value.
What are conversion routines in SAP ABAP?
Conversion routines implements nonstandard conversions from display format to sap internal format and vice-versa.
What is the difference between the function module and a normal ABAP/4 subroutine?
Sub routines do not return values. Sub routines do not return exceptions. Sub routines cannot be tested independently.
Declaring data as common parts is not possible for function modules. Function modules are stored in a central library.
Is it possible to call a subroutine of one program from another program?
True.
Can we call subroutine in another program? and what is the syntax?
Yes, we can call using external subroutine.
syntax-
perform form_tc(report_name).