Application Development and Automation 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: 
Read only

Refresh fieldcatalog during runtime

Former Member
0 Likes
31,595

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.
1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
31,032

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
30 REPLIES 30
Read only

RaymondGiuseppi
Active Contributor
31,032

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.)

Read only

0 Likes
31,032

I haven't infinite loop, this ABAP works one time, when i hide a column, datas are correctly sorted but when i try to make the field displayed again, the field is empty. So i have check my program via checkpoints where the refresh is trigerred and then, i deduced that when i call get_frontend_fieldcatalog, this table is update only the first time the program enter in the loop.

Concerning the value of the field TEST, it is set to empty when the event is trigerred. This prevent the infinite loop no ? Then for use it again, i set it to X after the method After_refresh.

Read only

0 Likes
31,032

Question: When a previously hidden column is displayed again, is the event raised, and what is the value of 'TEST'?

Read only

0 Likes
31,032

First step :

Read only

0 Likes
31,032

Second step :

Read only

0 Likes
31,032

Third step :

Read only

0 Likes
31,032

Fourth step :

On the fourth screenshot, we can see that TEST is null before the second call to refresh. And the event has been raised.

Read only

0 Likes
31,032

Fifth and sixth :

This is a view of the table it_fieldcat after the method get frontend fieldcatalog have been used. no_out value is unchanged from the moment the field has been hidden.

Read only

0 Likes
31,032

Sorry for multiple post, the website don't accept lot of picture for one post

Read only

0 Likes
31,032

Try to add a "call method cl_gui_cfw=>flush" at start of the event handler before getting the field catalog to force synchronisation.

Read only

0 Likes
31,031

Same issue, the field article is always empty.

Read only

0 Likes
31,031

The flush should be placed after the refresh_Table_display method

Read only

0 Likes
31,031

Thanks for your answer.

I have the same issue

Read only

0 Likes
31,031

Sorry, i read better and i see the problem: you get the fieldcat, change it, but you do not SET it again before the refresh!
Invoke method SET_FIELDCATALOG and then the REFRESH_TABLE_DISPLAY followed by the FLUSH

Read only

0 Likes
31,031

I have the same issue with this code :

Read only

RaymondGiuseppi
Active Contributor
31,031

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

Read only

0 Likes
31,029

I lunch the program so line 192, i check at it_fieldcat-no_out value :

here, no_out is initial

Read only

0 Likes
31,029

so next step, line 197 :

i check the value of it_fieldcat :

values have been updated. So i continue the execute

Read only

0 Likes
31,029

Here is datas who are firstly displayed.

I want to hide the field Article

Read only

0 Likes
31,027

again line 192, check if the fieldcatalog is initial:

values are empty for the moment so it is initial

Read only

0 Likes
31,027

line 197 again, check fieldcatalog again :

here the table has been correctly updated

Read only

0 Likes
31,027

the display is correct so now, i want to display the field Article :

Read only

0 Likes
31,023

line 192, i check values of fieldcatalog and line 197, i have the same table so this table haven't been updated

Read only

0 Likes
31,021

so i tried to switch order of the method call like this :

and i get the same issue, after the first refresh, datas aren't get anymore

Read only

0 Likes
31,021

I asked to swith order of 'cl_gui_cfw=>flush' and 'g_grid->get_frontend_fieldcatalog' and asked if the no_out field was correct in the returned et_fieldcatalog.

Read only

0 Likes
31,019

Like this, i get the a wrong no_out value for et_fieldcatalog

Read only

0 Likes
31,019

same issue like this :

and this :

Read only

Former Member
0 Likes
31,019

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 ?"

Read only

Sandra_Rossi
Active Contributor
31,033

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
Read only

31,019

Thank you very much for the explanation of the error. It works perfectly.