Pretty print in GET_TABLE

This commit is contained in:
Gregor Wolf 2019-02-11 17:03:14 +00:00
parent e29c54d3d1
commit 6bf5141b00

View File

@ -4217,7 +4217,7 @@ CLASS ZCL_EXCEL_WORKSHEET IMPLEMENTATION.
endmethod. endmethod.
method GET_TABLE. METHOD get_table.
*--------------------------------------------------------------------* *--------------------------------------------------------------------*
* Comment D. Rauchenstein * Comment D. Rauchenstein
* With this method, we get a fully functional Excel Upload, which solves * With this method, we get a fully functional Excel Upload, which solves
@ -4230,116 +4230,116 @@ CLASS ZCL_EXCEL_WORKSHEET IMPLEMENTATION.
* CL_EXCEL_READER_2007->ZIF_EXCEL_READER~LOAD_FILE() * CL_EXCEL_READER_2007->ZIF_EXCEL_READER~LOAD_FILE()
*--------------------------------------------------------------------* *--------------------------------------------------------------------*
field-symbols: <LS_LINE> type DATA. FIELD-SYMBOLS: <ls_line> TYPE data.
field-symbols: <LV_VALUE> type DATA. FIELD-SYMBOLS: <lv_value> TYPE data.
data LV_ACTUAL_ROW type INT4. DATA lv_actual_row TYPE int4.
data LV_ACTUAL_COL type INT4. DATA lv_actual_col TYPE int4.
data LV_ERRORMESSAGE type STRING. DATA lv_errormessage TYPE string.
data LV_MAX_COL type ZEXCEL_CELL_COLUMN. DATA lv_max_col TYPE zexcel_cell_column.
data LV_MAX_ROW type INT4. DATA lv_max_row TYPE int4.
data LV_DELTA_COL type INT4. DATA lv_delta_col TYPE int4.
data LV_VALUE type ZEXCEL_CELL_VALUE. DATA lv_value TYPE zexcel_cell_value.
data LV_RC type SYSUBRC. DATA lv_rc TYPE sysubrc.
LV_MAX_COL = ME->GET_HIGHEST_COLUMN( ). lv_max_col = me->get_highest_column( ).
LV_MAX_ROW = ME->GET_HIGHEST_ROW( ). lv_max_row = me->get_highest_row( ).
*--------------------------------------------------------------------* *--------------------------------------------------------------------*
* The row counter begins with 1 and should be corrected with the skips * The row counter begins with 1 and should be corrected with the skips
*--------------------------------------------------------------------* *--------------------------------------------------------------------*
LV_ACTUAL_ROW = IV_SKIPPED_ROWS + 1. lv_actual_row = iv_skipped_rows + 1.
LV_ACTUAL_COL = IV_SKIPPED_COLS + 1. lv_actual_col = iv_skipped_cols + 1.
try. TRY.
*--------------------------------------------------------------------* *--------------------------------------------------------------------*
* Check if we the basic features are possible with given "any table" * Check if we the basic features are possible with given "any table"
*--------------------------------------------------------------------* *--------------------------------------------------------------------*
append initial line to ET_TABLE assigning <LS_LINE>. APPEND INITIAL LINE TO et_table ASSIGNING <ls_line>.
if SY-SUBRC <> 0 or <LS_LINE> is not assigned. IF sy-subrc <> 0 OR <ls_line> IS NOT ASSIGNED.
LV_ERRORMESSAGE = 'Error at inserting new Line to internal Table'(002). lv_errormessage = 'Error at inserting new Line to internal Table'(002).
zcx_excel=>raise_text( lv_errormessage ). zcx_excel=>raise_text( lv_errormessage ).
else. ELSE.
LV_DELTA_COL = LV_MAX_COL - IV_SKIPPED_COLS. lv_delta_col = lv_max_col - iv_skipped_cols.
assign component LV_DELTA_COL of structure <LS_LINE> to <LV_VALUE>. ASSIGN COMPONENT lv_delta_col OF STRUCTURE <ls_line> TO <lv_value>.
if SY-SUBRC <> 0 or <LV_VALUE> is not assigned. IF sy-subrc <> 0 OR <lv_value> IS NOT ASSIGNED.
LV_ERRORMESSAGE = 'Internal table has less columns than excel'(003). lv_errormessage = 'Internal table has less columns than excel'(003).
zcx_excel=>raise_text( lv_errormessage ). zcx_excel=>raise_text( lv_errormessage ).
else. ELSE.
*--------------------------------------------------------------------* *--------------------------------------------------------------------*
*now we are ready for handle the table data *now we are ready for handle the table data
*--------------------------------------------------------------------* *--------------------------------------------------------------------*
refresh ET_TABLE. REFRESH et_table.
*--------------------------------------------------------------------* *--------------------------------------------------------------------*
* Handle each Row until end on right side * Handle each Row until end on right side
*--------------------------------------------------------------------* *--------------------------------------------------------------------*
while LV_ACTUAL_ROW <= LV_MAX_ROW . WHILE lv_actual_row <= lv_max_row .
*--------------------------------------------------------------------* *--------------------------------------------------------------------*
* Handle each Column until end on bottom * Handle each Column until end on bottom
* First step is to step back on first column * First step is to step back on first column
*--------------------------------------------------------------------* *--------------------------------------------------------------------*
LV_ACTUAL_COL = IV_SKIPPED_COLS + 1. lv_actual_col = iv_skipped_cols + 1.
unassign <LS_LINE>. UNASSIGN <ls_line>.
append initial line to ET_TABLE assigning <LS_LINE>. APPEND INITIAL LINE TO et_table ASSIGNING <ls_line>.
if SY-SUBRC <> 0 or <LS_LINE> is not assigned. IF sy-subrc <> 0 OR <ls_line> IS NOT ASSIGNED.
LV_ERRORMESSAGE = 'Error at inserting new Line to internal Table'(002). lv_errormessage = 'Error at inserting new Line to internal Table'(002).
zcx_excel=>raise_text( lv_errormessage ). zcx_excel=>raise_text( lv_errormessage ).
endif. ENDIF.
while LV_ACTUAL_COL <= LV_MAX_COL. WHILE lv_actual_col <= lv_max_col.
LV_DELTA_COL = LV_ACTUAL_COL - IV_SKIPPED_COLS. lv_delta_col = lv_actual_col - iv_skipped_cols.
assign component LV_DELTA_COL of structure <LS_LINE> to <LV_VALUE>. ASSIGN COMPONENT lv_delta_col OF STRUCTURE <ls_line> TO <lv_value>.
if SY-SUBRC <> 0. IF sy-subrc <> 0.
LV_ERRORMESSAGE = |{ 'Error at assigning field (Col:'(004) } { LV_ACTUAL_COL } { ' Row:'(005) } { LV_ACTUAL_ROW }|. lv_errormessage = |{ 'Error at assigning field (Col:'(004) } { lv_actual_col } { ' Row:'(005) } { lv_actual_row }|.
zcx_excel=>raise_text( lv_errormessage ). zcx_excel=>raise_text( lv_errormessage ).
endif. ENDIF.
ME->GET_CELL( me->get_cell(
exporting EXPORTING
IP_COLUMN = LV_ACTUAL_COL " Cell Column ip_column = lv_actual_col " Cell Column
IP_ROW = LV_ACTUAL_ROW " Cell Row ip_row = lv_actual_row " Cell Row
importing IMPORTING
EP_VALUE = LV_VALUE " Cell Value ep_value = lv_value " Cell Value
EP_RC = LV_RC " Return Value of ABAP Statements ep_rc = lv_rc " Return Value of ABAP Statements
). ).
if LV_RC <> 0 IF lv_rc <> 0
and LV_RC <> 4. "No found error means, zero/no value in cell AND lv_rc <> 4. "No found error means, zero/no value in cell
LV_ERRORMESSAGE = |{ 'Error at reading field value (Col:'(007) } { LV_ACTUAL_COL } { ' Row:'(005) } { LV_ACTUAL_ROW }|. lv_errormessage = |{ 'Error at reading field value (Col:'(007) } { lv_actual_col } { ' Row:'(005) } { lv_actual_row }|.
zcx_excel=>raise_text( lv_errormessage ). zcx_excel=>raise_text( lv_errormessage ).
endif. ENDIF.
<LV_VALUE> = LV_VALUE. <lv_value> = lv_value.
* CATCH zcx_excel. " * CATCH zcx_excel. "
add 1 to LV_ACTUAL_COL. ADD 1 TO lv_actual_col.
endwhile. ENDWHILE.
add 1 to LV_ACTUAL_ROW. ADD 1 TO lv_actual_row.
endwhile. ENDWHILE.
endif. ENDIF.
endif. ENDIF.
catch CX_SY_ASSIGN_CAST_ILLEGAL_CAST. CATCH cx_sy_assign_cast_illegal_cast.
LV_ERRORMESSAGE = |{ 'Error at assigning field (Col:'(004) } { LV_ACTUAL_COL } { ' Row:'(005) } { LV_ACTUAL_ROW }|. lv_errormessage = |{ 'Error at assigning field (Col:'(004) } { lv_actual_col } { ' Row:'(005) } { lv_actual_row }|.
zcx_excel=>raise_text( lv_errormessage ). zcx_excel=>raise_text( lv_errormessage ).
catch CX_SY_ASSIGN_CAST_UNKNOWN_TYPE. CATCH cx_sy_assign_cast_unknown_type.
LV_ERRORMESSAGE = |{ 'Error at assigning field (Col:'(004) } { LV_ACTUAL_COL } { ' Row:'(005) } { LV_ACTUAL_ROW }|. lv_errormessage = |{ 'Error at assigning field (Col:'(004) } { lv_actual_col } { ' Row:'(005) } { lv_actual_row }|.
zcx_excel=>raise_text( lv_errormessage ). zcx_excel=>raise_text( lv_errormessage ).
catch CX_SY_ASSIGN_OUT_OF_RANGE. CATCH cx_sy_assign_out_of_range.
LV_ERRORMESSAGE = 'Internal table has less columns than excel'(003). lv_errormessage = 'Internal table has less columns than excel'(003).
zcx_excel=>raise_text( lv_errormessage ). zcx_excel=>raise_text( lv_errormessage ).
catch CX_SY_CONVERSION_ERROR. CATCH cx_sy_conversion_error.
LV_ERRORMESSAGE = |{ 'Error at converting field value (Col:'(006) } { LV_ACTUAL_COL } { ' Row:'(005) } { LV_ACTUAL_ROW }|. lv_errormessage = |{ 'Error at converting field value (Col:'(006) } { lv_actual_col } { ' Row:'(005) } { lv_actual_row }|.
zcx_excel=>raise_text( lv_errormessage ). zcx_excel=>raise_text( lv_errormessage ).
endtry. ENDTRY.
endmethod. ENDMETHOD.
method GET_TABLES_ITERATOR. method GET_TABLES_ITERATOR.