12-17-2007 1:43 PM
Hi everybody!
I'm trying to generate an automatic fieldcat from an internal table using the FM 'LVC_FIELDCATALOG_MERGE' but it doesn't work! I don't know what I'm doing wrong!
Can anybody help me?
Here is my code.
types:
BEGIN OF type,
matnr type makt-matnr,
maktx type makt-maktx,
spras type makt-spras,
END OF type.
data: tabela type STANDARD TABLE OF type,
fieldcat type STANDARD TABLE OF lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_BUFFER_ACTIVE =
I_STRUCTURE_NAME = 'TYPE'
I_CLIENT_NEVER_DISPLAY = 'X'
I_BYPASSING_BUFFER =
I_INTERNAL_TABNAME = 'TABELA'
CHANGING
ct_fieldcat = fieldcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
BREAK-POINT.
12-28-2010 7:36 PM
Hi Gabriel,
this is SAP feature It works replacing TYPE with obsolete LIKE in data declaration.
I may have a better way anyway:
METHOD get_lvc_t_fcat_4_itab.
*Importing IT_TABLE TYPE TABLE
*Returning VALUE( RT_FCAT ) TYPE LVC_T_FCAT
DATA:
lo_columns TYPE REF TO cl_salv_columns_table,
lo_aggregations TYPE REF TO cl_salv_aggregations,
lo_salv_table TYPE REF TO cl_salv_table,
lr_table TYPE REF TO data.
FIELD-SYMBOLS:
<table> TYPE STANDARD TABLE.
* create unprotected table from import data
CREATE DATA lr_table LIKE it_table.
ASSIGN lr_table->* TO <table>.
*...New SALV Instance ...............................................
TRY.
cl_salv_table=>factory(
EXPORTING
list_display = abap_false
IMPORTING
r_salv_table = lo_salv_table
CHANGING
t_table = <table> ).
CATCH cx_salv_msg. "#EC NO_HANDLER
ENDTRY.
* get columns object (raw fieldcatalog)
lo_columns = lo_salv_table->get_columns( ).
* get aggregationss object (sorts)
lo_aggregations = lo_salv_table->get_aggregations( ).
rt_fcat =
cl_salv_controller_metadata=>get_lvc_fieldcatalog(
r_columns = lo_columns
r_aggregations = lo_aggregations ).
ENDMETHOD.
If you do not have a class to intergrate this method, you can replace METHOD/ENDMETHOD with FORM/ENDFORM.
This will work with any internal table. Results may be incorrect if the data reference a data element without domain. The same errors for this will occur as they do in SALV.
I created the method because I hate all kind of field catalog troubles. SALV does not require a field catalog - it is created internally using roughly the same way I did here.
Regards,
Clemens
12-17-2007 2:08 PM
Hi,
In FM you need to pass tabela instead of type to I_INTERNAL_TABNAME and comment the I_STRUCTURE_NAME.
Thanks,
Sriram Ponna.
12-17-2007 2:47 PM
12-17-2007 2:59 PM
Hi,
You can do as below :
Create a structure(se11) same as of the internal table and pass the structure to the Fieldcatalog merge I_STRUCTURE_NAME.
Thanks,
Sriram Ponna.
12-17-2007 4:51 PM
Hi!
I appreciate your answer, but I'd like to do using no elements from SE11!
With FM 'REUSE_ALV_FIELDCATALOG_MERGE' its possible do the fieldcat by an internal table, so in FM 'LVC_FIELDCATALOG_MERGE' I think its possible too because it has the option I_INTERNAL_TABNAME.
I think its a problem envolving the declaration of type or something else!
Thanks Sriram.
12-17-2007 4:55 PM
12-17-2007 5:11 PM
12-28-2010 6:03 PM
Hi, Gabriel!
The FM LVC_FIELDCATALOG_MERGE don't work with INTERNAL TABLE only.
It's should be used for merge any STRUCTURE in the ABAP DICTIONARY with your INTERNAL TABLE or used only with a STRUCTURE in the ABAP DICTIONARY.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE = 'X'
I_STRUCTURE_NAME = 'STRUCTURE' "Like MKPF for example
*I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER = 'X'
I_INTERNAL_TABNAME = 'IT_TAB' "Your Internal Table
CHANGING
ct_fieldcat = it_fieldcat "Your Fieldcatalogue
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
12-28-2010 7:36 PM
Hi Gabriel,
this is SAP feature It works replacing TYPE with obsolete LIKE in data declaration.
I may have a better way anyway:
METHOD get_lvc_t_fcat_4_itab.
*Importing IT_TABLE TYPE TABLE
*Returning VALUE( RT_FCAT ) TYPE LVC_T_FCAT
DATA:
lo_columns TYPE REF TO cl_salv_columns_table,
lo_aggregations TYPE REF TO cl_salv_aggregations,
lo_salv_table TYPE REF TO cl_salv_table,
lr_table TYPE REF TO data.
FIELD-SYMBOLS:
<table> TYPE STANDARD TABLE.
* create unprotected table from import data
CREATE DATA lr_table LIKE it_table.
ASSIGN lr_table->* TO <table>.
*...New SALV Instance ...............................................
TRY.
cl_salv_table=>factory(
EXPORTING
list_display = abap_false
IMPORTING
r_salv_table = lo_salv_table
CHANGING
t_table = <table> ).
CATCH cx_salv_msg. "#EC NO_HANDLER
ENDTRY.
* get columns object (raw fieldcatalog)
lo_columns = lo_salv_table->get_columns( ).
* get aggregationss object (sorts)
lo_aggregations = lo_salv_table->get_aggregations( ).
rt_fcat =
cl_salv_controller_metadata=>get_lvc_fieldcatalog(
r_columns = lo_columns
r_aggregations = lo_aggregations ).
ENDMETHOD.
If you do not have a class to intergrate this method, you can replace METHOD/ENDMETHOD with FORM/ENDFORM.
This will work with any internal table. Results may be incorrect if the data reference a data element without domain. The same errors for this will occur as they do in SALV.
I created the method because I hate all kind of field catalog troubles. SALV does not require a field catalog - it is created internally using roughly the same way I did here.
Regards,
Clemens
12-29-2010 5:32 PM
Nice contribution Clemens, actually today I began to research how CL_SALV_TABLE manages to build the catalog automatically, and reached this post afterwards (noticed you posted it in the wiki as well).
I tried to find a way to avoid instantiating CL_SALV_TABLE (because if you need this coding you already have your own CL_GUI_ALV_GRID instance) but found none as the CL_SALV_COLUMNS instance is loaded internally (as you may have seen CREATE OBJECT + cl_salv_data_descr=>describe_table is not doable as the columns constructor needs a reference to a controller instance). This need of redundant instantiation is the only "stain" I see in this code, as it implies creating unnecesary objects when only the columns and aggregations are actually needed. But for know I see no fix so this will do
I may add that I tried this code including a field with directly typed data element and experienced no problems so far. Could you describe yours so I can try to replicate it? Maybe we are in different SP levels? I'm on 700 0012 just in case.
Regards
Edited by: Alejandro Bindi on Dec 29, 2010 3:37 PM
12-29-2010 5:45 PM
Hi Alejandro,
I do not remember very clear, that was more than two years ago something went wrong with columns header and/or cell formatting with data elements without domain.
You are right it may not be required to (implicitly) create a grid instance. As I put the reference as local variable on the stack, it gets lost anyway and may be returned to system by garbage collector. This really does not hurt at all.
Anyway, this place is not the place for discussions not really concerning Gabriel's still unanswered question.
We may discuss further in the code gallery...
Regards,
Clemens
10-11-2012 12:58 PM
06-27-2014 1:57 PM
we cant requried any types in automatic alv report
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = STANARD TABLE NAME OR CUSTOM TABLE NAME
CHANGING
ct_fieldcat = UR INTERNAL TABLE OF THE TABLE TYPE (ST TABLE OR CUSTOM TABLE)
.IF sy-subrc <> 0.
ENDIF.
FOLLOW THIS WAY WE GENERATE OUTPUT AUTOMATICALLY