Skip to Content
avatar image
Former Member

Using the FM LVC_FIELDCATALOG_MERGE

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Dec 28, 2010 at 07: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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 17, 2007 at 02: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.

    Add comment
    10|10000 characters needed characters exceeded

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

  • avatar image
    Former Member
    Jun 27, 2014 at 12: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)

    • 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

    Add comment
    10|10000 characters needed characters exceeded