Skip to Content
-2

Refresh fieldcatalog during runtime

Hi experts, i need to delete duplicate entries when the user hide fields but the value of the fieldcatalog isn't refresh. Can you help me please ? Thanks in advance for your help ;)

Here is my code :

REPORT ZTESTALEX01 NO STANDARD PAGE HEADING.
TYPE-POOLS: slis.
CLASS cl_event_receiver DEFINITION DEFERRED.
*&-------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
 SET PF-STATUS 'MAIN'.
 SET TITLEBAR 'ALV_EXAMPLES'.
ENDMODULE. " STATUS_0100 OUTPUT
MODULE display_grid OUTPUT.
 PERFORM read_data.
 PERFORM display_grid.
ENDMODULE.
MODULE user_command_0100 INPUT.
* to react on oi_custom_events:
 call method cl_gui_cfw=>dispatch.
 CASE sy-ucomm.
 WHEN 'BACK' OR
 'EXIT' OR
 'CANCEL'.
 LEAVE PROGRAM.
 WHEN OTHERS.
* do nothing
 ENDCASE.

ENDMODULE.

TYPES: BEGIN OF ty_mara,
 MATNR LIKE MARA-MATNR, "Article
 ZZBIOJFA LIKE MARA-ZZBIOJFA, "Article bio
 MTART LIKE MARA-MTART, "
 ZZFRUIT LIKE MARA-ZZFRUIT, "
 ZZALLERGENE LIKE MARA-ZZALLERGENE, "
 PRDHA LIKE MARA-PRDHA, "
 LABOR LIKE MARA-LABOR, "lab./bureau d'étude
END OF ty_mara.

DATA: g_cont TYPE REF TO cl_gui_custom_container,
 g_grid TYPE REF TO cl_gui_alv_grid,
 rcv_ev TYPE REF TO cl_event_receiver,
 gs_layout TYPE lvc_s_layo,
 it_mara TYPE TABLE OF ty_mara,
 it_aff TYPE TABLE OF ty_mara,
 wa_mara TYPE ty_mara,
 it_fieldcat TYPE lvc_t_fcat,
 wa_fieldcat TYPE lvc_s_fcat,
 NOOUT1 TYPE STRING,
 NOOUT2 TYPE STRING,
 TEST TYPE C VALUE 'X',
 l_valid TYPE C,
 RS_SELFIELD TYPE SLIS_SELFIELD.
FIELD-SYMBOLS : <mara>,<aff>,<field> TYPE lvc_s_fcat ,<from>,<to>.
TABLES: MARA.

* CLASS lcl_events_d0100 DEFINITION
 class cl_event_receiver definition.

 public section.
 methods:
 handle_after_refresh for event after_refresh
 of cl_gui_alv_grid.
endclass. "lcl_events_d0100 DEFINITION
* CLASS lcl_events_d0100 IMPLEMENTATION
 class cl_event_receiver implementation.

* METHOD after_refresh *
 method handle_after_refresh.
 IF TEST = 'X'.
 perform d0100_event_after_refresh.
 ENDIF.
 endmethod. "after_refresh *
endclass. "lcl_events_d0100 IMPLEMENTATION
INITIALIZATION.
 PERFORM REMPLIR_AFFICHAGE.
 START-OF-SELECTION.
 CALL SCREEN 0100.

*&-------------------------------------------------------------------*
*& Form read_data
*&-------------------------------------------------------------------*
FORM read_data.
 SELECT MATNR ZZBIOJFA MTART ZZFRUIT ZZALLERGENE PRDHA LABOR
 INTO CORRESPONDING FIELDS OF TABLE it_mara
 FROM MARA.
ENDFORM.

*&-------------------------------------------------------------------*
*& Form display_grid
*&-------------------------------------------------------------------*
FORM display_grid.
 IF g_cont IS INITIAL.
 CREATE OBJECT g_grid
 EXPORTING
 i_appl_events = 'X'
 i_parent = cl_gui_container=>default_screen.

* create handler
 CREATE OBJECT rcv_ev.

* register handler for events
 SET HANDLER rcv_ev->handle_after_refresh FOR g_grid.

 CALL METHOD g_grid->set_table_for_first_display
* EXPORTING
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* I_CONSISTENCY_CHECK =
* I_STRUCTURE_NAME = 'MARA'
* IS_VARIANT =
* I_SAVE =
* I_DEFAULT = 'X'
* IS_LAYOUT =
* IS_PRINT =
* IT_SPECIAL_GROUPS =
* IT_TOOLBAR_EXCLUDING =
* IT_HYPERLINK =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO =
* IR_SALV_ADAPTER =
 CHANGING
 it_outtab = it_aff
 IT_FIELDCATALOG = it_fieldcat
* IT_SORT =
* IT_FILTER =
 EXCEPTIONS
 invalid_parameter_combination = 1
 program_error = 2
 too_many_lines = 3
 OTHERS = 4.
 IF sy-subrc <> 0.
 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
 ENDIF.
 ENDIF.
ENDFORM.

FORM REMPLIR_AFFICHAGE.
 wa_fieldcat-col_pos = 1.
 wa_fieldcat-fieldname = 'MATNR'.
 wa_fieldcat-tabname = 'TB_MARA'.
 wa_fieldcat-ref_table = 'MARA'.
 APPEND wa_fieldcat TO it_fieldcat.
 clear wa_fieldcat.
 wa_fieldcat-col_pos = 2.
 wa_fieldcat-fieldname = 'ZZBIOJFA'.
 wa_fieldcat-tabname = 'TB_MARA'.
 wa_fieldcat-ref_table = 'MARA'.
 APPEND wa_fieldcat TO it_fieldcat.
 clear wa_fieldcat.
 wa_fieldcat-col_pos = 3.
 wa_fieldcat-fieldname = 'MTART'.
 wa_fieldcat-tabname = 'TB_MARA'.
 wa_fieldcat-ref_table = 'MARA'.
 APPEND wa_fieldcat TO it_fieldcat.
 clear wa_fieldcat.
 wa_fieldcat-col_pos = 4.
 wa_fieldcat-fieldname = 'ZZFRUIT'.
 wa_fieldcat-tabname = 'TB_MARA'.
 wa_fieldcat-ref_table = 'MARA'.
 APPEND wa_fieldcat TO it_fieldcat.
 clear wa_fieldcat.
 wa_fieldcat-col_pos = 5.
 wa_fieldcat-fieldname = 'ZZALLERGENE'.
 wa_fieldcat-tabname = 'TB_MARA'.
 wa_fieldcat-ref_table = 'MARA'.
 APPEND wa_fieldcat TO it_fieldcat.
 clear wa_fieldcat.
 wa_fieldcat-col_pos = 6.
 wa_fieldcat-fieldname = 'PRDHA'.
 wa_fieldcat-tabname = 'TB_MARA'.
 wa_fieldcat-ref_table = 'MARA'.
 APPEND wa_fieldcat TO it_fieldcat.
 clear wa_fieldcat.
ENDFORM.



FORM d0100_event_after_refresh.

 CLEAR TEST. "Pour éviter le redondance de l'événement after refresh
 CLEAR it_aff. "La table devant etre affichée
* CLEAR it_fieldcat[].
* if g_grid is INITIAL.
 CALL METHOD g_grid->get_frontend_fieldcatalog
 IMPORTING
 et_fieldcatalog = it_fieldcat[].
* ENDIF.
 LOOP AT it_mara ASSIGNING <mara>.
 APPEND INITIAL LINE TO it_aff ASSIGNING <aff>.
 LOOP AT it_fieldcat ASSIGNING <field> WHERE no_out IS INITIAL AND tech IS INITIAL.
 ASSIGN COMPONENT <field>-fieldname OF STRUCTURE <mara> TO <from>.
 CHECK <from> IS ASSIGNED.
 ASSIGN COMPONENT <field>-fieldname OF STRUCTURE <aff> TO <to>.
 CHECK <to> IS ASSIGNED.
 <to> = <from>.
 ENDLOOP.
 ENDLOOP.

* CALL METHOD g_grid->set_frontend_fieldcatalog
* EXPORTING
* it_fieldcatalog = it_fieldcat.
* IF g_grid is NOT INITIAL.
* call METHOD g_grid->check_changed_data
* IMPORTING
* e_valid = l_valid.
* ENDIF.
* rs_selfield-refresh = l_valid.


 SORT it_aff ASCENDING. "On trie toutes les données
 DELETE ADJACENT DUPLICATES FROM it_aff COMPARING ALL FIELDS. "On supprime les duplicatas

 IF g_grid is NOT INITIAL.
 CALL METHOD g_grid->refresh_table_display."Reaffichage
 ENDIF.

 TEST = 'X'.

ENDFORM.
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Feb 05 at 11:00 AM

    Your error is NOT related to the field catalog, refresh, and so on.

    It's only due to the fact that you create the grid every time : G_CONT is always initial !

     IF g_grid IS INITIAL. "don't use g_cont !
       CREATE OBJECT g_grid
    
    Add comment
    10|10000 characters needed characters exceeded

  • Jan 23 at 02:05 PM

    Look at your management of the field TEST which should prevent infinite loop between refresh_table_display and handle_after_refresh (what is its initial value, etc.)

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 24 at 06:27 AM

    Is the fieldcat-no_out parameter initial after the get fieldcatalog call (if not, try to switch order of the method call)

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 31 at 09:14 AM
    -1

    Maybe the probleme come from the after refresh event, if i get an other event or user command like the button to state changes before having hide/display a column ? But i don't know how to get this event, the user_command value is DTC_CONT i think but how to handle event from it ?. So the first question who must be answered is : "Why i am getting false / unupdated values in my fieldcatalog ?"

    Add comment
    10|10000 characters needed characters exceeded