Dynamic programming fail: pass table TYPE cds as a parameter

Dear experts,

this is driving me mad.

I have several calling programs, which calls one wanna-be generic and reusable class. That class is supposed to select data from different CDS view entities and process them. Therefore I need to let the class know what CDS it is supposed to work with. I thought it would be easy but I could not be more wrong.

 

If it is not possible, I would be happy to know why.
Thank you.
Denis
btw – posting a question here is almost that impossible as what I am trying to achieve with ABAP.  Isn’t that symptomatic?

 

“Call from the main program
************** DEFINITION OF THE STRUCTURE FOR DATA FROM CDS **************

DATA: t_data_obs TYPE STANDARD TABLE OF zfi_data_obs. ” Internal table for passing the CDS structure to the class

************** INSTANTIATION AND CALLING THE CLASS **************
DATA: go_consumer TYPE REF TO zfi_obs_interface_consumer.
TRY.
CREATE OBJECT go_consumer
EXPORTING
i_where_cond = where_clause
i_t_code = ‘ZFI_SEND_PAYMENTS’
i_cds_view = ‘ZFI_DATA_OBS’
i_t_data_obs = t_data_obs
i_wholedoc = abap_true ” in transaction ZFI_SEND_PAYMENTS always true, only a whole document can be sent to OBS
i_hotspot_column = ‘DocumentNumber’. ” CDS field name for hotspot in ALV
CATCH cx_static_check INTO DATA(lx_error_static).
MESSAGE lx_error_static->get_text( ) TYPE ‘S’ DISPLAY LIKE ‘E’.
ENDTRY.

go_consumer->get_data( ).

” Constructor declaration and implementation, private attributes:
METHODS: constructor IMPORTING i_where_cond TYPE string “where condition from the calling program
i_t_code TYPE tcode “calling transaction
i_t_data_obs TYPE ANY TABLE
i_cds_view TYPE string “CDS view entity for selecting data
i_wholedoc TYPE abap_bool “transfer a complete document only?
i_hotspot_column TYPE string
“me->t_items = VALUE zfi_data_obs( ).
RAISING cx_static_check.

PRIVATE SECTION.
” Instance variables.
DATA: where_cond TYPE string,
t_code TYPE tcode,
cds_view TYPE string,
t_items TYPE REF TO data,
wholedoc TYPE abap_bool,
hotspot_column TYPE char30,
o_alv TYPE REF TO cl_salv_table,
o_events TYPE REF TO cl_salv_events_table,
lx_error TYPE REF TO cx_root.

CLASS ZFI_OBS_INTERFACE_CONSUMER IMPLEMENTATION.

METHOD constructor.
cds_view = i_cds_view.
where_cond = i_where_cond.
hotspot_column = i_hotspot_column.

t_items = i_t_data_obs.

* CREATE DATA t_items LIKE i_t_data_obs.
* FIELD-SYMBOLS: <fs_items> TYPE STANDARD TABLE.
* ASSIGN t_items->* TO <fs_items>.
* <fs_items> = i_t_data_obs.
ENDMETHOD.

METHOD get_data.
SELECT * FROM (cds_view) WHERE (where_cond) INTO TABLE @t_items. ” Dynamic select from CDS
me->t_items = t_items.
me->prepare_alv( ).

ENDMETHOD.

 

 

 

Scroll to Top