making the code work for 7.57

This commit is contained in:
sandraros 2023-05-08 15:58:23 +00:00
parent ddd7db1ead
commit 30ff895b73
2 changed files with 15 additions and 7 deletions

View File

@ -5,7 +5,7 @@ CLASS zcl_excel_converter_salv_model DEFINITION
CREATE PUBLIC .
PUBLIC SECTION.
CLASS-METHODS is_alv_displayed
CLASS-METHODS is_get_metadata_callable
IMPORTING
io_salv TYPE REF TO cl_salv_table
RETURNING
@ -18,13 +18,21 @@ ENDCLASS.
CLASS zcl_excel_converter_salv_model IMPLEMENTATION.
METHOD is_alv_displayed.
DATA: lo_model TYPE REF TO cl_salv_model.
METHOD is_get_metadata_callable.
DATA: lo_object TYPE REF TO object,
lo_model TYPE REF TO cl_salv_model.
" In 7.52 and older versions, we have a short dump with CL_SALV_TABLE->GET_METADATA if the ALV is not displayed
" (due to io_salv->r_controller->r_adapter not instantiated yet). That's later fixed by SAP (no short dump in 7.57).
" NB: r_controller is always instantiated.
lo_model ?= io_salv.
" (due to io_salv->r_controller->r_adapter not instantiated yet). That's later fixed by SAP (no short dump in 7.57).
" NB: r_controller is always instantiated.
lo_object = io_salv.
TRY.
lo_model ?= lo_object.
CATCH cx_sy_move_cast_error.
" In 7.57, CL_SALV_TABLE is no more a subclass of CL_SALV_MODEL, but CL_SALV_TABLE->GET_METADATA can be called.
result = abap_true.
RETURN.
ENDTRY.
result = boolc( lo_model->r_controller->r_adapter IS BOUND ).
ENDMETHOD.

View File

@ -75,7 +75,7 @@ CLASS zcl_excel_converter_salv_table IMPLEMENTATION.
ls_vari-handle = ls_layout_key-handle.
ls_vari-log_group = ls_layout_key-logical_group.
ELSE.
IF zcl_excel_converter_salv_model=>is_alv_displayed( io_salv ) = abap_true.
IF zcl_excel_converter_salv_model=>is_get_metadata_callable( io_salv ) = abap_true.
io_salv->get_metadata( ) .
ELSE.
" (do same as offline below)