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

Create a fieldcatalog dynamically

Former Member
0 Likes
655

Hey everyone,

I need to realize a method which creates dynamically a fieldcatalog. The call of the method looks like this:


  CALL METHOD me->describe_struct_for_fcat
    EXPORTING
      im_tab = it_data. "type: data

I have a vague idea how to do this:

1. get the type of the im_tab

2. Some kind of loop at the type of the im_tab where filling the row for the fcat and appending it to the fcat.

I would be pleased if you can post a code snippet or something, which I can copy.

Looking forward to your answers.

BR Fabian

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
619

As Keshav T suggested, use the SALV model to generate the ALV for your dynamic table. You can look the program SALV_DEMO_TABLE_SIMPLE.

Regards,

Naimesh Patel

4 REPLIES 4
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
619

Hi,

Check the code written in method factory of class CL_SALV_TABLE.

Or wait for our friend Marcin till he gives a clear & detailed explanation

Read only

naimesh_patel
Active Contributor
0 Likes
620

As Keshav T suggested, use the SALV model to generate the ALV for your dynamic table. You can look the program SALV_DEMO_TABLE_SIMPLE.

Regards,

Naimesh Patel

Read only

0 Likes
619

try this, but note, you will have do figure out how to get the correct length and decimals for field types P or I

REPORT  ZCA_BOB_CL_ABAP_STRUCTDESCR_X.


Data: r_descr type REF TO cl_abap_structdescr,
      wa_comp TYPE abap_compdescr.


types: begin of wa_int_tab,
        mandt type mandt,
        matnr type matnr,
        werks type WERKS_D,
        lgort type LGORT_D,
        min_qty type MINLF,
       end of wa_int_tab.
data: it_int_tab TYPE STANDARD TABLE OF wa_int_tab.
data: wk_int_tab like LINE OF  it_int_tab.


Data: wk_length(6) type n,
      wk_decimals(6) type n.

START-OF-SELECTION.


 r_descr ?= cl_abap_typedescr=>describe_by_data( wk_int_tab ).

 Loop at r_descr->components into wa_comp.
   If wa_comp-type_kind = 'C'
   or wa_comp-type_kind = 'D'
   or wa_comp-type_kind = 'N'.
    Divide wa_comp-length by 2.
  Else.
** go out to tables DD03L and  DD04L to get LENG and DECIMALS
  Endif.
   write:/ wa_comp-name,
           wa_comp-type_kind,
           wa_comp-length,
           wa_comp-decimals.

 EndLoop.

Read only

Former Member
0 Likes
619

Hi Bob,

thank you so much for your post! That is exactly what i was looking for!! Perfect!