From f6da60df7395e206c02c79127093fe7ba3ee3ea3 Mon Sep 17 00:00:00 2001 From: Rene Turnheim Date: Sat, 11 Aug 2012 20:35:41 +0000 Subject: [PATCH] ISSUE #200 and #201 This solution was proposed by Vladimir Scheglov and modified to solve same problem in converter and common class. Recursive call with check dictionary type was needed. Ready for testing #200 and also #201 git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@326 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 --- ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk | 623 ++++++++++++++++++++++---------- 1 file changed, 436 insertions(+), 187 deletions(-) diff --git a/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk b/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk index bb754fb..92801cd 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk @@ -1,13 +1,13 @@ - - + + class ZCL_EXCEL_COMMON definition public final create public . -public section. *"* public components of class ZCL_EXCEL_COMMON *"* do not include other source files here!!! +public section. constants C_EXCEL_BASELINE_DATE type D value '19000101'. "#EC NOTEXT class-data C_EXCEL_NUMFMT_OFFSET type INT1 value 164. "#EC NOTEXT . @@ -17,6 +17,12 @@ public section. class-data O_CONV type ref to CL_ABAP_CONV_OUT_CE . constants C_EXCEL_1900_LEAP_YEAR type D value '19000228'. "#EC NOTEXT + class-methods DESCRIBE_STRUCTURE + importing + !IO_STRUCT type ref to CL_ABAP_STRUCTDESCR + returning + value(RT_DFIES) type DDFIELDS . + class-methods DESCRIBE_TABLE . class-methods CONVERT_COLUMN2ALPHA importing !IP_COLUMN type SIMPLE @@ -101,16 +107,56 @@ public section. importing !IP_VALUE type T returning - value(EP_VALUE) type ZEXCEL_CELL_VALUE . + value(EP_VALUE) type ZEXCEL_CELL_VALUE . + interface IF_AUNIT_CONSTANTS load . + type-pools ABAP . + class-methods ASSERT_EQUALS + importing + !EXP type ANY + !ACT type ANY + !MSG type CSEQUENCE optional + !LEVEL type AUNIT_LEVEL default IF_AUNIT_CONSTANTS=>CRITICAL + !TOL type F optional + !QUIT type AUNIT_FLOWCTRL default IF_AUNIT_CONSTANTS=>METHOD + !IGNORE_HASH_SEQUENCE type ABAP_BOOL default ABAP_FALSE + returning + value(ASSERTION_FAILED) type ABAP_BOOL . + class-methods FAIL + importing + !MSG type CSEQUENCE optional + !LEVEL type AUNIT_LEVEL default IF_AUNIT_CONSTANTS=>CRITICAL + !QUIT type AUNIT_FLOWCTRL default IF_AUNIT_CONSTANTS=>METHOD + !DETAIL type CSEQUENCE optional . + class-methods ASSERT_DIFFERS + importing + !EXP type SIMPLE + !ACT type SIMPLE + !MSG type CSEQUENCE optional + !LEVEL type AUNIT_LEVEL default IF_AUNIT_CONSTANTS=>CRITICAL + !TOL type F optional + !QUIT type AUNIT_FLOWCTRL default IF_AUNIT_CONSTANTS=>METHOD + returning + value(ASSERTION_FAILED) type ABAP_BOOL . *"* protected components of class ZCL_EXCEL_COMMON *"* do not include other source files here!!! protected section. - private section. -*"* private components of class ZCL_EXCEL_COMMON + *"* private components of class ZCL_EXCEL_COMMON *"* do not include other source files here!!! +private section. class-data C_EXCEL_COL_MODULE type INT2 value 64. "#EC NOTEXT . + type-pools ABAP . + class-methods STRUCTURE_CASE + importing + !IS_COMPONENT type ABAP_COMPONENTDESCR + changing + !XT_COMPONENTS type ABAP_COMPONENT_TAB . + class-methods STRUCTURE_RECURSIVE + importing + !IS_COMPONENT type ABAP_COMPONENTDESCR + returning + value(RT_COMPONENTS) type ABAP_COMPONENT_TAB . class-methods CHAR2HEX importing !I_CHAR type CHAR1 @@ -142,12 +188,8 @@ CLASS zcl_excel_common DEFINITION LOCAL FRIENDS lcl_excel_common_test. *----------------------------------------------------------------------* * *----------------------------------------------------------------------* -CLASS lcl_excel_common_test DEFINITION FOR TESTING - " DURATION SHORT - " RISK LEVEL HARMLESS - "#AU Duration Medium - "#AU Risk_Level Harmless -. +CLASS lcl_excel_common_test DEFINITION FOR TESTING "#AU Risk_Level Harmless + . "#AU Duration Short *?<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0"> *?<asx:values> *?<TESTCLASS_OPTIONS> @@ -235,14 +277,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_column = zcl_excel_common=>convert_column2alpha( 1 ). - cl_aunit_assert=>assert_equals( + zcl_excel_common=>assert_equals( act = ep_column exp = 'A' msg = 'Wrong column conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + zcl_excel_common=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -252,14 +294,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_column = zcl_excel_common=>convert_column2alpha( 16384 ). - cl_aunit_assert=>assert_equals( + zcl_excel_common=>assert_equals( act = ep_column exp = 'XFD' msg = 'Wrong column conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + zcl_excel_common=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -269,12 +311,12 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_column = zcl_excel_common=>convert_column2alpha( 0 ). - cl_aunit_assert=>assert_equals( + zcl_excel_common=>assert_equals( act = ep_column exp = 'A' ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>assert_equals( + zcl_excel_common=>assert_equals( act = lx_excel->error exp = 'Index out of bounds' msg = 'Colum index 0 is out of bounds, min column index is 1' @@ -286,14 +328,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_column = zcl_excel_common=>convert_column2alpha( 16385 ). - cl_aunit_assert=>assert_differs( + zcl_excel_common=>assert_differs( act = ep_column exp = 'XFE' msg = 'Colum index 16385 is out of bounds, max column index is 16384' level = if_aunit_constants=>fatal ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>assert_equals( + zcl_excel_common=>assert_equals( act = lx_excel->error exp = 'Index out of bounds' msg = 'Wrong exception is thrown' @@ -311,14 +353,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_column = zcl_excel_common=>convert_column2int( 'A' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_column exp = 1 msg = 'Wrong column conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -328,14 +370,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_column = zcl_excel_common=>convert_column2int( 'XFD' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_column exp = 16384 msg = 'Wrong column conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -345,14 +387,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_column = zcl_excel_common=>convert_column2int( '' ). - cl_aunit_assert=>assert_differs( + ZCL_EXCEL_COMMON=>assert_differs( act = ep_column exp = '0' msg = 'Wrong column conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = lx_excel->error exp = 'Unable to interpret column' msg = 'Colum name should be a valid string' @@ -364,14 +406,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_column = zcl_excel_common=>convert_column2int( 'XFE' ). - cl_aunit_assert=>assert_differs( + ZCL_EXCEL_COMMON=>assert_differs( act = ep_column exp = 16385 msg = 'Wrong column conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = lx_excel->error exp = 'Index out of bounds' msg = 'Colum XFE is out of range' @@ -389,14 +431,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>date_to_excel_string( '19000101' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = 1 msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -405,14 +447,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>date_to_excel_string( '19000228' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = 59 msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -420,14 +462,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>date_to_excel_string( '19000301' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = 61 msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -438,14 +480,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>date_to_excel_string( '99991212' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = 2958446 msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -456,14 +498,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. DATA: lv_date TYPE d. ep_value = zcl_excel_common=>date_to_excel_string( lv_date ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value - exp = '-693596' + exp = '' msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -474,14 +516,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. DATA exp_value TYPE zexcel_cell_value VALUE 0. ep_value = zcl_excel_common=>date_to_excel_string( '18991231' ). - cl_aunit_assert=>assert_differs( + ZCL_EXCEL_COMMON=>assert_differs( act = ep_value exp = exp_value msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = lx_excel->error exp = 'Index out of bounds' msg = 'Dates prior of 1900 are not available in excel' @@ -499,14 +541,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. lv_encrypted_pwd = zcl_excel_common=>encrypt_password( 'test' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = lv_encrypted_pwd exp = 'CBEB' msg = 'Wrong password encryption' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -523,14 +565,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>excel_string_to_date( '0' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = '18991231' msg = 'Wrong date conversion' level = if_aunit_constants=>tolerable ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -539,14 +581,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>excel_string_to_date( '59' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = '19000228' msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -554,14 +596,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>excel_string_to_date( '61' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = '19000301' msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -571,14 +613,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>excel_string_to_date( '1' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = '19000101' msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -588,14 +630,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>excel_string_to_date( '2958446' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = '99991212' msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -605,14 +647,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>excel_string_to_date( '2958447' ). - cl_aunit_assert=>assert_differs( + ZCL_EXCEL_COMMON=>assert_differs( act = ep_value exp = '99991212' msg = 'Wrong date conversion' level = if_aunit_constants=>fatal ). - cl_aunit_assert=>assert_differs( + ZCL_EXCEL_COMMON=>assert_differs( act = ep_value exp = '00000000' msg = 'Wrong date conversion' @@ -620,7 +662,7 @@ CLASS lcl_excel_common_test IMPLEMENTATION. ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = lx_excel->error exp = 'Index out of bounds' msg = 'Wrong exception is thrown' @@ -638,14 +680,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>excel_string_to_time( '0' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = '000000' msg = 'Wrong date conversion' level = if_aunit_constants=>tolerable ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -655,14 +697,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>excel_string_to_time( '1' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = '000000' msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -672,14 +714,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>excel_string_to_time( '0.99999' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = '235959' msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -689,14 +731,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>excel_string_to_time( '4.1' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = '022400' msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -706,14 +748,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>excel_string_to_time( 'NaN' ). - cl_aunit_assert=>assert_differs( + ZCL_EXCEL_COMMON=>assert_differs( act = ep_value exp = '000000' msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = lx_excel->error exp = 'Unable to interpret time' msg = 'Time should be a valid string' @@ -731,14 +773,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>time_to_excel_string( '000001' ). " A test directly in Excel returns the value 0.0000115740740740741000 - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = '0.0000115740740741' msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -748,14 +790,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>time_to_excel_string( '235959' ). " A test directly in Excel returns the value 0.9999884259259260000000 - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = '0.9999884259259260' msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -765,14 +807,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>time_to_excel_string( '000000' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = '0' msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -782,14 +824,14 @@ CLASS lcl_excel_common_test IMPLEMENTATION. TRY. ep_value = zcl_excel_common=>time_to_excel_string( '022400' ). - cl_aunit_assert=>assert_equals( + ZCL_EXCEL_COMMON=>assert_equals( act = ep_value exp = '0.1000000000000000' msg = 'Wrong date conversion' level = if_aunit_constants=>critical ). CATCH zcx_excel INTO lx_excel. - cl_aunit_assert=>fail( + ZCL_EXCEL_COMMON=>fail( msg = 'unexpected exception' level = if_aunit_constants=>critical " Error Severity ). @@ -797,21 +839,123 @@ CLASS lcl_excel_common_test IMPLEMENTATION. ENDMETHOD. "time_To_Excel_String - - - ENDCLASS. "lcl_Excel_Common_Test - - - - - - - - - - - + + ABAP + + + + + + + + + + + + + + + + + METHOD assert_differs. + DATA: ls_seoclass TYPE seoclass. + +" Let see >=7.02 + SELECT SINGLE * INTO ls_seoclass + FROM seoclass + WHERE clsname = 'CL_ABAP_UNIT_ASSERT'. + + IF sy-subrc = 0. + CALL METHOD (ls_seoclass-clsname)=>assert_differs + EXPORTING + exp = exp + act = act + msg = msg + level = level + tol = tol + quit = quit + RECEIVING + assertion_failed = assertion_failed. + ELSE. +" Let see >=7.00 or even lower + SELECT SINGLE * INTO ls_seoclass + FROM seoclass + WHERE clsname = 'CL_AUNIT_ASSERT'. + + IF sy-subrc = 0. + CALL METHOD (ls_seoclass-clsname)=>assert_differs + EXPORTING + exp = exp + act = act + msg = msg + level = level + tol = tol + quit = quit + RECEIVING + assertion_failed = assertion_failed. + ELSE. +* We do nothing for now not supported + ENDIF. + ENDIF. +ENDMETHOD. + + + + + + + + + + + METHOD assert_equals. + DATA: ls_seoclass TYPE seoclass. + + " Let see >=7.02 + SELECT SINGLE * INTO ls_seoclass + FROM seoclass + WHERE clsname = 'CL_ABAP_UNIT_ASSERT'. + + IF sy-subrc = 0. + CALL METHOD (ls_seoclass-clsname)=>assert_equals + EXPORTING + exp = exp + act = act + msg = msg + level = level + tol = tol + quit = quit + ignore_hash_sequence = ignore_hash_sequence + RECEIVING + assertion_failed = assertion_failed. + ELSE. + " Let see >=7.00 or even lower + SELECT SINGLE * INTO ls_seoclass + FROM seoclass + WHERE clsname = 'CL_AUNIT_ASSERT'. + + IF sy-subrc = 0. + CALL METHOD (ls_seoclass-clsname)=>assert_equals + EXPORTING + exp = exp + act = act + msg = msg + level = level + tol = tol + quit = quit + ignore_hash_sequence = ignore_hash_sequence + RECEIVING + assertion_failed = assertion_failed. + ELSE. +* We do nothing for now not supported + ENDIF. + ENDIF. +ENDMETHOD. + + + + method CHAR2HEX. IF o_conv IS NOT BOUND. @@ -826,10 +970,10 @@ ENDCLASS. "lcl_Excel_Common_Test endmethod. - - - - + + + + method CONVERT_COLUMN2ALPHA. DATA: lo_conv TYPE REF TO cl_abap_conv_in_ce, @@ -856,10 +1000,10 @@ endmethod. endmethod. - - - - + + + + method CONVERT_COLUMN2INT. DATA: lv_uccpi TYPE i, @@ -947,10 +1091,10 @@ endmethod. endmethod. - - - - + + + + method CONVERT_COLUMNROW2COLUMN_A_ROW. DATA: width TYPE i, col_width TYPE i, @@ -969,13 +1113,13 @@ endmethod. e_row = row_str. endmethod. - - - - - - - + + + + + + + method CONVERT_RANGE2COLUMN_A_ROW. DATA: sheet TYPE string, @@ -1014,13 +1158,13 @@ endmethod. ). endmethod. - - - - method DATE_TO_EXCEL_STRING. + + + + METHOD date_to_excel_string. DATA: lv_date_diff TYPE i. - "CHECK ip_value IS NOT INITIAL. + CHECK ip_value IS NOT INITIAL. " Needed hack caused by the problem that: " Excel 2000 incorrectly assumes that the year 1900 is a leap year " http://support.microsoft.com/kb/214326/en-us @@ -1030,11 +1174,65 @@ endmethod. lv_date_diff = ip_value - c_excel_baseline_date + 1. ENDIF. ep_value = zcl_excel_common=>number_to_excel_string( ip_value = lv_date_diff ). +ENDMETHOD. + + + + + METHOD describe_structure. + DATA: lt_components TYPE abap_component_tab, + lt_comps TYPE abap_component_tab, + lo_struct TYPE REF TO cl_abap_structdescr, + ls_component TYPE abap_componentdescr, + lo_elemdescr TYPE REF TO cl_abap_elemdescr, + ls_dfies TYPE dfies, + l_position TYPE tabfdpos. + + "for DDIC structure get the info directly + IF lo_struct->is_ddic_type( ) = abap_true. + rt_dfies = lo_struct->get_ddic_field_list( ). + ELSE. + lt_components = io_struct->get_components( ). + + LOOP AT lt_components INTO ls_component. + structure_case( EXPORTING is_component = ls_component + CHANGING xt_components = lt_comps ) . + ENDLOOP. + LOOP AT lt_comps INTO ls_component. + CLEAR ls_dfies. + IF ls_component-type->kind = cl_abap_typedescr=>kind_elem. "E Elementary Type + ADD 1 TO l_position. + lo_elemdescr ?= ls_component-type. + IF lo_elemdescr->is_ddic_type( ) = abap_true. + ls_dfies = lo_elemdescr->get_ddic_field( ). + ls_dfies-position = l_position. + ELSE. + ls_dfies-fieldname = ls_component-name. + ls_dfies-position = l_position. + ls_dfies-inttype = lo_elemdescr->type_kind. + ls_dfies-leng = lo_elemdescr->length. + ls_dfies-outputlen = lo_elemdescr->length. + ls_dfies-decimals = lo_elemdescr->decimals. + ls_dfies-fieldtext = ls_component-name. + ls_dfies-reptext = ls_component-name. + ls_dfies-scrtext_s = ls_component-name. + ls_dfies-scrtext_m = ls_component-name. + ls_dfies-scrtext_l = ls_component-name. + ls_dfies-dynpfld = abap_true. + ENDIF. + INSERT ls_dfies INTO TABLE rt_dfies. + ENDIF. + ENDLOOP. + ENDIF. +ENDMETHOD. + + + method DESCRIBE_TABLE. endmethod. - - - + + + method ENCRYPT_PASSWORD. DATA lv_curr_offset TYPE i. @@ -1074,9 +1272,9 @@ endmethod. endmethod. - - - + + + method ESCAPE_STRING. DATA lv_value TYPE string. @@ -1092,10 +1290,10 @@ endmethod. endmethod. - - - - + + + + method EXCEL_STRING_TO_DATE. DATA: lv_date_int TYPE i. @@ -1115,10 +1313,10 @@ endmethod. ENDTRY. endmethod. - - - - + + + + method EXCEL_STRING_TO_TIME. DATA: lv_seconds_in_day TYPE i, lv_day_fraction TYPE f, @@ -1138,62 +1336,74 @@ endmethod. ENDTRY. endmethod. - - - - method GET_FIELDCATALOG. + + + + + + METHOD fail. + DATA: ls_seoclass TYPE seoclass. + + " Let see >=7.02 + SELECT SINGLE * INTO ls_seoclass + FROM seoclass + WHERE clsname = 'CL_ABAP_UNIT_ASSERT'. + + IF sy-subrc = 0. + CALL METHOD (ls_seoclass-clsname)=>fail + EXPORTING + msg = msg + level = level + quit = quit + detail = detail. + ELSE. + " Let see >=7.00 or even lower + SELECT SINGLE * INTO ls_seoclass + FROM seoclass + WHERE clsname = 'CL_AUNIT_ASSERT'. + + IF sy-subrc = 0. + CALL METHOD (ls_seoclass-clsname)=>fail + EXPORTING + msg = msg + level = level + quit = quit + detail = detail. + ELSE. +* We do nothing for now not supported + ENDIF. + ENDIF. + +ENDMETHOD. + + + + + METHOD get_fieldcatalog. DATA: lr_data TYPE REF TO data, lo_structdescr TYPE REF TO cl_abap_structdescr, - lo_elemdescr TYPE REF TO cl_abap_elemdescr, lt_dfies TYPE ddfields, ls_dfies TYPE dfies, - lv_sytabix TYPE sytabix, - ls_fieldcatalog TYPE zexcel_s_fieldcatalog, - lt_components TYPE abap_component_tab, - ls_component LIKE LINE OF lt_components. + ls_fieldcatalog TYPE zexcel_s_fieldcatalog. CREATE DATA lr_data LIKE LINE OF ip_table. - lo_structdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ). + lo_structdescr ?= cl_abap_structdescr=>describe_by_data( lr_data ). - "for DDIC structure get the info directly - IF lo_structdescr->is_ddic_type( ) = abap_true. - lt_dfies = lo_structdescr->get_ddic_field_list( ). + lt_dfies = describe_structure( io_struct = lo_structdescr ). - LOOP AT lt_dfies INTO ls_dfies. - CLEAR ls_fieldcatalog. - MOVE-CORRESPONDING ls_dfies TO ls_fieldcatalog. - APPEND ls_fieldcatalog TO ep_fieldcatalog. - ENDLOOP. - ELSE. - "if structure is not DDIC check components - lt_components = lo_structdescr->get_components( ). - LOOP AT lt_components INTO ls_component. - lv_sytabix = sy-tabix. - CLEAR ls_fieldcatalog. - lo_elemdescr ?= ls_component-type. - "component is DDIC - IF lo_elemdescr->is_ddic_type( ) = abap_true. - ls_dfies = lo_elemdescr->get_ddic_field( ). - MOVE-CORRESPONDING ls_dfies TO ls_fieldcatalog. - ls_fieldcatalog-fieldname = ls_component-name. - ELSE. - "component is not DDIC -> return minimum information required - ls_fieldcatalog-fieldname = ls_component-name. - ls_fieldcatalog-dynpfld = abap_true. - ls_fieldcatalog-scrtext_m = ls_component-name. - ENDIF. - ls_fieldcatalog-position = lv_sytabix. - APPEND ls_fieldcatalog TO ep_fieldcatalog. - ENDLOOP. - ENDIF. + LOOP AT lt_dfies INTO ls_dfies. + CLEAR ls_fieldcatalog. + MOVE-CORRESPONDING ls_dfies TO ls_fieldcatalog. + APPEND ls_fieldcatalog TO ep_fieldcatalog. + ENDLOOP. -endmethod. +ENDMETHOD. - - - + + + method NUMBER_TO_EXCEL_STRING. DATA: lv_value_c TYPE c LENGTH 100. @@ -1210,10 +1420,10 @@ endmethod. ENDIF. endmethod. - - - - + + + + method RECURSIVE_CLASS_TO_STRUCT. " # issue 139 * is working for me - but after looking through this coding I guess @@ -1269,10 +1479,10 @@ endmethod. endmethod. - - - - + + + + method RECURSIVE_STRUCT_TO_CLASS. " # issue 139 * is working for me - but after looking through this coding I guess @@ -1329,9 +1539,9 @@ endmethod. endmethod. - - - + + + method SHL01. DATA: @@ -1349,9 +1559,9 @@ endmethod. endmethod. - - - + + + method SHR14. DATA: @@ -1376,9 +1586,48 @@ endmethod. endmethod. - - - + + + + METHOD structure_case. + DATA: lt_comp_str TYPE abap_component_tab. + + CASE is_component-type->kind. + WHEN cl_abap_typedescr=>kind_elem. "E Elementary Type + INSERT is_component INTO TABLE xt_components. + WHEN cl_abap_typedescr=>kind_table. "T Table + INSERT is_component INTO TABLE xt_components. + WHEN cl_abap_typedescr=>kind_struct. "S Structure + lt_comp_str = structure_recursive( is_component = is_component ). + INSERT LINES OF lt_comp_str INTO TABLE xt_components. + WHEN OTHERS. "cl_abap_typedescr=>kind_ref or cl_abap_typedescr=>kind_class or cl_abap_typedescr=>kind_intf. +* We skip it. for now. + ENDCASE. +ENDMETHOD. + + + + + METHOD structure_recursive. + DATA: lo_struct TYPE REF TO cl_abap_structdescr, + lt_components TYPE abap_component_tab, + ls_components TYPE abap_componentdescr. + + REFRESH rt_components. + + lo_struct ?= is_component-type. + lt_components = lo_struct->get_components( ). + + LOOP AT lt_components INTO ls_components. + structure_case( EXPORTING is_component = ls_components + CHANGING xt_components = rt_components ) . + ENDLOOP. + +ENDMETHOD. + + + + method TIME_TO_EXCEL_STRING. DATA: lv_seconds_in_day TYPE i, lv_day_fraction TYPE f,