abapOpenChecks - Installation - Checks - Utilities - Links

CHECK_45 - Use expressions

Improve this page
RFC enabled
CODE

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( )

CONDENSE field.

can be replaced with

field = condense( field ).

see documentation: https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abencondense_functions.htm

Use concat_lines_of( )

CONCATENATE LINES OF itab INTO field.

can be replaced with

field = concat_lines_of( itab ).

see documentation: https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abenconcatenation_functions.htm

Use shift_left( ) or shift_right( )

SHIFT field LEFT.

can be replaced with

field = shift_left( field ).

see documentation: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abenshift_functions.htm

Use to_upper( ) or to_lower( )

TRANSLATE field TO UPPER CASE.

can be replaced with

field = to_upper( field ).

see documentation: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abencase_functions.htm

Use translate( )

TRANSLATE field USING mask

can be replaced with

field = translate( val = field from = from to = to )

see documentation: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abentranslate_functions.htm

Use string templates

CONCATENATE field1 field2 INTO field3.

can be replaced with

field = field1 && field2.

see documentation: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abenstring_templates.htm

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

Use CORRESPONDING #( )

MOVE-CORRESPONDING struc1 TO struc2.

can be replaced with

struc2 = CORRESPONDING #( struc1 ).

Warning: struc2 will be initialized before the move.

see documentation: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abenconstructor_expr_corresponding.htm

Configuration

todo