Skip to Content
author's profile photo Former Member
Former Member

Creating fieldcat using internal table

Hi experts,

I was looking, how to create a fieldcatalog using internal table, if we use fm 'LVC_FIELDCATALOG_MERGE' it will create a fieldcat with all the fields from the dbtable to which internal table ref to. Also tell me how to create automatic fcat for two tables.

Thanks,

Anna.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 06, 2010 at 05:55 PM

    Hi anna,

    I think you can use class CL_SALV_TABLE and its methods to create FCAT using internal table.

    Thanks,

    Anmol.

    Add a comment
    10|10000 characters needed characters exceeded

    • ... or try this:

      <my latest 'invention', just 2 days old>

      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,
          lt_slis_fieldcat_alv        TYPE slis_t_fieldcat_alv.
        FIELD-SYMBOLS:
          <table>         TYPE table.
      * create unprotected table from import data
        CREATE DATA lr_table LIKE it_table.
        ASSIGN lr_table->* TO <table>.
      *...New ALV 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.
      
        lo_columns  = lo_salv_table->get_columns( ).
        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.

      You may use the code in a FORM routine or directly in program, not necessary to use a method.

      Regards,

      Clemens

  • Posted on Oct 06, 2010 at 05:39 PM

    You can go for SALV Display which doesnt need any fieldcat to be populated.

    Search in Google or SCN for SALV Demos.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 06, 2010 at 05:28 PM

    Hi Anna,

    The function LVC_FIELDCATALOG_MERGE generate fieldcatalog for all fields always, so if you need less fields try delete not required fields or (my personal choice) generate the fieldcatalog manually.

    if you need merge two tables in one catalog, try generate a table catalog for each table and then append second table to first one.

    I hope this help,

    Best regards,

    X.S.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 07, 2010 at 04:56 AM

    Hi Anna

    first you need to define the fieldcatlog table as below.

    DATA: I_FCAT TYPE LVC_T_FCAT,

    WA_FCAT TYPE LVC_S_FCAT.

    Suppose you have 2 internal tables itab and itab1

    then create the subroutine as below.

    FORM FIELD_CATLOG.

    CLEAR WA_FCAT.

    WA_FCAT-TABNAME = 'ITAB'. "INT. TABLE NAME.

    WA_FCAT-COL_POS = '1'. " COLUMN POSITION.

    WA_FCAT-FIELDNAME = 'EMP_ID'. "FIELD NAME.

    WA_FCAT-REPTEXT = 'EMPLOYEE ID'. "COLUMN HEADING.

    • WA_FCAT-HOTSPOT = 'X'.

    APPEND WA_FCAT TO I_FCAT.

    CLEAR WA_FCAT.

    WA_FCAT-TABNAME = 'ITAB1'. "INT. TABLE NAME.

    WA_FCAT-COL_POS = '2'. " COLUMN POSITION.

    WA_FCAT-FIELDNAME = 'LAST_NAME'. "FIELD NAME.

    WA_FCAT-REPTEXT = 'LAST NAME'. "COLUMN HEADING.

    • WA_FCAT-HOTSPOT = 'X'.

    APPEND WA_FCAT TO I_FCAT.

    CLEAR WA_FCAT.

    Endform.

    In above code mention the table names in TABNAME field which identifies whichfield to refer from which table.

    like at 1 column field emp_id from table itab and at column 2 last_name from table itab1.

    But make sure before that your tables itab and itab1 must have data.

    Thanks

    Lalit Gupta

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.