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: 

Dynamic catalog generation.. ??

0 Kudos

Hi experts,

Here i want to generate dynamic catalog for alv.

i.e. initially table name is not known to me.

at runtime my application will get to know table name. (table name will be stored in some variable)

So can anybody please tell me how to do this?

please write code snippet for this.

also while generating catalog how to determing coloum names for this table at runtime?

Cheers,

Naveen

1 ACCEPTED SOLUTION

Former Member
0 Kudos

u can do it by using REUSE_ALV_FIELDCATALOGUE_MERGE

function module

after getting the table name pass the table name to this fm

it will create a fieldcat and gives it for you

once after getting field cat u can modify the field cat as per your requirement

3 REPLIES 3

Former Member
0 Kudos

u can do it by using REUSE_ALV_FIELDCATALOGUE_MERGE

function module

after getting the table name pass the table name to this fm

it will create a fieldcat and gives it for you

once after getting field cat u can modify the field cat as per your requirement

former_member212653
Active Contributor
0 Kudos

Check out this code this code :


field-symbols:
*Dynamic table for PART C 
<f_data>    type standard table.
field-symbols: <l_temp> type any.
field-symbols: <l_wa_f_data> type any.
data: l_wa_ref type ref to data,
*Field catalog
i_lvc_t_fcat  type lvc_t_fcat,
* Pointer to dynamic table
i_table    type ref to data.



clear: wa_line.
refresh: i_tab,i_lvc_t_fcat.

* Creating the ALV Catalog
  perform sub_create_catalog1 using:
     'WERKS'    'Plant'(011)              '4'  'WERKS_D',
     'MATNR'    'Material'(012)           '18' 'MATNR',
     'MAKTX'    'Description'(066)        '40' 'MAKTX',
     'WAERS'    'Curr.'(019)              '5'  'WAERS',
     'PEINH'    'Price Unit'(052)         '6'  'PEINH'.

  if p_pp1 = c_check.
    perform sub_create_catalog1 using:
       'ZPLP1'    'PlndPrice1'(020)      '14' 'DZPLP1',
       'ZPLD1'    'PP date 1'(021)       '10' 'DZPLD1'.
  endif.
  if p_pp2 = c_check.
    perform sub_create_catalog1 using:
       'ZPLP2'    'PlndPrice2'(022)      '14' 'DZPLP2',
       'ZPLD2'    'PP date 2'(023)       '10' 'DZPLD2'.
  endif.
  if p_pp3 = c_check.
    perform sub_create_catalog1 using:
       'ZPLP3'    'PlndPrice3'(024)      '14' 'DZPLP3',
       'ZPLD3'    'PP date 3'(025)       '10' 'DZPLD3'.
  endif.
  if p_disall = c_check.
    perform sub_create_catalog1 using:
       'ZPLP1'    'PlndPrice1'(020)      '14' 'DZPLP1',
       'ZPLD1'    'PP date 1'(021)       '10' 'DZPLD1',
       'ZPLP2'    'PlndPrice2'(022)      '14' 'DZPLP2',
       'ZPLD2'    'PP date 2'(023)       '10' 'DZPLD2',
       'ZPLP3'    'PlndPrice3'(024)      '14' 'DZPLP3',
       'ZPLD3'    'PP date 3'(025)       '10' 'DZPLD3'.
  endif.

* Create internal table
  call method cl_alv_table_create=>create_dynamic_table
    exporting
      it_fieldcatalog = i_lvc_t_fcat
    importing
      ep_table        = i_table.

*Create a table
  assign i_table->* to <f_data>.
  check sy-subrc = 0.

*Create a data
  create data l_wa_ref like line of <f_data>.
*Assign the work area
  assign l_wa_ref->* to <l_wa_f_data>.
  check sy-subrc = 0.

*&---------------------------------------------------------------------*
*&      Form  sub_create_catalog1
*&---------------------------------------------------------------------*
*       Popualate Temp Field catalog
*----------------------------------------------------------------------*
*      -->P_FLDNAME      Fieldname
*      -->P_COL_HEADING  Coloumn Heading
*      -->P_OUTPUTLEN    Length
*----------------------------------------------------------------------*
form sub_create_catalog1  using   p_fldname      type slis_fieldname
                                  p_col_heading  type scrtext_l
                                  p_outputlen    type any
                                  p_rollname     type rollname.
  data:l_wa_lvc_t_fcat like line of i_lvc_t_fcat.

*...Clear Workarea
  clear l_wa_lvc_t_fcat.

  l_wa_lvc_t_fcat-fieldname   =  p_fldname.            " Field name
  l_wa_lvc_t_fcat-outputlen   =  p_outputlen.          " Output Length
  l_wa_lvc_t_fcat-seltext     =  p_col_heading.        " Column heading
  l_wa_lvc_t_fcat-rollname    =  p_rollname.           " Data element

* Append the data into field catalog table
  append l_wa_lvc_t_fcat to i_lvc_t_fcat .


endform.                    " sub_create_catalog1

0 Kudos

Hi Saurav,

This doesn't seem to be solution. since we don't know coloum headings at compile time.

so what i want to know is , while generating catalog dynamically how to determing coloum heading.

or alternatively how to create a table with header line from a table name stored in some variable.

I tried following way:

data tab_name type DD02L-TABNAME.

data uitab type ref to data.

create data uitab type table of (TAB_NAME).

"(say value in tab_name is 'spfli')

call method my_alv->set_table_for_first_display

exporting

i_structure_name = '(NAME)'

But since this table doesn't contain the header line so this method requires another changing parameter

it_fieldcatalog . But to perform create_catalog i must know what coloums are there within the table.

Ah!!! finally i got it..

Thanks a lot for your attempt..

Edited by: Naveen Trivedi on Jul 15, 2008 6:34 AM