IMPORTING

From Abap2Java

Jump to: navigation, search

ABAP

The keyword IMPORTING defines that a certain parameter of a method or function module is imported. This means that the parameter value is sent from the calling method to the called method.

"method definition:
METHODS say_hello IMPORTING iv_message TYPE STRING 
                                    iv_count TYPE INT4.
"method implementation:
METHOD say_hello.
  DO iv_count TIMES.
    WRITE iv_message.
  ENDDO.
ENDMETHOD.
"method call:
say_hello( 'Hello World' ). "not possible! 
                            "only possible if there is only one non-optional importing parameter
"method call (alternative syntax):
say_hello( iv_message = 'Hello World' iv_count = 3 ). 
"method call (alternative syntax):
CALL METHOD say_hello EXPORTING iv_number = 'Hello World' iv_count = 3.

To define an importing parameter, the keyword IMPORTING is used, while the keyword EXPORTING is used in the corresponding method call (overview of parameter types).

Java

A parameter is an importing parameter, if it is defined inside the brackets of the method implementation.

//method definition and implementation:
void say_hello( string iv_message, int iv_count ){
  for( int i = 0; i < iv_count; i++ ){
    System.out.print( iv_message );
  }
}
//method call:
say_hello( "Hello World", iv_count );

If there are multiple parameter, ABAP needs the parameter name to know which parameter shall get which value, while Java assigns values to parameters by the order.

Personal tools