CALL METHOD

Use

The ABAP keyword CALL METHOD calls the method m of the object obj. m can be literal or a variable.

Basic Form:

CALL METHOD OF obj m

Additions:

  1. ... = f

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

  3. ... NO FLUSH.

Normally, all consecutive OLE statements are buffered by the ABAP processor and sent to the presentation server in bundled form. But it is still possible for a statement to refer to the results of preceding statements.

In debugging, however, you should remember that the values of the return parameters cannot be displayed until directly before execution of the first ABAP non-OLE statement. A command that refers to an object not yet generated by any OLE statement terminates the automatic bundling.

The return code value of SY-SUBRC indicates whether all the bundled commands have been successfully executed. It can have the following values:

  • SY-SUBRC = 0:

    All commands were successfully executed.

  • SY-SUBRC = 1:

    When communicating with the presentation server, a system error occurred. The field SY-MSGLI contains a short description of the error.

  • SY-SUBRC = 2:

    A method call resulted in an error.

  • SY-SUBRC = 3:

    Setting a property resulted in an error.

  • SY-SUBRC = 4:

    Reading a property resulted in an error.

CALL METHOD belongs to a group of key words that allows you to process external objects with ABAP. At present, only the object model OLE2 is supported. All objects to be processed must therefore be of type OLE2_OBJECT. This type and other necessary data are defined in the INCLUDE module OLE2INCL.

Extras

  • ... = f

    The addition =f saves the return parameter of the method in the variable f. The return value can also be of type OLE2_OBJECT. This addition must always come before other additions.

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

    The addition EXPORTING transfers values from fields to the parameters of the method. p1, p2,.. are either keyword parameters or position parameters.

    If the parameters have to be ordered according to the sequence, then p1, p2,... have to begin with a # followed by the position number of the parameter. Only position parameters are currently supported.

    The EXPORTING parameters always come at the end of the statement.

  • ... NO FLUSH.

    The addition NO FLUSH continues the collection process, even if the next command is not an OLE statement. This means, for example, that a series of properties can be set in a loop and downloaded to the presentation server in a single transport operation.

    If NO FLUSH is used, programmers must ensure that they do not rely on the contents of return parameters that are not yet filled. Also, all objects must be initialized in a bundle, i.e. they must be generated by an OLE call that has already been executed.

    Every FREE statement always causes an exchange of the buffer.

    You open an EXCEL file using the Open method.

    INCLUDE OLE2INCL. 
    DATA  EXCEL       TYPE OLE2_OBJECT. 
    DATA  WORKBOOK    TYPE OLE2_OBJECT.
    
    CREATE OBJECT EXCEL 'Excel.Application'. 
    CALL METHOD OF EXCEL 'WORKBOOKS' = WORKBOOK.
    
    CALL METHOD OF WORKBOOK 'Open' EXPORTING #1 = 'C:\EX1.XLS'.