Application Development and Automation 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: 
Read only

Getting internal table information at runtime

Former Member
0 Likes
1,010

Hi All

I am trying to create a method that will automatically create a field catalog based on INTERNAL TABLE input. I have found the following for determining components within a database structure. I am wondering if there is a equivalent for internal tables?

Does anyone know if there is a function/method available to automatically create a field catalog based on lvc_t_fcat? Yes I know there is the REUSE_ALV_FIELDCATALOG_MERGE but this only works for FM ALV. I have thought about wrapping this function but would prefer to do it the 'tricky' way.

DATA table_descr TYPE REF TO cl_abap_tabledescr.

  DATA struct_descr TYPE REF TO cl_abap_structdescr.

  DATA columns TYPE abap_compdescr_tab.

  table_descr ?= cl_abap_typedescr=>describe_by_data( itab ).

  struct_descr ?= table_descr->get_table_line_type( ).

  columns = struct_descr->components.

3 REPLIES 3
Read only

Former Member
0 Likes
928

Hi Brad,

What you have written above will work well for determining the components of an Internal table.

If what you need is to create a LVC fieldcatalog from an Internal table, you can go through this link.

http://wiki.sdn.sap.com/wiki/display/Snippets/Creating+LVC+fieldcatalog+Using+Internal+table+through...

Use LVC_TRANSFER_FROM_SLIS after using REUSE_ALV_FIELDCATALOG_MERGE to convert.

Thanks,

Shambu

Read only

yogendra_bhaskar
Contributor
0 Likes
928

HI Brad ,

Have a look on following code , this may help you :

*&---------------------------------------------------------------------*

*&      Form  get_lvc_t_fcat_4_itab

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->IT_TABLE   text

*      -->RT_FCAT    text

*----------------------------------------------------------------------*

FORM get_lvc_t_fcat_4_itab USING it_table CHANGING rt_fcat.

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

ENDFORM.                    "get_lvc_t_fcat_4_itab

Thanx n Regards,

Yogendra Bhaskar

Read only

janewar
Participant
0 Likes
928

This message was moderated.