Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Recycling objects (alv-grid)

Hi gurus.

I must get seven different grids (seven different totals) starting from a gui.

I wouldnu2019t wish to declare seven containers and seven alv-grid, I would prefer declare only one time both objects. So every time I use the FREE instruction and then the CREATE again:

DATA: r_cont_2 TYPE REF TO cl_gui_custom_container, r_alv_2 TYPE REF TO cl_gui_alv_grid, gs_layout2 TYPE lvc_s_layo. IF NOT r_cont_2 IS INITIAL. FREE r_cont_2. CLEAR r_cont_2. ENDIF. IF NOT r_alv_2 IS INITIAL. FREE r_alv_2. CLEAR r_alv_2. ENDIF. CREATE OBJECT r_cont_2 EXPORTING container_name = 'SCR_TXT2'. CREATE OBJECT r_alv_2 EXPORTING i_parent = r_cont_2. CASE ok_code. WHEN '1'. CALL METHOD r_alv_2->set_table_for_first_display EXPORTING is_layout = gs_layout2 CHANGING it_fieldcatalog = it_fdcat u201C <<< Changed for table 1!!! it_outtab = it_tab1 u201C <<< Table 1 EXCEPTIONS OTHERS = 4. WHEN '2'. CALL METHOD r_alv_2->set_table_for_first_display EXPORTING is_layout = gs_layout2 CHANGING it_fieldcatalog = it_fdcat u201C <<< Changed for table 2!!! it_outtab = it_tab2 u201C <<< Table 2 EXCEPTIONS OTHERS = 4. u2026u2026.. ENDCASE.

When I get the first output, I get the first grid correct (any table, everything is ok). When I get the second output and over, I see the first table again. In debug mode I can see the second new table correctly when I call the method, and I can see the objects full before the FREE instruction, and empty after.

Is there a solution, or must I declare seven alv-grid?

Must I declare seven containers too?

Thanks for you replies.

Former Member
replied

Hi ,

Use one instance for alv and container . Change fieldcat , layout using SET_FRONTEND_FIELDCATALOG

SET_FRONTEND_LAYOUT methods , than refresh grid.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question