abapOpenChecks - Installation - Checks - Utilities - Links

CHECK_45 - Use expressions

Use lines( ) expression

DESCRIBE TABLE lt_table LINES lv_lines

Can be reduced to

lv_lines = lines( lt_table ).

Sometimes lv_lines is only used once after this, in this case consider removing the variable and replacing with the expression.

Use NEW abc( ) expression

DATA: lo_foo TYPE REF TO zcl_foobar.
CREATE OBJECT lo_foo
  EXPORTING
    iv_moo = 'ABC'.

Can be reduced to

DATA(lo_moo) = NEW zcl_foobar( 'ABC' ).

Declare variable in LOOP statement

DATA: ls_foo LIKE LINE OF lt_table.
LOOP AT lt_table INTO ls_foo.
   ...
ENDLOOP.

Can be reduced to

LOOP AT lt_table INTO DATA(ls_foo).
   ...
ENDLOOP.

Similarily with FIELD-SYMBOLS

Use condense( )

todo

Use concate_lines_of( )

todo

Use shift_left( ) or shift_right( )

todo

Use to_upper( ) or to_lower( )

todo

Use translate( )

todo

Use string templates

todo

Use REF

GET REFERENCE OF i_data INTO lo_data.

can be replaced with

lo_data = REF #( i_data )

see example: https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abapget_reference.htm

Configuration

todo