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: 

Creating fieldcat using internal table

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi anna,

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

Thanks,

Anmol.

7 REPLIES 7

rxsalomone
Explorer
0 Kudos

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.

kesavadas_thekkillath
Active Contributor
0 Kudos

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

Search in Google or SCN for SALV Demos.

Former Member
0 Kudos

Hi anna,

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

Thanks,

Anmol.

0 Kudos

Hi Anna,

Use method FACTORY of class CL_SALV_TABLE, then use method GET_COLUMNS of the same class using ref from method FACTORY, then use method GET of class CL_SALV_COLUMNS_TABLE, you will have the names of the fields in the return table.

Thanks,

Anmol.

0 Kudos

Hi Anna,

Try this code.


FORM BUILD_FCAT   TABLES T_FCAT TYPE LVC_T_FCAT USING TABNAME.
DATA : O_ALV TYPE REF TO CL_SALV_TABLE,
       O_VALUE TYPE  REF TO CL_SALV_COLUMNS_TABLE,
       O_COLREF TYPE REF TO CL_SALV_COLUMN,
       TAB TYPE SALV_T_COLUMN_REF,
       WA_TAB TYPE SALV_S_COLUMN_REF.
  FIELD-SYMBOLS : <TAB> TYPE STANDARD TABLE.

  CREATE DATA TABNM TYPE TABLE OF (TABNAME).
  ASSIGN TABNM->* TO <TAB>.
  REFRESH : T_FCAT.
  CLEAR : WA_FCAT,ROLLNAME.

 CALL METHOD CL_SALV_TABLE=>FACTORY
          IMPORTING
            R_SALV_TABLE = O_ALV
          CHANGING
            T_TABLE = <TAB>.

  CALL METHOD O_ALV->GET_COLUMNS
           RECEIVING
             VALUE = O_VALUE.
  CALL METHOD O_VALUE->GET
          RECEIVING
            VALUE = TAB.

  LOOP AT TAB INTO WA_TAB.
    CALL METHOD WA_TAB-R_COLUMN->GET_MEDIUM_TEXT
              RECEIVING
                VALUE = WA_FCAT-SCRTEXT_M.
    WA_FCAT-SELTEXT = WA_FCAT-SCRTEXT_M.
    WA_FCAT-FIELDNAME = WA_TAB-COLUMNNAME.
    APPEND WA_FCAT TO T_FCAT.
    CLEAR : WA_FCAT.
  ENDLOOP.
ENDFORM.                    " BUILD_FCAT

Thanks,

Anmol

0 Kudos

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

Former Member
0 Kudos

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