Skip to Content
-2

Refresh fieldcatalog during runtime

Jan 23 at 01:54 PM

176

avatar image

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.
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Sandra Rossi Feb 05 at 11:00 AM
1

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
Show 1 Share
10 |10000 characters needed characters left characters exceeded

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

1
Raymond Giuseppi
Jan 23 at 02:05 PM
1

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

Show 14 Share
10 |10000 characters needed characters left characters exceeded

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.

0
Alexandre HOLZHAMMER

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

0

First step :

capture1.png (21.6 kB)
0

Second step :

capture2.png (20.4 kB)
0

Third step :

capture3.png (19.9 kB)
0

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.

capture4.png (58.2 kB)
0

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.

capture5.png (37.1 kB)
capture6.png (22.6 kB)
0

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

0
Show more comments
Raymond Giuseppi
Jan 24 at 06:27 AM
1

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

Show 11 Share
10 |10000 characters needed characters left characters exceeded

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

here, no_out is initial

capture1.png (23.8 kB)
capture2.png (9.6 kB)
0

so next step, line 197 :

i check the value of it_fieldcat :

values have been updated. So i continue the execute

capture5.png (36.3 kB)
capture6.png (17.5 kB)
0

Here is datas who are firstly displayed.

I want to hide the field Article

capture5.png (36.3 kB)
capture6.png (17.5 kB)
0

again line 192, check if the fieldcatalog is initial:

values are empty for the moment so it is initial

capture7.png (11.4 kB)
capture8.png (11.1 kB)
0

line 197 again, check fieldcatalog again :

here the table has been correctly updated

capture9.png (30.8 kB)
capture10.png (17.5 kB)
0

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

capture11.png (20.2 kB)
capture12.png (17.8 kB)
0
Show more comments
Alexandre HOLZHAMMER 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 ?"

Share
10 |10000 characters needed characters left characters exceeded