Caring about ABAP

IT Conference on SAP Technologies, 2017
@LarsHvam
larshp
INVIXO.com

Disclaimer

Fibonacci

function fib(n) {
  if (n <= 2) {
    return 1;
  } else {
    return fib(n-1) + fib(n-2);
  }
}

fib(13);

Fibonacci in ABAP

REPORT zfib01.
PARAMETERs: p_n TYPE i DEFAULT 13.
START-of-SELECTION.
PERform run.
DATA: r TYPE i,     b.
FORM run.
PERFORM f USING p_n r.
WRITE r.
ENDFORM.
* this form calculates fibonac numbers
FORM f USING n r.
data n1 TYPE i.DATA: n2
type i.
data: r1   TYPE p,
r2 TYPE f.
CLEAR r1.
n2 = n - 1. n1 = n2  - 1.
if n = 1.
r = n.
ELSEIF         n:= 2.
MOVE n TO r.
SUBTRACT 1 FrOm r.
ELSE.
PERFORM f USING: n1
r2, n2 r1.
*    PERFORM f USING n2.
ENDIF . r = r + r1 + r2.
ENDFORM.

Static code analysis

  • ATC/SCI

    Manual code review

  • Tools?

    Automatic testing

  • ABAP Unit
  • Design your code to be tested
  • SCI/ATC

    abapOpenChecks
    Extra checks for SCI/ATC
    started 3 years ago
    600 commits
    1 contributor
    ~28000 lines
    7.02 and up
    MIT License

    Background

  • Based on real life examples
  • Fix false positives
  • All checks configurable

  • upDOWNci
  • Checks

    01x - IF in IF
    02 - EXIT or CHECK outside of loop
    03x - Wrong use of TRY-CATCH
    04 - Line length
    05 - 7 bit ASCII
    06 - Check for use of pretty printer
    07 - Functional writing style for CALL METHOD
    08 - Obsolete statement
    09 - Tab instead of spaces
    10 - Use icon_ constants
    11 - Max one statement per line
    12 - Specify SORT order
    13 - Sequential blank lines
    14 - Commented code
    15 - Kernel CALL
    16 - Line contains only . or ).
    17 - Definitions in top of routine
    18 - Empty branch
    19 - Use LINE OF
    20 - Bad indentation
    21 - Unused FORM parameter
    22 - Conditions contain identical code
    23 - Chained Statements
    24x - Identical code blocks
    25 - Selection screen data not referenced
    26 - No direct changes to standard tables
    27 - Last statement is RETURN
    28 - Space before . or ,
    29x - Naming, Local test classes
    30 - EXPORTING can be omitted
    31 - Extended Program Check, Filterable
    32 - Database access
    33 - Append structure field names
    34 - Large WHEN construct
    35 - Message not in use
    36 - Exception text not in use
    37 - Define message texts in SE91
    38 - Avoid use of SELECT-ENDSELECT
    39 - Smartforms global definitions naming
    40 - Check SY-SUBRC
    41 - Empty line in statement
    42 - Identical WHEN code
    43 - Parameter name can be omitted
    44 - EXPORTING can be changed to RETURNING
    45x - Use expressions
    46 - Shadowed variable
    47 - RFC call error handling
    48 - Table DEFAULT KEY
    49x - Double space
    50 - ASSERT and unit test ASSERT
    51x - Open SQL - Escape host variables
    52 - Pragma placement
    53 - Function module recommendations
    54 - CALL TRANSACTION authority check
    55 - Statements can be chained
    56 - Method parameters
    57 - MESSAGE or list processing in global classes
    58 - Method not referenced statically
    59 - Logical expression structure
    60 - Concatenation of string templates
    62 - LOOP simplification/performance
    63 - ABAP Doc - Check parameter consistency
    64 - Unit test not covering class

    CHECK_07 - Functional style

    CALL METHOD lo_columns->set_count_column
      EXPORTING
        value = 'FOOBAR'.
    lo_columns->set_count_column( EXPORTING value = 'FOOBAR' ).

    CHECK_30 - EXPORTING

    lo_columns->set_count_column( EXPORTING value = 'FOOBAR' ).
    lo_columns->set_count_column( value = 'FOOBAR' ).

    CHECK_43 - Parameter name

    lo_columns->set_count_column( value = 'FOOBAR' ).
    lo_columns->set_count_column( 'FOOBAR' ).

    Open Source Collaboration

    Fork
    Commit
    Create Pull Request
    Review
    Merge
    Understanding the GitHub Flow
    abaplint
    ABAP linter
    started 2 years ago
    600 commits
    1 contributor
    ~16000 lines
    Browser + Node.js
    MIT License
    7bit_ascii
    breakpoint
    colon_missing_space
    contains_tab
    definitions_top
    empty_statement
    exit_or_check
    exporting
    functional_writing
    indentation
    line_length
    line_only_punc
    max_one_statement
    obsolete_statement
    parser_error
    sequential_blank
    space_before_colon
    start_at_tab
    whitespace_end

    Syntax Trees!

    On Travis CI

    Other SAP Events

    SAP Inside Tracks

    #sitCPH

    Hope to see you in Barcelona

    #ABAPisNotDead

    https://larshp.github.io/Presentations/itsapcluj2017/code

    Contribute

    http://abapopenchecks.org

    Contribute

    http://github.com/larshp/abaplint

    Twitter

    @LarsHvam