diff --git a/src/zcl_excel_common.clas.abap b/src/zcl_excel_common.clas.abap index 67a9e6c..c4a0352 100644 --- a/src/zcl_excel_common.clas.abap +++ b/src/zcl_excel_common.clas.abap @@ -1056,12 +1056,10 @@ CLASS zcl_excel_common IMPLEMENTATION. METHOD recursive_class_to_struct. " # issue 139 -* is working for me - but after looking through this coding I guess -* I'll rewrite this to a version w/o recursion -* This is private an no one using it so far except me, so no need to hurry DATA: descr TYPE REF TO cl_abap_structdescr, wa_component LIKE LINE OF descr->components, attribute_name LIKE wa_component-name, + type_kind TYPE abap_typekind, flag_class TYPE abap_bool. FIELD-SYMBOLS: TYPE any, @@ -1069,6 +1067,9 @@ CLASS zcl_excel_common IMPLEMENTATION. TYPE any. + DESCRIBE FIELD i_source TYPE type_kind. + flag_class = boolc( type_kind = cl_abap_typedescr=>typekind_oref ). + descr ?= cl_abap_structdescr=>describe_by_data( e_target ). LOOP AT descr->components INTO wa_component. @@ -1076,22 +1077,19 @@ CLASS zcl_excel_common IMPLEMENTATION. * Assign structure and X-structure ASSIGN COMPONENT wa_component-name OF STRUCTURE e_target TO . ASSIGN COMPONENT wa_component-name OF STRUCTURE e_targetx TO . -* At least one field in the structure should be marked - otherwise continue with next field - CLEAR flag_class. -* maybe source is just a structure - try assign component... - ASSIGN COMPONENT wa_component-name OF STRUCTURE i_source TO . - IF sy-subrc <> 0. -* not - then it is an attribute of the class - use different assign then + + IF flag_class = abap_false. +* source is a structure - use assign component + ASSIGN COMPONENT wa_component-name OF STRUCTURE i_source TO . + ELSE. +* then it is an attribute of the class - use different assign then CONCATENATE 'i_source->' wa_component-name INTO attribute_name. ASSIGN (attribute_name) TO . - IF sy-subrc <> 0. - EXIT. - ENDIF. " Should not happen if structure is built properly - otherwise just exit to create no dumps - flag_class = abap_true. ENDIF. + IF sy-subrc <> 0.EXIT.ENDIF. " Should not happen if structure is built properly - otherwise just exit to avoid dumps CASE wa_component-type_kind. - WHEN cl_abap_structdescr=>typekind_struct1 OR cl_abap_structdescr=>typekind_struct2. " Structure --> use recursio + WHEN cl_abap_structdescr=>typekind_struct1 OR cl_abap_structdescr=>typekind_struct2. " Structure --> use recursion zcl_excel_common=>recursive_class_to_struct( EXPORTING i_source = CHANGING e_target = e_targetx = ). @@ -1107,12 +1105,10 @@ CLASS zcl_excel_common IMPLEMENTATION. METHOD recursive_struct_to_class. " # issue 139 -* is working for me - but after looking through this coding I guess -* I'll rewrite this to a version w/o recursion -* This is private an no one using it so far except me, so no need to hurry DATA: descr TYPE REF TO cl_abap_structdescr, wa_component LIKE LINE OF descr->components, attribute_name LIKE wa_component-name, + type_kind TYPE abap_typekind, flag_class TYPE abap_bool, o_border TYPE REF TO zcl_excel_style_border. @@ -1121,6 +1117,14 @@ CLASS zcl_excel_common IMPLEMENTATION. TYPE any. + DESCRIBE FIELD e_target TYPE type_kind. + flag_class = boolc( type_kind = cl_abap_typedescr=>typekind_oref ). + IF flag_class = abap_true AND e_target IS INITIAL. +* Only borders will be passed as unbound references. But since we want to set a value we have to create an instance + CREATE OBJECT o_border. + e_target = o_border. + ENDIF. + descr ?= cl_abap_structdescr=>describe_by_data( i_source ). LOOP AT descr->components INTO wa_component. @@ -1130,31 +1134,19 @@ CLASS zcl_excel_common IMPLEMENTATION. ASSIGN COMPONENT wa_component-name OF STRUCTURE i_sourcex TO . * At least one field in the structure should be marked - otherwise continue with next field CHECK CA abap_true. - CLEAR flag_class. -* maybe target is just a structure - try assign component... - ASSIGN COMPONENT wa_component-name OF STRUCTURE e_target TO . - IF sy-subrc <> 0. -* not - then it is an attribute of the class - use different assign then + + IF flag_class = abap_false. +* target is a structure - use assign component + ASSIGN COMPONENT wa_component-name OF STRUCTURE e_target TO . + ELSE. +* then it is an attribute of the class - use different assign then CONCATENATE 'E_TARGET->' wa_component-name INTO attribute_name. ASSIGN (attribute_name) TO . - IF sy-subrc <> 0.EXIT.ENDIF. " Should not happen if structure is built properly - otherwise just exit to create no dumps - flag_class = abap_true. ENDIF. + IF sy-subrc <> 0.EXIT.ENDIF. " Should not happen if structure is built properly - otherwise just exit to avoid dumps CASE wa_component-type_kind. WHEN cl_abap_structdescr=>typekind_struct1 OR cl_abap_structdescr=>typekind_struct2. " Structure --> use recursion - " To avoid dump with attribute GRADTYPE of class ZCL_EXCEL_STYLE_FILL - " quick and really dirty fix -> check the attribute name - " Border has to be initialized somewhere else - IF wa_component-name EQ 'GRADTYPE'. - flag_class = abap_false. - ENDIF. - - IF flag_class = abap_true AND IS INITIAL. -* Only borders will be passed as unbound references. But since we want to set a value we have to create an instance - CREATE OBJECT o_border. - = o_border. - ENDIF. zcl_excel_common=>recursive_struct_to_class( EXPORTING i_source = i_sourcex = CHANGING e_target = ).