Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sandraros opened this issue Jan 5, 2024 · 0 comments

Comments

@sandraros
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant