Thursday, April 10, 2008

CALL FUNCTION SYNTAX FOR SAP ABAP

Variant 1

CALL FUNCTION func.

Additions



1. ... EXPORTING p1 = f1 ... pn = fn
2. ... IMPORTING p1 = f1 ... pn = fn
3. ... TABLES p1 = itab1 ... pn = itabn
4. ... CHANGING p1 = f1 ... pn = fn
5. ... EXCEPTIONS except1 = rc1 ... exceptn = rcn

Effect

Calls the function module func ; func can be a literal or a variable.
To edit function modules, select Tools -> ABAP/4 Workbench -> Function Library .
The assignment of parameters is by name ( p1 , p2 , etc.), not by sequence.
To return from the function module, you use the key word EXIT, unless EXIT occurs in a loop or a subroutine.

Note

You can use the editor commands " SHOW FUNCTION func " and " SHOW FUNCTION * " to get information about the function module func or any other function module.

Addition 1

... EXPORTING p1 = f1 ... pn = fn

Effect

EXPORTING passes fields, field strings or internal tables to the function module. You must declare the parameters p1 ... pn in the function interface as import parameters. When you call the function module, you must assign values to all import parameters which are not flagged in the interface definition as optional and do not have any default values.

Addition 2

... IMPORTING p1 = f1 ... pn = fn

Effect

IMPORTING passes fields, field strings or internal tables from the function module back to the calling program. The parameters p1 ... pn must be declared as export parameters in the function interface.

Addition 3

... TABLES p1 = itab1 ... pn = itabn

Effect

TABLES passes references to internal tables. The parameters p1 ... pn must be declared as table parameters in the function interface. When you call the function module, you must assign values to all table parameters which are not flagged as optional in the interface definition.

Addition 4

... CHANGING p1 = f1 ... pn = fn

Effect

CHANGING passes fields, field strings or internal tables to the function module and the changed values are returned. The parameters p1 ... pn must be declared as CHANGING parameters in the function interface. When you call the function module, you must assign values to all CHANGING parameters of the function module which are not flagged as optional in the interface definition and have no default values.

Addition 5

... EXCEPTIONS except1 = rc1 ... exceptn = rcn

Effect

EXCEPTIONS lists the exceptions to be handled by the calling program itself. At the end of the exception list, you can use OTHERS to refer to all the remaining exceptions.
If one of the listed exceptions occurs, SY-SUBRC is set to the appropriate value rc (a number literal!) and control passes back to the calling program. By specifying a return code, you can divided the exceptions into classes. With the second form, without "=rc", SY-SUBRC is set to a value other than 0 if an exception occurs.
If the function module triggers an exception (with the statements RAISE and MESSAGE ...RAISING ) and the exception is not to be handled by the calling program itself,

  • RAISE terminates the program with a runtime error;
  • MESSAGE ... RAISING outputs the message.

Note

The following EXCEPTIONS are predefined by the system and have a special meaning:

  • OTHERS : Covers all user-defined exceptions in the called function module.
  • ERROR_MESSAGE : This exception instructs the system to ignore S messages, I messages and W messages until return from the function module (although they still appear in the log during background processing). When an E message or an A message occurs, the called function module terminates, as if the exception ERROR_MESSAGE has been triggered.

Examples

 
DATA: FIELD(30) VALUE 'Example: This is a field.',
      head(30).
CALL FUNCTION   'STRING_SPLIT'
     EXPORTING  DELIMITER = ':'


                STRING    = FIELD
     IMPORTING  HEAD      = HEAD
                TAIL      = FIELD
     EXCEPTIONS NOT_FOUND = 1
                OTHERS    = 2.
CASE SY-SUBRC.
  WHEN 1. ...
  WHEN 2. ....
ENDCASE.
...
 
DATA: BEGIN OF TAB1 OCCURS 10, X, END OF TAB1,
      BEGIN OF TAB2 OCCURS 20, Y, END OF TAB2.
CALL FUNCTION 'ITAB_COPY'
     TABLES   TAB_IN    = TAB1
TAB_OUT = TAB2.

Runtime errors

  • CALL_FUNCTION_NOT_FOUND : The called function is unknown.
  • CALL_FUNCTION_NO_VB : Only update function modules can be called in the update task.
  • CALL_FUNCTION_NOT_ACTIVE : The called function is known, but not active.
  • CALL_FUNCTION_PARM_MISSING : The function expects a parameter, but none was passed by the calling program.
  • CALL_FUNCTION_PARM_UNKNOWN : The calling program passed a parameter which the function does not recognize.
  • CALL_FUNCTION_CONFLICT_LENG : The function expected a different actual parameter length.
  • CALL_FUNCTION_CONFLICT_TYPE
  • CALL_FUNCTION_CONFLICT_GEN_TYP : The actual parameter type does not satisfy the requirements of the function interface.
  • CALL_FUNCTION_WRONG_ALIGNMENT : An actual parameter does not satisfy the alignment requirements of the corresponding formal parameter.
  • CALL_FUNCTION_BASE_LITL : A literal was supposed to be passed to a structured formal parameter.

No comments:

Blog Archive