Ever wondered how to get out your inline created dynamic table out of your method / sub procedure?
REPORT zzjd_tmp2.
CLASS lc_flights DEFINITION.
PUBLIC SECTION.
METHODS main.
METHODS get_data RETURNING VALUE(rr_dyntab) TYPE REF TO data.
METHODS display_alv IMPORTING REFERENCE(ir_dyntab) type REF TO data.
PRIVATE SECTION.
DATA _r_datatable TYPE REF TO data.
ENDCLASS.
CLASS lc_flights IMPLEMENTATION.
METHOD get_data.
* create a fancy dynamic table
SELECT FROM sflights AS f
JOIN scarr AS c ON c~carrid = f~carrid
FIELDS c~*, f~*
INTO TABLE @DATA(lt_flight).
*** copy table to heap memory ***
* Create table description
DATA(lo_tabledesc) = CAST cl_abap_tabledescr(
cl_abap_tabledescr=>describe_by_data( p_data = lt_flight ) ).
* Create table in heap memory and set return reference
CREATE DATA rr_dyntab TYPE HANDLE lo_tabledesc.
FIELD-SYMBOLS <lt_datatable> LIKE lt_flight. " Create a field-symbol...
ASSIGN rr_dyntab->* TO <lt_datatable>. " because append doesn't work with references
APPEND LINES OF lt_flight TO <lt_datatable>. " Copy content to heap table
*********************************
ENDMETHOD.
METHOD display_alv.
FIELD-SYMBOLS <lt_datatable> TYPE ANY TABLE.
ASSIGN ir_dyntab->* TO <lt_datatable>.
cl_salv_table=>factory(
IMPORTING r_salv_table = DATA(lo_salv)
CHANGING t_table = <lt_datatable>
).
lo_salv->display( ).
ENDMETHOD.
METHOD main.
_r_datatable = get_data( ).
display_alv( _r_datatable ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA(lo_flights) = NEW lc_flights( ).
lo_flights->main( ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
4 | |
4 | |
4 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 |