Skip to content

Latest commit

 

History

History
103 lines (73 loc) · 3.94 KB

CallMethodRule.md

File metadata and controls

103 lines (73 loc) · 3.94 KB

<-- previous rule | overview | next rule -->

Replace CALL METHOD with functional call

Replaces obsolete CALL METHOD statements with functional calls, adding parentheses, if missing.

Keeps CALL METHOD if dynamic typing is used for the method name, since no function equivalent is available here.

This rule is part of the essential profile, as it is explicitly demanded by the Clean ABAP Styleguide.

References

Options

  • Unchain CALL METHOD: chains (required for processing them with this rule)

Examples

  METHOD replace_call_method.
    CALL METHOD lo_any_instance->any_method
      EXPORTING iv_param = iv_param
      IMPORTING ev_param = ev_param
      CHANGING  cv_param = cv_param.

    " obsolete EXPORTING will be removed:
    CALL METHOD any_method_name
      EXPORTING iv_name   = iv_name
                iv_value  = iv_value.

    " RECEIVING may be omitted, depending on Omit RECEIVING rule:
    CALL METHOD other_method_name
      EXPORTING iv_name   = iv_name
                iv_value  = iv_value
      RECEIVING rv_result = DATA(lv_result).

    " dynamic method calls cannot be replaced
    CALL METHOD mo_any_instance->(iv_dynamic_method_name)
      EXPORTING iv_par = iv_par. 

    CALL METHOD (iv_dynamic_class_name)=>(iv_dynamic_method_name)
      EXPORTING iv_par = iv_par. 

    " chains can only be processed if they are first unchained
    CALL METHOD: any_method,
                 other_method EXPORTING iv_value = iv_value,
                 mo_any_instance->(iv_dynamic_method_name).

    CALL METHOD third_method EXPORTING iv_name =: 'abc', 'def', 'ghi'.
  ENDMETHOD.

Resulting code:

  METHOD replace_call_method.
    lo_any_instance->any_method(
      EXPORTING iv_param = iv_param
      IMPORTING ev_param = ev_param
      CHANGING  cv_param = cv_param ).

    " obsolete EXPORTING will be removed:
    any_method_name(
        iv_name   = iv_name
        iv_value  = iv_value ).

    " RECEIVING may be omitted, depending on Omit RECEIVING rule:
    DATA(lv_result) = other_method_name(
                          iv_name   = iv_name
                          iv_value  = iv_value ).

    " dynamic method calls cannot be replaced
    CALL METHOD mo_any_instance->(iv_dynamic_method_name)
      EXPORTING iv_par = iv_par.

    CALL METHOD (iv_dynamic_class_name)=>(iv_dynamic_method_name)
      EXPORTING iv_par = iv_par.

    " chains can only be processed if they are first unchained
    any_method( ).
    other_method( iv_value = iv_value ).
    CALL METHOD mo_any_instance->(iv_dynamic_method_name).

    third_method( iv_name = 'abc' ).
    third_method( iv_name = 'def' ).
    third_method( iv_name = 'ghi' ).
  ENDMETHOD.

Related code