larshp/upDOWNci

CL_CI_TEST_ABAP_NAMING_NEW dump, type T_S_OPTION

Closed this issue · 2 comments

CL_CI_TEST_ABAP_NAMING_NEW dump, type T_S_OPTION

The problem is in the method create_structure. Please import the class name (iv_class). Then change the code:

METHOD create_structure.

DATA:
  lt_components  TYPE cl_abap_structdescr=>component_table,
  lo_structdescr TYPE REF TO cl_abap_structdescr,
  descr_ref      TYPE REF TO cl_abap_typedescr,
  data_value     TYPE REF TO object,                    "#EC NEEDED
  type_descr_ref TYPE REF TO cl_abap_typedescr,
  data_name      TYPE        string,                    "#EC NEEDED
  structdescr    TYPE REF TO cl_abap_structdescr,
  objectdescr    TYPE REF TO cl_abap_objectdescr,
  tabledescr     TYPE REF TO cl_abap_tabledescr.

FIELD-SYMBOLS:
  <ls_component> LIKE LINE OF lt_components,
  <ls_type>      LIKE LINE OF it_types.

IF it_types IS INITIAL.
  RETURN.
ENDIF.

LOOP AT it_types ASSIGNING <ls_type>.

  APPEND INITIAL LINE TO lt_components ASSIGNING <ls_component>.
  <ls_component>-name = <ls_type>-name.
  cl_abap_typedescr=>describe_by_name( EXPORTING  p_name         = <ls_type>-type
                                       RECEIVING  p_descr_ref    = descr_ref
                                       EXCEPTIONS type_not_found = 1
                                                  OTHERS         = 2 ).
  IF sy-subrc <> 0. " typically rasied by class pool declared types
    CREATE OBJECT data_value TYPE (iv_class).
    MOVE cl_abap_typedescr=>describe_by_object_ref( data_value ) TO type_descr_ref.
    objectdescr ?= type_descr_ref.
    objectdescr->get_attribute_type( EXPORTING  p_name         = <ls_type>-name
                           RECEIVING  p_descr_ref    = descr_ref
                           EXCEPTIONS attribute_not_found = 1 ).
    IF sy-subrc <> space.
    ELSE.
      <ls_component>-type ?= descr_ref.
    ENDIF.
  ELSE.
  ENDIF.
  <ls_component>-type ?= descr_ref.

ENDLOOP.

SORT lt_components BY name ASCENDING.
DELETE ADJACENT DUPLICATES FROM lt_components COMPARING name.

TRY.
    lo_structdescr = cl_abap_structdescr=>create( lt_components ).
    CREATE DATA rr_data TYPE HANDLE lo_structdescr.
  CATCH cx_sy_struct_comp_name.
    _raise 'error creating structure'.
ENDTRY.

ENDMETHOD. "create_structure

In my opinion, you can deal with all type like this way, I have tested this with the class CL_CI_TEST_ABAP_NAMING_NEW.

It's also a solution for your bypass in the method find_types:

METHOD find_types.

DATA: lv_name  TYPE seocmpname,
      lv_field TYPE string,
      lv_type  TYPE string,
      lt_attr  TYPE seo_attributes.

FIELD-SYMBOLS: <ls_type>      LIKE LINE OF rt_types,
               <ls_attr>      LIKE LINE OF lt_attr,
               <ls_parameter> LIKE LINE OF it_parameters.


lt_attr = lcl_class=>attributes( iv_class ).

LOOP AT it_parameters ASSIGNING <ls_parameter>.
  IF <ls_parameter>-value CA '-'.
    SPLIT <ls_parameter>-value AT '-' INTO lv_name lv_field.
  ELSE.
    lv_name = <ls_parameter>-value.
    CLEAR lv_field.
  ENDIF.

  READ TABLE lt_attr ASSIGNING <ls_attr> WITH KEY cmpname = lv_name.
  IF sy-subrc = 0.
    lv_type = <ls_attr>-type.
  ENDIF.

  APPEND INITIAL LINE TO rt_types ASSIGNING <ls_type>.
  <ls_type>-parameter = <ls_parameter>-name.
  <ls_type>-name = lv_name.
  <ls_type>-type = lv_type.
  <ls_type>-field = lv_field.

ENDLOOP.

ENDMETHOD. "find_types