Skip to content

variable is assigned but never used not working correctly #331

Description

@Ennowulff

Hey there!

please see the following code

CLASS zcl_demo_01 DEFINITION
  PUBLIC FINAL
  CREATE PUBLIC.

  PUBLIC SECTION.
    METHODS replace_text_in
      IMPORTING
        mailtext        TYPE string
        with            TYPE clike
        if              TYPE clike
        text            TYPE clike OPTIONAL
      RETURNING
        VALUE(r_result) TYPE string.

  PRIVATE SECTION.
    TYPES: BEGIN OF _changed_parts,
             one   TYPE abap_bool,
             two   TYPE abap_bool,
             three TYPE abap_bool,
           END OF _changed_parts.

    DATA changed_parts TYPE _changed_parts.
ENDCLASS.


CLASS zcl_demo_01 IMPLEMENTATION.
  METHOD replace_text_in.
    ASSIGN COMPONENT if OF STRUCTURE changed_parts TO FIELD-SYMBOL(<field>).
    IF sy-subrc > 0.
      RETURN.
    ENDIF.

    " TODO: variable is assigned but never used (ABAP cleaner)
    DATA(findstr) = |${ if }%|.
    r_result = mailtext.
    DATA(replacestr) = |<p>{ with }{ COND #( WHEN text IS SUPPLIED THEN |: <b>{ text }</b>| ELSE `` ) }</p>|.
    IF <field> IS NOT INITIAL.
      REPLACE findstr WITH replacestr INTO r_result.
    ELSE.
      REPLACE findstr WITH `` INTO r_result.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

ABAP cleaner thinks that the variable findstr is not used, but it is by REPLACE.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions