5 1 1 1 1 1 Rating 100% (9 Votes)
Many people still asks how to create field catalog for CL_GUI_ALV_GRID or REUSE_ALV_GRID_DISPLAY on a base of internal table. This is very easy since we have SALV classes, you could see it in my article Create XLSX/MHTML file from internal table in background and probably also somewhere in the net. To make it easier here are ready methods to create LVC and SLIS field catalogs from internal table using CL_SALV_CONTROLLER_METADATA and  CL_SALV_TABLE. Both methods are created with new ABAP 7.40 SP05 syntax.
 
LVC Field catalog definition

  class-methods lvc_fcat_from_internal_table
  importing
    it_table type any table
  returning value(rt_fcattype lvc_t_fcat.

LVC field catalog implementation

  method lvc_fcat_from_internal_table.
    datatable type ref to data.
    create data table like it_table.
    assign table->to field-symbol(<table>).
    try.
        cl_salv_table=>factoryimporting
                                  r_salv_table   data(salv_table)
                                changing
                                  t_table        <table>  ).
        rt_fcat cl_salv_controller_metadata=>get_lvc_fieldcatalog(
            r_columns      salv_table->get_columns" ALV Filter
            r_aggregations salv_table->get_aggregations" ALV Aggregations
    ).
      catch cx_root.
    endtry.
  endmethod.

 
SLIS field catalog definition

  class-methods slis_fcat_from_internal_table
  importing
    it_table type any table
  returning value(rt_fcattype slis_t_fieldcat_alv.

SLIS field catalog implementation

  method slis_fcat_from_internal_table.
    datatable type ref to data.
    create data table like it_table.
    assign table->to field-symbol(<table>).
    try.
        cl_salv_table=>factoryimporting
                                  r_salv_table   data(salv_table)
                                changing
                                  t_table        <table>  ).
        rt_fcat cl_salv_controller_metadata=>get_slis_fieldcatalog(
            r_columns      salv_table->get_columns" ALV Filter
            r_aggregations salv_table->get_aggregations" ALV Aggregations
    ).
      catch cx_root.
    endtry.
  endmethod.

You can also have only one of this methods and if needed then you can use one of theFM LVC_TRANSFER_FROM_SLIS or LVC_TRANSFER_TO_SLIS to convert LVC and SLIS field catalogs between themselves.