Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Help on oo alv display and manage functions please

Former Member
0 Kudos

Hi experts, i'am using OO ALV to display datas and do some operations before output. My probleme is that when i create a variant, i am unable to delete it. I think there are differents view, one for display data, other to manage layout but when i click on the manage view button, nothing append. Without using a container, my datas are succesfully displayed(see image and code)

 CREATE OBJECT g_grid
 EXPORTING
" i_appl_events = 'X'
 i_parent = cl_gui_container=>default_screen"container"
 EXCEPTIONS
 error_cntl_create = 1
 error_cntl_init = 2
 error_cntl_link = 3
 error_dp_create = 4
 OTHERS = 5.


but when i add a container, the only part which is displayed is the title(see the attached file and following code).

 CREATE OBJECT ALV_CONTAINER
 EXPORTING
 CONTAINER_NAME = 'ALV_CONTAINER'.

 CREATE OBJECT g_grid
 EXPORTING
 I_PARENT = ALV_CONTAINER.

To create and select layouts, i use theres function module :

***------------------------------------------------------------------***
*** Form SUB_VARIANT_INIT ***
***------------------------------------------------------------------***
*** Display default variant ***
***------------------------------------------------------------------***
form SUB_VARIANT_INIT.
I_VARIANT1-REPORT = SY-REPID.
* Search default variant for the report
 CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
 EXPORTING
 i_save = 'X'
 CHANGING
 cs_variant = i_variant1
 EXCEPTIONS
 not_found = 2.
* If default variant is found , use it as default.
* Else , use the variant LAYOUT1.
 IF sy-subrc = 0.
 p_var = i_variant1-variant.
 ELSE.
 p_var = ''.
 ENDIF.
endform. " SUB_VARIANT_INIT
***------------------------------------------------------------------***
*** Form SUB_CHECK_PVAR ***
***------------------------------------------------------------------***
*** Once the user has entered variant, check about its existence ***
***------------------------------------------------------------------***
FORM SUB_CHECK_PVAR.
* If the name of the variable is not blank, check about its existence
if not p_var is initial.
 clear i_variant.
 i_variant-report = sy-repid.
 i_variant-variant = p_var.
 CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
 EXPORTING
 I_SAVE = 'X'
 CHANGING
 CS_VARIANT = I_VARIANT.
* If no such variant found , flash error message
 if sy-subrc ne 0 .
 message e398(00) with 'No such variant exists'.
 else.
* If variant exists , use the variant name to populate structure
* I_VARIANT1 which will be used for export parameter : IS_VARIANT
* in the function module : REUSE_ALV_GRID_DISPLAY
 clear i_variant1.
 move p_var to i_variant1-variant.
 move sy-repid to i_variant1-report.
 endif.
 else.
 clear i_variant.
 endif.
ENDFORM. " SUB_CHECK_PVAR
***------------------------------------------------------------------***
*** Form SUB_VARIANT_F4 ***
***------------------------------------------------------------------***
*** Display a list of various variants of the report when the user ***
*** presses F4 key in the variant field ***
***------------------------------------------------------------------***
form SUB_VARIANT_F4.
i_variant-report = sy-repid.
* Utilising the name of the report , this function module will search for a list of variants and will fetch the selected one
* into the parameter field for variants
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
 EXPORTING
 IS_VARIANT = I_VARIANT
 I_SAVE = 'X'
 I_DISPLAY_VIA_GRID = 'X'
 IMPORTING
 ES_VARIANT = I_VARIANT1
 EXCEPTIONS
 NOT_FOUND = 1
 PROGRAM_ERROR = 2
 OTHERS = 3.
 IF SY-SUBRC = 0.
 P_VAR = I_VARIANT1-VARIANT.
 ENDIF.
ENDFORM. " SUB_VARIANT_F4
FORM variant_delete.
 CALL FUNCTION 'REUSE_ALV_VARIANT_ALL_MAINTAIN'
 EXPORTING
 is_variant = I_VARIANT-REPORT
* i_default = ld_i_default
* i_user_specific = ld_i_user_specific
* i_tabname_header = ld_i_tabname_header
* i_tabname_item = ld_i_tabname_item
* is_layout = ld_is_layout
* it_default_fieldcat = ld_it_default_fieldcat
 EXCEPTIONS
 FOREIGN_LOCK = 1
 PROGRAM_ERROR = 2
 . " REUSE_ALV_VARIANT_ALL_MAINTAIN

 IF SY-SUBRC EQ 0.
 "All OK
 ELSEIF SY-SUBRC EQ 1. "Exception
 "Add code for exception here
 ELSEIF SY-SUBRC EQ 2. "Exception
 "Add code for exception here
 ENDIF.
ENDFORM.
2 REPLIES 2

roberto_forti
Contributor
0 Kudos

Hi,

Following SAP documentation CL_GUI_ALV_GRID to help you.

Regards,

former_member201147
Active Participant
0 Kudos

The CL_GUI_ALV_GRID class and the REUSE_ALV_* function modules are 2 totally separate things. They do not work together. You either use one or the other. The ALV Grid class gives you more functionality. Also, look up the CL_SALV* classes for a newer implementation of the ALV Grid.