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: 

Using the FM LVC_FIELDCATALOG_MERGE

former_member680493
Participant
0 Kudos

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.

1 ACCEPTED SOLUTION

Clemenss
Active Contributor
0 Kudos

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 REPLIES 12

Former Member
0 Kudos

Hi,

In FM you need to pass tabela instead of type to I_INTERNAL_TABNAME and comment the I_STRUCTURE_NAME.

Thanks,

Sriram Ponna.

0 Kudos

This message was moderated.

0 Kudos

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.

0 Kudos

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.

0 Kudos

Try Commenting out I_STRUCTURE_NAME.

Thanks,

Sri.

0 Kudos

I tried! it doesn't work!!

0 Kudos

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.

Clemenss
Active Contributor
0 Kudos

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

0 Kudos

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

Clemenss
Active Contributor
0 Kudos

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

0 Kudos

That's level-coding....! nice!

Former Member
0 Kudos

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)

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

FOLLOW THIS WAY WE GENERATE OUTPUT AUTOMATICALLY