Skip to content

Weird error message "Index out of bounds" if converting a not-date Excel value into an ABAP date field #1170

Open
@sandraros

Description

@sandraros

While running convert_to_table of zcl_excel_worksheet, the method excel_string_to_date of zcl_excel_common may return a weird message "Index out of bounds" which doesn't help identifying the error:

METHOD excel_string_to_date.
DATA: lv_date_int TYPE i.
CHECK ip_value IS NOT INITIAL AND ip_value CN ' 0'.
TRY.
lv_date_int = ip_value.
IF lv_date_int NOT BETWEEN 1 AND 2958465.
zcx_excel=>raise_text( 'Unable to interpret date' ).
ENDIF.
ep_value = lv_date_int + c_excel_baseline_date - 2.
" 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
IF ep_value < c_excel_1900_leap_year.
ep_value = ep_value + 1.
ENDIF.
CATCH cx_sy_conversion_error.
zcx_excel=>raise_text( 'Index out of bounds' ).
ENDTRY.
ENDMETHOD.

It happens if the et_data table contains a D type component but the corresponding Excel cell contains a value which is not a date:

  source_worksheet->convert_to_table( EXPORTING iv_begin_row = 2
                                                iv_end_row   = 4
                                      IMPORTING et_data      = three_lines_table_with_d_comp ).

Is it possible to fix the message and indicate the text which is not a valid date to help locating the error?

If possible, is it possible to improve convert_to_table to convert the maximum number of cells, to not fail and to collect all the errors in a new parameter?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions