Skip to content

Latest commit

 

History

History
122 lines (102 loc) · 3.86 KB

EscapeCharForParametersRule.md

File metadata and controls

122 lines (102 loc) · 3.86 KB

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

Standardize escaping of !parameters

Removes or adds the ! escape character for parameter names in method declarations, making its usage independent from which IDE the method was created with.

Options

  • Use ! escape character for parameters [only if parameter name is an ABAP word]

Examples

CLASS cl_escape_char_for_params DEFINITION.
  PUBLIC SECTION.
    METHODS:
      " SAP GUI creates method declarations with ! before each parameter name,
      " but not before VALUE(...), REFERENCE(...) or in the RAISING / EXCEPTIONS section:
      any_chained_method
        IMPORTING
          !it_source_table  TYPE ty_tt_any OPTIONAL
          !iv_name          TYPE string
        EXPORTING
          !et_error_table   TYPE ty_tt_any
          !ev_value         TYPE i
        CHANGING
          !cts_result_table TYPE ty_ts_any,

      " ABAP Development Tools creates method declarations without escape characters:
      other_chained_method
        IMPORTING
          iv_any_param     TYPE i      OPTIONAL
          iv_other_param   TYPE string DEFAULT 'abc'
        RETURNING
          VALUE(rv_result) TYPE char10
        RAISING
          cx_any_exception,

      " the escape char ! is recommendable if the parameter name is also an ABAP word:
      third_chained_method
        IMPORTING
          min    TYPE i DEFAULT 0
          max    TYPE i DEFAULT 100
          sum    TYPE i
        EXPORTING
          output TYPE string.

    " in some rather theoretical cases, ! is strictly necessary to prevent syntax errors:
    METHODS fourth_method
      IMPORTING
        !optional   TYPE i
        !default    TYPE i
        !preferred  TYPE i OPTIONAL
        !exporting  TYPE i OPTIONAL
      EXPORTING
        !changing   TYPE string
      CHANGING
        !raising    TYPE i
        !exceptions TYPE string.
ENDCLASS.

Resulting code:

CLASS cl_escape_char_for_params DEFINITION.
  PUBLIC SECTION.
    METHODS:
      " SAP GUI creates method declarations with ! before each parameter name,
      " but not before VALUE(...), REFERENCE(...) or in the RAISING / EXCEPTIONS section:
      any_chained_method
        IMPORTING
          it_source_table  TYPE ty_tt_any OPTIONAL
          iv_name          TYPE string
        EXPORTING
          et_error_table   TYPE ty_tt_any
          ev_value         TYPE i
        CHANGING
          cts_result_table TYPE ty_ts_any,

      " ABAP Development Tools creates method declarations without escape characters:
      other_chained_method
        IMPORTING
          iv_any_param     TYPE i      OPTIONAL
          iv_other_param   TYPE string DEFAULT 'abc'
        RETURNING
          VALUE(rv_result) TYPE char10
        RAISING
          cx_any_exception,

      " the escape char ! is recommendable if the parameter name is also an ABAP word:
      third_chained_method
        IMPORTING
          !min    TYPE i DEFAULT 0
          !max    TYPE i DEFAULT 100
          !sum    TYPE i
        EXPORTING
          !output TYPE string.

    " in some rather theoretical cases, ! is strictly necessary to prevent syntax errors:
    METHODS fourth_method
      IMPORTING
        !optional   TYPE i
        !default    TYPE i
        !preferred  TYPE i OPTIONAL
        !exporting  TYPE i OPTIONAL
      EXPORTING
        !changing   TYPE string
      CHANGING
        !raising    TYPE i
        !exceptions TYPE string.
ENDCLASS.

Related code