11

Sorry for this basic ABAP question. What are the different ways to call methods in ABAP? And what are their "official" names? I've heard of perform, method call, and internal/inline method call.

Perform uses the PERFORM keyword and method call the CALL METHOD syntax, I guess. But what is an "internal" or "inline method call"?

Mike
  • 14,010
  • 29
  • 101
  • 161
Ulrich Scholz
  • 2,039
  • 4
  • 30
  • 51

3 Answers3

14

These are the possibilities of an inline method call.

If you are calling so called functional method which has only IMPORTING parameters and optionally one RETURN parameter you can call it like this.

CLASS lcl_test DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      func_meth
        IMPORTING
          i_param TYPE i
        RETURNING
          VALUE(r_res) TYPE char1.
ENDCLASS.

l_res = lcl_test=>func_meth( 1 ).

* you could also call it like this
l_res = lcl_test=>func_meth( i_param = 1 ).

* also this variant is possible
l_res = lcl_test=>func_meth( EXPORTING i_param = 1 ).

* the traditional CALL METHOD syntax would be like this
CALL METHOD lcl_test=>func_meth
  EXPORTING
    i_param = 1
  RECEIVING
    r_res = l_res.

If there is more than one IMPORTING parameter you have to specify names of the parameters.

CLASS lcl_test DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      func_meth
        IMPORTING
          i_param1 TYPE i
          i_param2 TYPE i
        RETURNING
          VALUE(r_res) TYPE char1.
ENDCLASS.

l_res = lcl_test=>func_meth(
   i_param1 = 1
   i_param2 = 2
).

If there are EXPORTING or CHANGING parameters in the method then an inline call is still possible but the parameter categories have to be explicitly specified.

CLASS lcl_test DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      func_meth
        IMPORTING
          i_param TYPE i
        EXPORTING
          e_param TYPE c
        CHANGING
          c_param TYPE n.
ENDCLASS.

lcl_test=>func_meth(
  EXPORTING
    i_param = 1
  IMPORTING
    e_param = l_param
  CHANGING
    c_param = l_paramc
).
Mike
  • 14,010
  • 29
  • 101
  • 161
Jagger
  • 10,350
  • 9
  • 51
  • 93
1

Good luck in your quest - you will find this task to be much harder than anticipated. For example, ABAP contains a macro processing facility that will make it really hard to find out that an actual method call is taking place. A malicious example that will compile nonetheless:

DATA: l_foo TYPE c LENGTH 32.

DEFINE foo.
  l_&4 = cl_&1_&3&5&2&9if_&1_&3&5_&8~&7_&3&5_c&6( ).
END-OF-DEFINITION.

foo system = u foo uid 32 create static >.

You will find that macros are used extensively in some parts of the system. Good luck finding method calls in that kind of stuff without using the built-in parser and macro processor.

vwegert
  • 18,371
  • 3
  • 37
  • 55
  • I think, it will not be that hard, from what I understood, he has to port abap to java, surely because ot the new jababap stuff. So downloading classes to local textfiles, creating special parser, should work, in fact I even do not think, they will port standard , but only z-stuff. @op: am I right ? – icbytes Feb 06 '15 at 13:47
  • We transform ABAP to ABAP. Just the transformation tool is written in Java. And we cover all of ABAP. Unfortunately, that means ALL. Parser and tool already exist - as the result of 10+ years of work. I've just started to look into it - and into ABAP. There's a mountain in front of me. – Ulrich Scholz Feb 09 '15 at 10:30
0

You have massively mixed up many things. Lets be kind, and start with some basics here:

Method is the official name of a member function of a class, means, if You talk about methods, You talk about object oriented prorgamming ( OOP ). There are about two or three ways of method call variants, at least in abap. Lets go into detail later, after You promise me, to read about this, If You decide to develop following OO-paradigms. And You should.

Function is just a function, a small(or big) piece of code, which can be called from several callers, to be reused. It is no OOP paradigm, and exists since prorgamming started. Nevertheless in abap it has a slight "bigger" definition, let us talk about this in detail, if You promise me, to read about it. And You should, If You want to develop ABAP at all.

Perform ? "Perform" is an abap keyword to call form-routines. Form-routines are the real old school functions-equivalent in abap, most similiar to functions from the good old times, when programming started. Small pieces of reusable code, which can be calles from anywhere in Your prorgamm, but sometimes from somewhere else ( this is too far for You now ).

So, if You are mixing up those three ( or two of those three ) already, then You are not even in a good position, to talk about internal or inline, at all. I am sorry, but it is, as it is. It is no offending.

Do You ever developed in another language ?

icbytes
  • 1,831
  • 1
  • 17
  • 27
  • Actually, I develop in Java and work on an (existing) tool that automatically analyzes and transforms ABAP programs. These ABAP programs are given to us as text, so the tool does not have direct access to SAP systems. I'm a beginner to ABAP and I'm learning on the fly. I promise you to my heart that I will never have the intention to program in ABAP. But in front of me I have gigantic ABAP code bases, stemming from all ages and styles, and I try to figure it out. – Ulrich Scholz Feb 05 '15 at 13:52
  • So, then for perform: perform is followed by a name of a formroutine. If You search for this name in the code, You will find all it's calls. Be carefull and check each include. The definition is preceeded by form. So perform calculate_sth using x , y. Has somewhere its definition like "form calculate_sth using x type i , y type i. " bla endform." – icbytes Feb 05 '15 at 13:56