From ff513166fbf8c77e6d1bfd0d3e7a6d46d2858e19 Mon Sep 17 00:00:00 2001 From: Bernd <135710507+darnoc312@users.noreply.github.com> Date: Mon, 8 Jul 2024 14:13:18 +0200 Subject: [PATCH 1/5] Update zcl_excel_common.clas.abap --- src/zcl_excel_common.clas.abap | 70 ++++++++++++++++------------------ 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/src/zcl_excel_common.clas.abap b/src/zcl_excel_common.clas.abap index 67a9e6c..c12aec1 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,20 +1105,30 @@ 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, + lo_refdescr TYPE REF TO cl_abap_refdescr, 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. + lv_clsname TYPE seoclsname. FIELD-SYMBOLS: TYPE any, TYPE any, 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. + lo_refdescr ?= cl_abap_typedescr=>describe_by_data( e_target ). +* The result in lv_clsname is still always 'ZCL_EXCEL_STYLE_BORDER', +* because currently only borders will be passed as unbound references. +* But since we want to set a value we have to create an instance. + lv_clsname = lo_refdescr->get_referenced_type( )->get_relative_name( ). + CREATE OBJECT e_target TYPE (lv_clsname). + ENDIF. + descr ?= cl_abap_structdescr=>describe_by_data( i_source ). LOOP AT descr->components INTO wa_component. @@ -1130,31 +1138,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 = ). From f66a4d23ebb7ec2f5be09048e0d4a3482d878967 Mon Sep 17 00:00:00 2001 From: Bernd <135710507+darnoc312@users.noreply.github.com> Date: Tue, 9 Jul 2024 15:19:31 +0200 Subject: [PATCH 2/5] Update zcl_excel_common.clas.abap --- src/zcl_excel_common.clas.abap | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/zcl_excel_common.clas.abap b/src/zcl_excel_common.clas.abap index c12aec1..c4a0352 100644 --- a/src/zcl_excel_common.clas.abap +++ b/src/zcl_excel_common.clas.abap @@ -1106,12 +1106,11 @@ CLASS zcl_excel_common IMPLEMENTATION. METHOD recursive_struct_to_class. " # issue 139 DATA: descr TYPE REF TO cl_abap_structdescr, - lo_refdescr TYPE REF TO cl_abap_refdescr, wa_component LIKE LINE OF descr->components, attribute_name LIKE wa_component-name, type_kind TYPE abap_typekind, flag_class TYPE abap_bool, - lv_clsname TYPE seoclsname. + o_border TYPE REF TO zcl_excel_style_border. FIELD-SYMBOLS: TYPE any, TYPE any, @@ -1121,12 +1120,9 @@ CLASS zcl_excel_common IMPLEMENTATION. 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. - lo_refdescr ?= cl_abap_typedescr=>describe_by_data( e_target ). -* The result in lv_clsname is still always 'ZCL_EXCEL_STYLE_BORDER', -* because currently only borders will be passed as unbound references. -* But since we want to set a value we have to create an instance. - lv_clsname = lo_refdescr->get_referenced_type( )->get_relative_name( ). - CREATE OBJECT e_target TYPE (lv_clsname). +* 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 ). From 636de5e2e1451b042a16a239d4ac5df7332dc6ec Mon Sep 17 00:00:00 2001 From: Bernd <135710507+darnoc312@users.noreply.github.com> Date: Tue, 16 Jul 2024 12:14:16 +0200 Subject: [PATCH 3/5] Update zcl_excel_common.clas.abap --- src/zcl_excel_common.clas.abap | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/zcl_excel_common.clas.abap b/src/zcl_excel_common.clas.abap index c4a0352..fe68692 100644 --- a/src/zcl_excel_common.clas.abap +++ b/src/zcl_excel_common.clas.abap @@ -1111,6 +1111,8 @@ CLASS zcl_excel_common IMPLEMENTATION. type_kind TYPE abap_typekind, flag_class TYPE abap_bool, o_border TYPE REF TO zcl_excel_style_border. +* lo_refdescr TYPE REF TO cl_abap_refdescr, +* lv_clsname TYPE seoclsname. FIELD-SYMBOLS: TYPE any, TYPE any, @@ -1123,6 +1125,9 @@ CLASS zcl_excel_common IMPLEMENTATION. * 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. +* lo_refdescr ?= cl_abap_typedescr=>describe_by_data( e_target ). +* lv_clsname = lo_refdescr->get_referenced_type( )->get_relative_name( ). +* CREATE OBJECT e_target TYPE (lv_clsname). ENDIF. descr ?= cl_abap_structdescr=>describe_by_data( i_source ). From 6dcfbcf4e373f2cbac56d8ebfa46e3a55e3e4ff8 Mon Sep 17 00:00:00 2001 From: Bernd <135710507+darnoc312@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:57:55 +0200 Subject: [PATCH 4/5] Update zcl_excel_common.clas.abap --- src/zcl_excel_common.clas.abap | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/zcl_excel_common.clas.abap b/src/zcl_excel_common.clas.abap index 70399f3..75e8b9e 100644 --- a/src/zcl_excel_common.clas.abap +++ b/src/zcl_excel_common.clas.abap @@ -1086,6 +1086,10 @@ CLASS zcl_excel_common IMPLEMENTATION. IF flag_class = abap_false. * source is a structure - use assign component ASSIGN COMPONENT wa_component-name OF STRUCTURE i_source TO . + ELSEIF i_source IS INITIAL. + CLEAR . + CLEAR WITH abap_true. + CONTINUE. ELSE. * then it is an attribute of the class - use different assign then CONCATENATE 'i_source->' wa_component-name INTO attribute_name. From b036ad8750ff6c654ab7b63f7fe78692206f0424 Mon Sep 17 00:00:00 2001 From: Bernd <135710507+darnoc312@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:07:48 +0200 Subject: [PATCH 5/5] Update zcl_excel_common.clas.abap defined exit when unbound reference (border) in class_to_struct instead "Should not happen" exit --- src/zcl_excel_common.clas.abap | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/zcl_excel_common.clas.abap b/src/zcl_excel_common.clas.abap index 75e8b9e..1fd4ccf 100644 --- a/src/zcl_excel_common.clas.abap +++ b/src/zcl_excel_common.clas.abap @@ -1075,6 +1075,9 @@ CLASS zcl_excel_common IMPLEMENTATION. DESCRIBE FIELD i_source TYPE type_kind. flag_class = boolc( type_kind = cl_abap_typedescr=>typekind_oref ). +* Only borders will be passed as unbound references. + CHECK flag_class = abap_false OR i_source IS NOT INITIAL. " Exit if unbound reference + descr ?= cl_abap_structdescr=>describe_by_data( e_target ). LOOP AT descr->components INTO wa_component. @@ -1086,10 +1089,6 @@ CLASS zcl_excel_common IMPLEMENTATION. IF flag_class = abap_false. * source is a structure - use assign component ASSIGN COMPONENT wa_component-name OF STRUCTURE i_source TO . - ELSEIF i_source IS INITIAL. - CLEAR . - CLEAR WITH abap_true. - CONTINUE. ELSE. * then it is an attribute of the class - use different assign then CONCATENATE 'i_source->' wa_component-name INTO attribute_name. @@ -1130,6 +1129,7 @@ CLASS zcl_excel_common IMPLEMENTATION. 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.